mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[REF] contract: refactor _get_period_to_invoice
Move the part of the logic that compute the next period depending on the chosen next invoice date to _get_next_period_date_end.
This commit is contained in:
committed by
Pedro M. Baeza
parent
a040b1c066
commit
ab49596169
@@ -374,6 +374,7 @@ class ContractLine(models.Model):
|
|||||||
):
|
):
|
||||||
next_period_date_end = self._get_next_period_date_end(
|
next_period_date_end = self._get_next_period_date_end(
|
||||||
next_period_date_start,
|
next_period_date_start,
|
||||||
|
recurring_invoicing_type,
|
||||||
recurring_rule_type,
|
recurring_rule_type,
|
||||||
recurring_interval,
|
recurring_interval,
|
||||||
max_date_end=max_date_end,
|
max_date_end=max_date_end,
|
||||||
@@ -392,9 +393,11 @@ class ContractLine(models.Model):
|
|||||||
def _get_next_period_date_end(
|
def _get_next_period_date_end(
|
||||||
self,
|
self,
|
||||||
next_period_date_start,
|
next_period_date_start,
|
||||||
|
recurring_invoicing_type,
|
||||||
recurring_rule_type,
|
recurring_rule_type,
|
||||||
recurring_interval,
|
recurring_interval,
|
||||||
max_date_end,
|
max_date_end,
|
||||||
|
next_invoice_date=False,
|
||||||
):
|
):
|
||||||
"""Compute the end date for the next period"""
|
"""Compute the end date for the next period"""
|
||||||
if not next_period_date_start:
|
if not next_period_date_start:
|
||||||
@@ -402,21 +405,39 @@ class ContractLine(models.Model):
|
|||||||
if max_date_end and next_period_date_start > max_date_end:
|
if max_date_end and next_period_date_start > max_date_end:
|
||||||
# start is past max date end: there is no next period
|
# start is past max date end: there is no next period
|
||||||
return False
|
return False
|
||||||
if recurring_rule_type == 'monthlylastday':
|
if not next_invoice_date:
|
||||||
next_period_date_end = (
|
# regular algorithm
|
||||||
next_period_date_start
|
if recurring_rule_type == 'monthlylastday':
|
||||||
+ self.get_relative_delta(
|
next_period_date_end = (
|
||||||
recurring_rule_type, recurring_interval - 1
|
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)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
next_period_date_end = (
|
# special algorithm when the next invoice date is forced
|
||||||
next_period_date_start
|
if recurring_rule_type == 'monthlylastday':
|
||||||
+ self.get_relative_delta(
|
next_period_date_end = next_invoice_date
|
||||||
recurring_rule_type, recurring_interval
|
elif recurring_invoicing_type == 'pre-paid':
|
||||||
|
next_period_date_end = (
|
||||||
|
next_invoice_date
|
||||||
|
+ self.get_relative_delta(
|
||||||
|
recurring_rule_type, recurring_interval
|
||||||
|
)
|
||||||
|
- relativedelta(days=1)
|
||||||
|
)
|
||||||
|
else: # post-paid
|
||||||
|
next_period_date_end = next_invoice_date - relativedelta(
|
||||||
|
days=1
|
||||||
)
|
)
|
||||||
- relativedelta(days=1)
|
|
||||||
)
|
|
||||||
if max_date_end and next_period_date_end > max_date_end:
|
if max_date_end and next_period_date_end > max_date_end:
|
||||||
# end date is past max_date_end: trim it
|
# end date is past max_date_end: trim it
|
||||||
next_period_date_end = max_date_end
|
next_period_date_end = max_date_end
|
||||||
@@ -437,6 +458,7 @@ class ContractLine(models.Model):
|
|||||||
|
|
||||||
@api.depends(
|
@api.depends(
|
||||||
'next_period_date_start',
|
'next_period_date_start',
|
||||||
|
'recurring_invoicing_type',
|
||||||
'recurring_rule_type',
|
'recurring_rule_type',
|
||||||
'recurring_interval',
|
'recurring_interval',
|
||||||
'date_end',
|
'date_end',
|
||||||
@@ -445,9 +467,11 @@ class ContractLine(models.Model):
|
|||||||
for rec in self:
|
for rec in self:
|
||||||
rec.next_period_date_end = self._get_next_period_date_end(
|
rec.next_period_date_end = self._get_next_period_date_end(
|
||||||
rec.next_period_date_start,
|
rec.next_period_date_start,
|
||||||
|
rec.recurring_invoicing_type,
|
||||||
rec.recurring_rule_type,
|
rec.recurring_rule_type,
|
||||||
rec.recurring_interval,
|
rec.recurring_interval,
|
||||||
max_date_end=rec.date_end,
|
max_date_end=rec.date_end,
|
||||||
|
next_invoice_date=rec.recurring_next_date,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -612,6 +636,8 @@ class ContractLine(models.Model):
|
|||||||
def _get_period_to_invoice(
|
def _get_period_to_invoice(
|
||||||
self, last_date_invoiced, recurring_next_date, stop_at_date_end=True
|
self, last_date_invoiced, recurring_next_date, stop_at_date_end=True
|
||||||
):
|
):
|
||||||
|
# TODO this method can now be removed, since
|
||||||
|
# TODO self.next_period_date_start/end have the same values
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
first_date_invoiced = False
|
first_date_invoiced = False
|
||||||
if not recurring_next_date:
|
if not recurring_next_date:
|
||||||
@@ -621,24 +647,14 @@ class ContractLine(models.Model):
|
|||||||
if last_date_invoiced
|
if last_date_invoiced
|
||||||
else self.date_start
|
else self.date_start
|
||||||
)
|
)
|
||||||
if self.recurring_rule_type == 'monthlylastday':
|
last_date_invoiced = self._get_next_period_date_end(
|
||||||
last_date_invoiced = recurring_next_date
|
first_date_invoiced,
|
||||||
else:
|
self.recurring_invoicing_type,
|
||||||
if self.recurring_invoicing_type == 'pre-paid':
|
self.recurring_rule_type,
|
||||||
last_date_invoiced = (
|
self.recurring_interval,
|
||||||
recurring_next_date
|
max_date_end=(self.date_end if stop_at_date_end else False),
|
||||||
+ self.get_relative_delta(
|
next_invoice_date=recurring_next_date,
|
||||||
self.recurring_rule_type, self.recurring_interval
|
)
|
||||||
)
|
|
||||||
- relativedelta(days=1)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
last_date_invoiced = recurring_next_date - relativedelta(
|
|
||||||
days=1
|
|
||||||
)
|
|
||||||
if stop_at_date_end:
|
|
||||||
if self.date_end and self.date_end < last_date_invoiced:
|
|
||||||
last_date_invoiced = self.date_end
|
|
||||||
return first_date_invoiced, last_date_invoiced, recurring_next_date
|
return first_date_invoiced, last_date_invoiced, recurring_next_date
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
|||||||
Reference in New Issue
Block a user