mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[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:
committed by
Francisco Ivan Anton Prieto
parent
87babeba9f
commit
e63ad7d15f
@@ -358,20 +358,51 @@ class ContractLine(models.Model):
|
||||
@api.model
|
||||
def _get_recurring_next_date(
|
||||
self,
|
||||
date_start,
|
||||
next_period_date_start,
|
||||
recurring_invoicing_type,
|
||||
recurring_rule_type,
|
||||
recurring_interval,
|
||||
):
|
||||
next_period_date_end = self._get_next_period_date_end(
|
||||
next_period_date_start,
|
||||
recurring_rule_type,
|
||||
recurring_interval,
|
||||
max_date_end=False, # TODO
|
||||
)
|
||||
if recurring_rule_type == 'monthlylastday':
|
||||
return date_start + self.get_relative_delta(
|
||||
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
|
||||
)
|
||||
if recurring_invoicing_type == 'pre-paid':
|
||||
return date_start
|
||||
return date_start + self.get_relative_delta(
|
||||
)
|
||||
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
|
||||
def _get_first_date_end(
|
||||
|
||||
Reference in New Issue
Block a user