From 2eaaad49db737157f8a86682e78cbc3f0c4c6b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Tue, 3 Mar 2020 10:59:21 +0100 Subject: [PATCH] Handle setup fee in bills --- uncloud/uncloud_pay/models.py | 15 +++++++++------ uncloud/uncloud_pay/serializers.py | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py index 8964cb3..24cc858 100644 --- a/uncloud/uncloud_pay/models.py +++ b/uncloud/uncloud_pay/models.py @@ -167,22 +167,25 @@ class BillRecord(): self.bill.starting_date.year, self.bill.starting_date.month) adjusted_recurring_price = self.recurring_price / days_in_month - recurring_price = adjusted_recurring_price * days - - return self.recurring_price # TODO + amount = adjusted_recurring_price * days elif self.recurring_period == RecurringPeriod.PER_DAY: days = ceil(billed_delta / timedelta(days=1)) - return self.recurring_price * days + amount = self.recurring_price * days elif self.recurring_period == RecurringPeriod.PER_HOUR: hours = ceil(billed_delta / timedelta(hours=1)) - return self.recurring_price * hours + amount = self.recurring_price * hours elif self.recurring_period == RecurringPeriod.PER_SECOND: seconds = ceil(billed_delta / timedelta(seconds=1)) - return self.recurring_price * seconds + amount = self.recurring_price * seconds else: raise Exception('Unsupported recurring period: {}.'. format(record.recurring_period)) + if self.order.starting_date > self.bill.starting_date: + amount += self.setup_fee + + return amount + ### # Orders. diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index 6e4b2d3..fcbaf73 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -96,6 +96,7 @@ class BillRecordSerializer(serializers.Serializer): description = serializers.CharField() recurring_period = serializers.CharField() recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2) + setup_fee = serializers.DecimalField(max_digits=10, decimal_places=2) amount = serializers.DecimalField(max_digits=10, decimal_places=2) class BillSerializer(serializers.ModelSerializer):