Add initial generate-bills and charge-negative-balance uncloud-pay

commands
This commit is contained in:
fnux 2020-02-28 08:59:32 +01:00
commit 059791e2f2
10 changed files with 275 additions and 12 deletions

View file

@ -19,21 +19,26 @@ class RecurringPeriod(models.TextChoices):
PER_SECOND = 'SECOND', _('Per Second')
class Bill(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(),
on_delete=models.CASCADE)
creation_date = models.DateTimeField()
creation_date = models.DateTimeField(auto_now_add=True)
starting_date = models.DateTimeField()
ending_date = models.DateTimeField()
due_date = models.DateField()
paid = models.BooleanField(default=False)
valid = models.BooleanField(default=True)
@property
def amount(self):
# iterate over all related orders
return 20
orders = Order.objects.filter(bill=self)
amount = 0
for order in orders:
amount += order.recurring_price
return amount
class Order(models.Model):
@ -49,8 +54,7 @@ class Order(models.Model):
bill = models.ManyToManyField(Bill,
editable=False,
blank=True,
null=True)
blank=True)
recurring_price = models.FloatField(editable=False)