Cleanup a bit BillRecord

This commit is contained in:
fnux 2020-03-02 16:41:49 +01:00
parent 9e9018060e
commit c651c4ddaa
2 changed files with 8 additions and 12 deletions

View file

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

View file

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