Use quantity instead of usage_count
This commit is contained in:
parent
8a17ee6de5
commit
126d9da764
3 changed files with 23 additions and 5 deletions
|
@ -7,7 +7,7 @@ class BillRecordInline(admin.TabularInline):
|
||||||
|
|
||||||
class BillAdmin(admin.ModelAdmin):
|
class BillAdmin(admin.ModelAdmin):
|
||||||
inlines = [ BillRecordInline ]
|
inlines = [ BillRecordInline ]
|
||||||
;
|
|
||||||
admin.site.register(Bill, BillAdmin)
|
admin.site.register(Bill, BillAdmin)
|
||||||
admin.site.register(Order)
|
admin.site.register(Order)
|
||||||
admin.site.register(BillRecord)
|
admin.site.register(BillRecord)
|
||||||
|
|
18
uncloud_pay/migrations/0003_auto_20200621_1442.py
Normal file
18
uncloud_pay/migrations/0003_auto_20200621_1442.py
Normal file
|
@ -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',
|
||||||
|
),
|
||||||
|
]
|
|
@ -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
|
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):
|
def active_before(self, ending_date):
|
||||||
|
@ -502,7 +502,7 @@ class Bill(models.Model):
|
||||||
bill_records=None):
|
bill_records=None):
|
||||||
|
|
||||||
bill_record = BillRecord.objects.create(bill=self,
|
bill_record = BillRecord.objects.create(bill=self,
|
||||||
usage_count=1,
|
quantity=1,
|
||||||
starting_date=order.starting_date,
|
starting_date=order.starting_date,
|
||||||
ending_date=order.starting_date + timedelta(seconds=order.recurring_period))
|
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)
|
order = models.ForeignKey(Order, on_delete=models.CASCADE)
|
||||||
|
|
||||||
# How many times the order has been used in this record
|
# 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
|
# The timeframe the bill record is for can (and probably often will) differ
|
||||||
# from the bill time
|
# from the bill time
|
||||||
|
@ -548,7 +548,7 @@ class BillRecord(models.Model):
|
||||||
ending_date = models.DateTimeField()
|
ending_date = models.DateTimeField()
|
||||||
|
|
||||||
def __str__(self):
|
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):
|
class OrderRecord(models.Model):
|
||||||
|
|
Loading…
Reference in a new issue