Skip to content

Commit 1788c68

Browse files
committed
Merge branch 'develop' into task/authoritative-msca-delegation
2 parents ece2a52 + 937a218 commit 1788c68

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

endorsement/models/itbill.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,29 @@ 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
101107
"""
108+
current_quantity = 0
102109
if self.state == self.SUBSCRIPTION_DEPLOYED:
103110
for provision in self.get_provisions():
104111
for quantity in provision.get_quantities():
105-
if quantity.start_date <= now:
106-
if (quantity.end_date is None
107-
or quantity.end_date >= now):
108-
return quantity.quantity_gigabytes
112+
if (quantity.start_date <= now
113+
and (quantity.end_date is None
114+
or quantity.end_date >= now)):
115+
current_quantity += quantity.quantity
109116

110-
return None
117+
return current_quantity
111118

112119
def json_data(self):
113120
return {
@@ -134,12 +141,6 @@ class ITBillProvision(
134141
)
135142
current_quantity = models.IntegerField()
136143

137-
@property
138-
def current_quantity_gigabytes(self):
139-
return (self.current_quantity * 100) + getattr(
140-
settings, "ITBILL_SHARED_DRIVE_SUBSIDIZED_QUOTA"
141-
)
142-
143144
def from_json(self, provision):
144145
for quantity in provision.quantities:
145146
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)