From c651c4ddaa7aca5b6e48aefb2a33520ed7a09201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Mon, 2 Mar 2020 16:41:49 +0100 Subject: [PATCH] Cleanup a bit BillRecord --- uncloud/uncloud_pay/models.py | 19 +++++++------------ uncloud/uncloud_pay/serializers.py | 1 + 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py index e257b9e..9cbeb48 100644 --- a/uncloud/uncloud_pay/models.py +++ b/uncloud/uncloud_pay/models.py @@ -38,12 +38,7 @@ class Bill(models.Model): orders = Order.objects.filter(bill=self) for order in orders: for order_record in order.records: - bill_record = BillRecord( - self, - order_record.setup_fee, - order_record.recurring_price, - order_record.recurring_period, - order_record.description) + bill_record = BillRecord(order_record) bill_records.append(bill_record) return bill_records @@ -53,12 +48,12 @@ class Bill(models.Model): return reduce(lambda acc, record: acc + record.amount(), self.records, 0) class BillRecord(): - def __init__(self, bill, setup_fee, recurring_price, recurring_period, description): - self.bill = bill - self.setup_fee = setup_fee - self.recurring_price = recurring_price - self.recurring_period = recurring_period - self.description = description + def __init__(self, order_record): + self.order = order_record.order.uuid + self.setup_fee = order_record.setup_fee + self.recurring_price = order_record.recurring_price + self.recurring_period = order_record.recurring_period + self.description = order_record.description def amount(self): # TODO: Billing logic here! diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index 976ab6b..e3ac0eb 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -9,6 +9,7 @@ from uncloud_vm.models import VMProduct # TODO: remove magic numbers for decimal fields class BillRecordSerializer(serializers.Serializer): + order = serializers.CharField() description = serializers.CharField() recurring_period = serializers.CharField() recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2)