forked from uncloud/uncloud
Cleanup a bit BillRecord
This commit is contained in:
parent
9e9018060e
commit
c651c4ddaa
2 changed files with 8 additions and 12 deletions
|
@ -38,12 +38,7 @@ class Bill(models.Model):
|
||||||
orders = Order.objects.filter(bill=self)
|
orders = Order.objects.filter(bill=self)
|
||||||
for order in orders:
|
for order in orders:
|
||||||
for order_record in order.records:
|
for order_record in order.records:
|
||||||
bill_record = BillRecord(
|
bill_record = BillRecord(order_record)
|
||||||
self,
|
|
||||||
order_record.setup_fee,
|
|
||||||
order_record.recurring_price,
|
|
||||||
order_record.recurring_period,
|
|
||||||
order_record.description)
|
|
||||||
bill_records.append(bill_record)
|
bill_records.append(bill_record)
|
||||||
|
|
||||||
return bill_records
|
return bill_records
|
||||||
|
@ -53,12 +48,12 @@ class Bill(models.Model):
|
||||||
return reduce(lambda acc, record: acc + record.amount(), self.records, 0)
|
return reduce(lambda acc, record: acc + record.amount(), self.records, 0)
|
||||||
|
|
||||||
class BillRecord():
|
class BillRecord():
|
||||||
def __init__(self, bill, setup_fee, recurring_price, recurring_period, description):
|
def __init__(self, order_record):
|
||||||
self.bill = bill
|
self.order = order_record.order.uuid
|
||||||
self.setup_fee = setup_fee
|
self.setup_fee = order_record.setup_fee
|
||||||
self.recurring_price = recurring_price
|
self.recurring_price = order_record.recurring_price
|
||||||
self.recurring_period = recurring_period
|
self.recurring_period = order_record.recurring_period
|
||||||
self.description = description
|
self.description = order_record.description
|
||||||
|
|
||||||
def amount(self):
|
def amount(self):
|
||||||
# TODO: Billing logic here!
|
# TODO: Billing logic here!
|
||||||
|
|
|
@ -9,6 +9,7 @@ from uncloud_vm.models import VMProduct
|
||||||
|
|
||||||
# TODO: remove magic numbers for decimal fields
|
# TODO: remove magic numbers for decimal fields
|
||||||
class BillRecordSerializer(serializers.Serializer):
|
class BillRecordSerializer(serializers.Serializer):
|
||||||
|
order = serializers.CharField()
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue