This commit is contained in:
Nico Schottelius 2020-09-03 17:16:18 +02:00
parent f7274fe967
commit 077c665c53

View file

@ -372,6 +372,24 @@ class Order(models.Model):
return next_date return next_date
def get_ending_date_for_bill(bill):
"""
Determine the ending date given a specific bill
"""
# If the order is quit, charge the final amount (?)
if order.ending_date:
this_ending_date = order.ending_date
else:
if order.earliest_ending_date > bill.ending_date:
this_ending_date = order.earliest_ending_date
else:
this_ending_date = bill.ending_date
return this_ending_date
@property @property
def count_billed(self): def count_billed(self):
""" """
@ -381,7 +399,6 @@ class Order(models.Model):
return sum([ br.quantity for br in self.bill_records.all() ]) return sum([ br.quantity for br in self.bill_records.all() ])
@property
def count_used(self, when=None): def count_used(self, when=None):
""" """
How many times this order was billed so far. How many times this order was billed so far.
@ -401,13 +418,23 @@ class Order(models.Model):
return (when - self.starting_date) / self.default_recurring_period return (when - self.starting_date) / self.default_recurring_period
@property @property
def fully_billed(self, when=None): def all_usage_billed(self, when=None):
""" """
Returns true if this order does not need any further billing Returns true if this order does not need any further billing
ever. In other words: is this order "closed"? ever. In other words: is this order "closed"?
""" """
if self.count_billed == if self.count_billed == self.count_used(when):
return True
else:
return False
@property
def is_closed(self):
if self.all_usage_billed and self.ending_date:
return True
else:
return False
@property @property
def is_recurring(self): def is_recurring(self):
@ -567,7 +594,7 @@ class Bill(models.Model):
this_starting_date = start_after(last_bill_record.ending_date) this_starting_date = start_after(last_bill_record.ending_date)
ending_date = cls.get_bill_record_ending_date(order, bill) ending_date = order.get_ending_date_for_bill(bill)
return BillRecord.objects.create(bill=bill, return BillRecord.objects.create(bill=bill,
order=order, order=order,
@ -595,23 +622,6 @@ class Bill(models.Model):
bill_record_for_this_bill.save() bill_record_for_this_bill.save()
@staticmethod
def get_bill_record_ending_date(order, bill):
"""
Determine the ending date of the billing record
"""
# If the order is quit, charge the final amount (?)
if order.ending_date:
this_ending_date = order.ending_date
else:
if order.earliest_ending_date > bill.ending_date:
this_ending_date = order.earliest_ending_date
else:
this_ending_date = bill.ending_date
return this_ending_date
@classmethod @classmethod
def create_next_bill_for_user_address_old(cls, def create_next_bill_for_user_address_old(cls,
owner, owner,