[REF] contract: clarify _get_recurring_next_date

First compute the next period end date,
then derive the next invoice date from the next
period stard and end date.
This commit is contained in:
Stéphane Bidoul (ACSONE)
2019-12-06 10:19:55 +01:00
committed by Francisco Ivan Anton Prieto
parent 87babeba9f
commit e63ad7d15f

View File

@@ -358,20 +358,51 @@ class ContractLine(models.Model):
@api.model @api.model
def _get_recurring_next_date( def _get_recurring_next_date(
self, self,
date_start, next_period_date_start,
recurring_invoicing_type, recurring_invoicing_type,
recurring_rule_type, recurring_rule_type,
recurring_interval, recurring_interval,
): ):
if recurring_rule_type == 'monthlylastday': next_period_date_end = self._get_next_period_date_end(
return date_start + self.get_relative_delta( next_period_date_start,
recurring_rule_type, recurring_interval - 1 recurring_rule_type,
) recurring_interval,
if recurring_invoicing_type == 'pre-paid': max_date_end=False, # TODO
return date_start
return date_start + self.get_relative_delta(
recurring_rule_type, recurring_interval
) )
if recurring_rule_type == 'monthlylastday':
return next_period_date_end
elif recurring_invoicing_type == 'pre-paid':
return next_period_date_start
else: # post-paid
return next_period_date_end + relativedelta(days=1)
@api.model
def _get_next_period_date_end(
self,
next_period_date_start,
recurring_rule_type,
recurring_interval,
max_date_end,
):
"""Compute the end date for the next period"""
if recurring_rule_type == 'monthlylastday':
next_period_date_end = (
next_period_date_start
+ self.get_relative_delta(
recurring_rule_type, recurring_interval - 1
)
)
else:
next_period_date_end = (
next_period_date_start
+ self.get_relative_delta(
recurring_rule_type, recurring_interval
)
- relativedelta(days=1)
)
if max_date_end and next_period_date_end > max_date_end:
next_period_date_end = max_date_end
return next_period_date_end
@api.model @api.model
def _get_first_date_end( def _get_first_date_end(