Handle edge cases of last day of the month of billing period.
This commit is contained in:
parent
dc722ec17a
commit
2b06652a5b
|
@ -151,7 +151,10 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
else:
|
else:
|
||||||
date = timezone.now().date()
|
date = timezone.now().date()
|
||||||
if self.billing_point == self.ON_REGISTER:
|
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:
|
elif self.billing_point == self.FIXED_DATE:
|
||||||
day = 1
|
day = 1
|
||||||
else:
|
else:
|
||||||
|
@ -171,6 +174,11 @@ class ServiceHandler(plugins.Plugin, metaclass=plugins.PluginMount):
|
||||||
year = bp.year - relativedelta.relativedelta(years=1)
|
year = bp.year - relativedelta.relativedelta(years=1)
|
||||||
if bp.month >= month:
|
if bp.month >= month:
|
||||||
year = bp.year + 1
|
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)
|
bp = datetime.date(year=year, month=month, day=day)
|
||||||
elif self.billing_period == self.NEVER:
|
elif self.billing_period == self.NEVER:
|
||||||
bp = order.registered_on
|
bp = order.registered_on
|
||||||
|
|
Loading…
Reference in New Issue