Skip to content

Commit f31907c

Browse files
authored
Merge pull request #764 from uw-it-aca/fix/itbill-billing-dates
quantity calc based on itbill billing period
2 parents 937a218 + e3069fa commit f31907c

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

endorsement/models/itbill.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django_prometheus.models import ExportModelOperationsMixin
88
from endorsement.util.date import datetime_to_str, date_to_str
99
from endorsement.util.key_remote import key_remote
10+
from datetime import date
1011
import json
1112

1213

@@ -102,16 +103,25 @@ def current_quantity(self):
102103

103104
def get_quantity_on_date(self, now):
104105
"""
105-
Walks Provisions list to return the subscribed quota
106-
associated with the given date
106+
Walks provision quantities to return the subscribed quota
107+
associated with the given date. Quantity dates must fall
108+
within ITBill billing period, which is December 1st to
109+
November 30th of the following year.
107110
"""
111+
billing_period_start_year = now.year if (
112+
now.month == 12) else now.year - 1
113+
billing_period_end_year = now.year if (
114+
now.month < 12) else now.year + 1
115+
billing_period_start_date = date(billing_period_start_year, 12, 1)
116+
billing_period_end_date = date(billing_period_end_year, 11, 30)
117+
108118
current_quantity = 0
109119
if self.state == self.SUBSCRIPTION_DEPLOYED:
110120
for provision in self.get_provisions():
111121
for quantity in provision.get_quantities():
112-
if (quantity.start_date <= now
113-
and (quantity.end_date is None
114-
or quantity.end_date >= now)):
122+
if ((not quantity.end_date
123+
or quantity.end_date > billing_period_start_date)
124+
and quantity.start_date < billing_period_end_date):
115125
current_quantity += quantity.quantity
116126

117127
return current_quantity

endorsement/static/endorsement/js/tab/google.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ var ManageSharedDrives = (function () {
189189
_prepSharedDriveContext = function (drive) {
190190
var expiration = moment(drive.datetime_expiration),
191191
deadline = moment(drive.datetime_subscription_deadline),
192-
now = moment.utc();
192+
now = moment.utc(),
193+
billing_period_start = moment(((now.month() == 11) ? now.year() : now.year() - 1) + '-12-01'),
194+
billing_period_end = moment(((now.month() == 11) ? now.year() + 1 : now.year()) + '-11-30');
193195

194196
drive.expiration_date = expiration.format('M/D/YYYY');
195197
drive.expiration_days = expiration.diff(now, 'days');
@@ -212,8 +214,8 @@ var ManageSharedDrives = (function () {
212214
$.each(this.quantities, function () {
213215
var starting = this.start_date ? moment(this.start_date) : null,
214216
ending = this.end_date ? moment(this.end_date): null,
215-
is_future = starting && starting.diff(now) > 0,
216-
is_ending = starting && ending && starting.diff(now) < 0 && ending.diff(now) > 0,
217+
is_future = starting && starting.diff(billing_period_end) > 0 && this.quota_limit != drive.drive.drive_quota.quota_limit,
218+
is_ending = ending && ending.diff(billing_period_end) < 0,
217219
is_increasing = this.quota_limit > drive.drive.drive_quota.quota_limit,
218220
is_decreasing = this.quota_limit < drive.drive.drive_quota.quota_limit,
219221
is_changing = (is_future || is_ending);

endorsement/test/models/test_itbill.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_current_quota(self):
2323
record = SharedDriveRecord.objects.get(
2424
shared_drive__drive_id='IRDXB54TWF3OY8MVC9J')
2525

26-
now = datetime.strptime('2023-12-31', '%Y-%m-%d').date()
26+
now = datetime.strptime('2023-11-30', '%Y-%m-%d').date()
2727
quota = record.subscription.get_quantity_on_date(now)
2828
self.assertEqual(quota, 0)
2929

@@ -43,6 +43,6 @@ def test_current_quota(self):
4343
quota = record.subscription.get_quantity_on_date(now)
4444
self.assertEqual(quota, 2)
4545

46-
now = datetime.strptime('2024-12-30', '%Y-%m-%d').date()
46+
now = datetime.strptime('2025-12-01', '%Y-%m-%d').date()
4747
quota = record.subscription.get_quantity_on_date(now)
4848
self.assertEqual(quota, 0)

0 commit comments

Comments
 (0)