Skip to content

Commit 44955ef

Browse files
committed
distinct quantity and quota calc
1 parent c6a954d commit 44955ef

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

endorsement/models/itbill.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ def clear_provisions(self):
9292

9393
@property
9494
def current_quota(self):
95-
return self.get_quota_on_date(timezone.now().date())
95+
return (self.current_quantity * 100) + getattr(
96+
settings, "ITBILL_SHARED_DRIVE_SUBSIDIZED_QUOTA"
97+
)
98+
99+
@property
100+
def current_quantity(self):
101+
return self.get_quantity_on_date(timezone.now().date())
96102

97-
def get_quota_on_date(self, now):
103+
def get_quantity_on_date(self, now):
98104
"""
99105
Walks Provisions list to return the subscribed quota
100106
associated with the given date
@@ -106,9 +112,9 @@ def get_quota_on_date(self, now):
106112
if (quantity.start_date <= now
107113
and (quantity.end_date is None
108114
or quantity.end_date >= now)):
109-
current_quantity += quantity.quantity_gigabytes
115+
current_quantity += quantity.quantity
110116

111-
return current_quantity if current_quantity else None
117+
return current_quantity
112118

113119
def json_data(self):
114120
return {
@@ -135,12 +141,6 @@ class ITBillProvision(
135141
)
136142
current_quantity = models.IntegerField()
137143

138-
@property
139-
def current_quantity_gigabytes(self):
140-
return (self.current_quantity * 100) + getattr(
141-
settings, "ITBILL_SHARED_DRIVE_SUBSIDIZED_QUOTA"
142-
)
143-
144144
def from_json(self, provision):
145145
for quantity in provision.quantities:
146146
self.set_quantity(quantity)

endorsement/test/models/test_itbill.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ def test_current_quota(self):
2424
shared_drive__drive_id='IRDXB54TWF3OY8MVC9J')
2525

2626
now = datetime.strptime('2023-12-31', '%Y-%m-%d').date()
27-
quota = record.subscription.get_quota_on_date(now)
28-
self.assertEqual(quota, None)
27+
quota = record.subscription.get_quantity_on_date(now)
28+
self.assertEqual(quota, 0)
2929

3030
now = datetime.strptime('2024-01-01', '%Y-%m-%d').date()
31-
quota = record.subscription.get_quota_on_date(now)
32-
self.assertEqual(quota, 300)
31+
quota = record.subscription.get_quantity_on_date(now)
32+
self.assertEqual(quota, 2)
3333

3434
now = datetime.strptime('2024-01-02', '%Y-%m-%d').date()
35-
quota = record.subscription.get_quota_on_date(now)
36-
self.assertEqual(quota, 300)
35+
quota = record.subscription.get_quantity_on_date(now)
36+
self.assertEqual(quota, 2)
3737

3838
now = datetime.strptime('2024-12-28', '%Y-%m-%d').date()
39-
quota = record.subscription.get_quota_on_date(now)
40-
self.assertEqual(quota, 300)
39+
quota = record.subscription.get_quantity_on_date(now)
40+
self.assertEqual(quota, 2)
4141

4242
now = datetime.strptime('2024-12-29', '%Y-%m-%d').date()
43-
quota = record.subscription.get_quota_on_date(now)
44-
self.assertEqual(quota, 300)
43+
quota = record.subscription.get_quantity_on_date(now)
44+
self.assertEqual(quota, 2)
4545

4646
now = datetime.strptime('2024-12-30', '%Y-%m-%d').date()
47-
quota = record.subscription.get_quota_on_date(now)
48-
self.assertEqual(quota, None)
47+
quota = record.subscription.get_quantity_on_date(now)
48+
self.assertEqual(quota, 0)

0 commit comments

Comments
 (0)