From 126d9da764ed5396daca8dd72ebecadd77b6bba8 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 21 Jun 2020 16:42:55 +0200 Subject: [PATCH] Use quantity instead of usage_count --- uncloud_pay/admin.py | 2 +- .../migrations/0003_auto_20200621_1442.py | 18 ++++++++++++++++++ uncloud_pay/models.py | 8 ++++---- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 uncloud_pay/migrations/0003_auto_20200621_1442.py diff --git a/uncloud_pay/admin.py b/uncloud_pay/admin.py index 4135432..a78462b 100644 --- a/uncloud_pay/admin.py +++ b/uncloud_pay/admin.py @@ -7,7 +7,7 @@ class BillRecordInline(admin.TabularInline): class BillAdmin(admin.ModelAdmin): inlines = [ BillRecordInline ] -; + admin.site.register(Bill, BillAdmin) admin.site.register(Order) admin.site.register(BillRecord) diff --git a/uncloud_pay/migrations/0003_auto_20200621_1442.py b/uncloud_pay/migrations/0003_auto_20200621_1442.py new file mode 100644 index 0000000..89e49cd --- /dev/null +++ b/uncloud_pay/migrations/0003_auto_20200621_1442.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.6 on 2020-06-21 14:42 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0002_auto_20200621_1335'), + ] + + operations = [ + migrations.RenameField( + model_name='billrecord', + old_name='usage_count', + new_name='quantity', + ), + ] diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 0afd135..94961c2 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -336,7 +336,7 @@ class Order(models.Model): This logic is mainly thought to be for recurring bills, but also works for one time bills """ - return sum([ br.usage_count for br in self.bill_records.all() ]) + return sum([ br.quantity for br in self.bill_records.all() ]) def active_before(self, ending_date): @@ -502,7 +502,7 @@ class Bill(models.Model): bill_records=None): bill_record = BillRecord.objects.create(bill=self, - usage_count=1, + quantity=1, starting_date=order.starting_date, ending_date=order.starting_date + timedelta(seconds=order.recurring_period)) @@ -539,7 +539,7 @@ class BillRecord(models.Model): order = models.ForeignKey(Order, on_delete=models.CASCADE) # How many times the order has been used in this record - usage_count = models.IntegerField(default=1) + quantity = models.IntegerField(default=1) # The timeframe the bill record is for can (and probably often will) differ # from the bill time @@ -548,7 +548,7 @@ class BillRecord(models.Model): ending_date = models.DateTimeField() def __str__(self): - return f"{self.bill}: {self.usage_count} x {self.order}" + return f"{self.bill}: {self.quantity} x {self.order}" class OrderRecord(models.Model):