Add records to orders

This commit is contained in:
fnux 2020-03-02 09:25:03 +01:00
commit 81bd54116a
4 changed files with 34 additions and 16 deletions

View file

@ -65,16 +65,6 @@ class BillEntry():
# confusing: the order is a 'contract' with the customer, were both parts
# agree on deal => That's what we want to keep archived.
#
# SOON:
#
# We'll need to add some kind of OrderEntry table (each order might have
# multiple entries) storing: recurring_price, recurring_period, setup_fee, description
#
# FOR NOW:
#
# We dynamically get pricing from linked product, as they are not updated in
# this stage of development.
#
# /!\ BIG FAT WARNING /!\ #
class Order(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
@ -95,11 +85,23 @@ class Order(models.Model):
choices = RecurringPeriod.choices,
default = RecurringPeriod.PER_MONTH)
@property
def records(self):
return OrderRecord.objects.filter(order=self)
@property
def amount(self):
records = OrderRecord.objects.filter(order=self)
return 1
def setup_fee(self):
return reduce(lambda acc, record: acc + record.setup_fee, self.records, 0)
@property
def recurring_price(self):
return reduce(lambda acc, record: acc + record.recurring_price, self.records, 0)
def add_record(self, setup_fee, recurring_price, description):
OrderRecord.objects.create(order=self,
setup_fee=setup_fee,
recurring_price=recurring_price,
description=description)
class OrderRecord(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE)