Handle setup fee in bills

This commit is contained in:
fnux 2020-03-03 10:59:21 +01:00
parent 9fdf66ed74
commit 2eaaad49db
2 changed files with 10 additions and 6 deletions

View file

@ -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.

View file

@ -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):