Display allr elevant values on Bill serializer/page
This commit is contained in:
parent
a49fe6ff51
commit
db9ff5d18b
2 changed files with 20 additions and 5 deletions
|
@ -525,10 +525,11 @@ class Bill(models.Model):
|
|||
|
||||
@property
|
||||
def billing_address(self):
|
||||
return self.order.billing_address
|
||||
# FIXME: make sure all the orders of a bill match the same billing address.
|
||||
orders = Order.objects.filter(bill=self)
|
||||
return orders[0].billing_address
|
||||
|
||||
@staticmethod
|
||||
|
||||
def generate_for(year, month, user):
|
||||
# /!\ We exclusively work on the specified year and month.
|
||||
generated_bills = []
|
||||
|
@ -605,7 +606,6 @@ class Bill(models.Model):
|
|||
|
||||
# Handle yearly bills starting on working month.
|
||||
if len(unpaid_orders['yearly']) > 0:
|
||||
|
||||
# For every starting date, generate new bill.
|
||||
for next_yearly_bill_start_on in unpaid_orders['yearly']:
|
||||
# No postpaid for yearly payments.
|
||||
|
@ -735,6 +735,10 @@ class BillRecord():
|
|||
raise Exception('Unsupported recurring period: {}.'.
|
||||
format(record.recurring_period))
|
||||
|
||||
@property
|
||||
def vat(self):
|
||||
return 0
|
||||
|
||||
@property
|
||||
def amount(self):
|
||||
return Decimal(float(self.recurring_price) * self.recurring_count) + self.one_time_price
|
||||
|
@ -891,12 +895,12 @@ class Product(UncloudModel):
|
|||
if being_created:
|
||||
record = OrderRecord(
|
||||
one_time_price=self.one_time_price,
|
||||
recurring_price=self.recurring_price(recurring_period=self.recurring_period),
|
||||
recurring_price=self.recurring_price,
|
||||
description=self.description)
|
||||
self.order.orderrecord_set.add(record, bulk=False)
|
||||
|
||||
@property
|
||||
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
||||
def recurring_price(self):
|
||||
pass # To be implemented in child.
|
||||
|
||||
@property
|
||||
|
@ -907,6 +911,10 @@ class Product(UncloudModel):
|
|||
def recurring_period(self):
|
||||
return self.order.recurring_period
|
||||
|
||||
@property
|
||||
def billing_address(self):
|
||||
return self.order.billing_address
|
||||
|
||||
@staticmethod
|
||||
def allowed_recurring_periods():
|
||||
return RecurringPeriod.choices
|
||||
|
|
|
@ -56,6 +56,13 @@ class BillRecordSerializer(serializers.Serializer):
|
|||
order = serializers.HyperlinkedRelatedField(
|
||||
view_name='order-detail',
|
||||
read_only=True)
|
||||
description = serializers.CharField()
|
||||
one_time_price = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS)
|
||||
recurring_price = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS)
|
||||
recurring_period = serializers.ChoiceField(choices=RecurringPeriod.choices)
|
||||
recurring_count = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS)
|
||||
vat = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS)
|
||||
amount = serializers.DecimalField(AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS)
|
||||
|
||||
class BillingAddressSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
|
Loading…
Reference in a new issue