forked from uncloud/uncloud
Handle setup fee in bills
This commit is contained in:
parent
9fdf66ed74
commit
2eaaad49db
2 changed files with 10 additions and 6 deletions
|
@ -167,22 +167,25 @@ class BillRecord():
|
||||||
self.bill.starting_date.year,
|
self.bill.starting_date.year,
|
||||||
self.bill.starting_date.month)
|
self.bill.starting_date.month)
|
||||||
adjusted_recurring_price = self.recurring_price / days_in_month
|
adjusted_recurring_price = self.recurring_price / days_in_month
|
||||||
recurring_price = adjusted_recurring_price * days
|
amount = adjusted_recurring_price * days
|
||||||
|
|
||||||
return self.recurring_price # TODO
|
|
||||||
elif self.recurring_period == RecurringPeriod.PER_DAY:
|
elif self.recurring_period == RecurringPeriod.PER_DAY:
|
||||||
days = ceil(billed_delta / timedelta(days=1))
|
days = ceil(billed_delta / timedelta(days=1))
|
||||||
return self.recurring_price * days
|
amount = self.recurring_price * days
|
||||||
elif self.recurring_period == RecurringPeriod.PER_HOUR:
|
elif self.recurring_period == RecurringPeriod.PER_HOUR:
|
||||||
hours = ceil(billed_delta / timedelta(hours=1))
|
hours = ceil(billed_delta / timedelta(hours=1))
|
||||||
return self.recurring_price * hours
|
amount = self.recurring_price * hours
|
||||||
elif self.recurring_period == RecurringPeriod.PER_SECOND:
|
elif self.recurring_period == RecurringPeriod.PER_SECOND:
|
||||||
seconds = ceil(billed_delta / timedelta(seconds=1))
|
seconds = ceil(billed_delta / timedelta(seconds=1))
|
||||||
return self.recurring_price * seconds
|
amount = self.recurring_price * seconds
|
||||||
else:
|
else:
|
||||||
raise Exception('Unsupported recurring period: {}.'.
|
raise Exception('Unsupported recurring period: {}.'.
|
||||||
format(record.recurring_period))
|
format(record.recurring_period))
|
||||||
|
|
||||||
|
if self.order.starting_date > self.bill.starting_date:
|
||||||
|
amount += self.setup_fee
|
||||||
|
|
||||||
|
return amount
|
||||||
|
|
||||||
###
|
###
|
||||||
# Orders.
|
# Orders.
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ class BillRecordSerializer(serializers.Serializer):
|
||||||
description = serializers.CharField()
|
description = serializers.CharField()
|
||||||
recurring_period = serializers.CharField()
|
recurring_period = serializers.CharField()
|
||||||
recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2)
|
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)
|
amount = serializers.DecimalField(max_digits=10, decimal_places=2)
|
||||||
|
|
||||||
class BillSerializer(serializers.ModelSerializer):
|
class BillSerializer(serializers.ModelSerializer):
|
||||||
|
|
Loading…
Reference in a new issue