From db9ff5d18be98892d40b2e570f1917028f992334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Sat, 18 Apr 2020 10:43:23 +0200 Subject: [PATCH] Display allr elevant values on Bill serializer/page --- .../uncloud/uncloud_pay/models.py | 18 +++++++++++++----- .../uncloud/uncloud_pay/serializers.py | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/uncloud_django_based/uncloud/uncloud_pay/models.py b/uncloud_django_based/uncloud/uncloud_pay/models.py index 8a71abb..3b545fb 100644 --- a/uncloud_django_based/uncloud/uncloud_pay/models.py +++ b/uncloud_django_based/uncloud/uncloud_pay/models.py @@ -525,10 +525,11 @@ class Bill(models.Model): @property def billing_address(self): - return self.order.billing_address + # FIXME: make sure all the orders of a bill match the same billing address. + orders = Order.objects.filter(bill=self) + return orders[0].billing_address @staticmethod - def generate_for(year, month, user): # /!\ We exclusively work on the specified year and month. generated_bills = [] @@ -605,7 +606,6 @@ class Bill(models.Model): # Handle yearly bills starting on working month. if len(unpaid_orders['yearly']) > 0: - # For every starting date, generate new bill. for next_yearly_bill_start_on in unpaid_orders['yearly']: # No postpaid for yearly payments. @@ -735,6 +735,10 @@ class BillRecord(): raise Exception('Unsupported recurring period: {}.'. format(record.recurring_period)) + @property + def vat(self): + return 0 + @property def amount(self): return Decimal(float(self.recurring_price) * self.recurring_count) + self.one_time_price @@ -891,12 +895,12 @@ class Product(UncloudModel): if being_created: record = OrderRecord( one_time_price=self.one_time_price, - recurring_price=self.recurring_price(recurring_period=self.recurring_period), + recurring_price=self.recurring_price, description=self.description) self.order.orderrecord_set.add(record, bulk=False) @property - def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH): + def recurring_price(self): pass # To be implemented in child. @property @@ -907,6 +911,10 @@ class Product(UncloudModel): def recurring_period(self): return self.order.recurring_period + @property + def billing_address(self): + return self.order.billing_address + @staticmethod def allowed_recurring_periods(): return RecurringPeriod.choices diff --git a/uncloud_django_based/uncloud/uncloud_pay/serializers.py b/uncloud_django_based/uncloud/uncloud_pay/serializers.py index 659092c..1f6eb62 100644 --- a/uncloud_django_based/uncloud/uncloud_pay/serializers.py +++ b/uncloud_django_based/uncloud/uncloud_pay/serializers.py @@ -56,6 +56,13 @@ class BillRecordSerializer(serializers.Serializer): order = serializers.HyperlinkedRelatedField( view_name='order-detail', read_only=True) + description = serializers.CharField() + one_time_price = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS) + recurring_price = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS) + recurring_period = serializers.ChoiceField(choices=RecurringPeriod.choices) + recurring_count = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS) + vat = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS) + amount = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS) class BillingAddressSerializer(serializers.ModelSerializer): class Meta: