Handle edge cases of last day of the month of billing period.

This commit is contained in:
Santiago L 2021-03-31 12:11:53 +02:00
parent dc722ec17a
commit 2b06652a5b

View file

@ -151,7 +151,10 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount):
else:
date = timezone.now().date()
if self.billing_point == self.ON_REGISTER:
day = order.registered_on.day
# handle edge cases of last day of the month:
# e.g. on March is 31 but on April 30
last_day_of_month = calendar.monthrange(date.year, date.month)[1]
day = min(last_day_of_month, order.registered_on.day)
elif self.billing_point == self.FIXED_DATE:
day = 1
else:
@ -171,6 +174,11 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount):
year = bp.year - relativedelta.relativedelta(years=1)
if bp.month >= month:
year = bp.year + 1
# handle edge cases of last day of the month:
# e.g. on March is 31 but on April 30
last_day_of_month = calendar.monthrange(year,month)[1]
day = min(last_day_of_month, day)
bp = datetime.date(year=year, month=month, day=day)
elif self.billing_period == self.NEVER:
bp = order.registered_on