Browse Source

[REF] contract: remove one monthlylastday special case

get_relative_delta now works the same for all recurring rules.
Move the special case handling to _init_last_date_invoiced
which is used only for migration.
pull/434/head
Stéphane Bidoul (ACSONE) 5 years ago
parent
commit
d53f01d66f
No known key found for this signature in database GPG Key ID: BCAB2555446B5B92
  1. 21
      contract/models/contract_line.py

21
contract/models/contract_line.py

@ -424,14 +424,6 @@ class ContractLine(models.Model):
return False return False
if not next_invoice_date: if not next_invoice_date:
# regular algorithm # regular algorithm
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_end = (
next_period_date_start next_period_date_start
+ self.get_relative_delta( + self.get_relative_delta(
@ -717,8 +709,9 @@ class ContractLine(models.Model):
last_date_invoiced = ( last_date_invoiced = (
rec.recurring_next_date rec.recurring_next_date
- self.get_relative_delta( - self.get_relative_delta(
rec.recurring_rule_type, rec.recurring_interval
rec.recurring_rule_type, rec.recurring_interval - 1
) )
- relativedelta(days=1)
) )
elif rec.recurring_invoicing_type == 'post-paid': elif rec.recurring_invoicing_type == 'post-paid':
last_date_invoiced = ( last_date_invoiced = (
@ -726,12 +719,18 @@ class ContractLine(models.Model):
- self.get_relative_delta( - self.get_relative_delta(
rec.recurring_rule_type, rec.recurring_interval rec.recurring_rule_type, rec.recurring_interval
) )
) - relativedelta(days=1)
- relativedelta(days=1)
)
if last_date_invoiced > rec.date_start: if last_date_invoiced > rec.date_start:
rec.last_date_invoiced = last_date_invoiced rec.last_date_invoiced = last_date_invoiced
@api.model @api.model
def get_relative_delta(self, recurring_rule_type, interval): def get_relative_delta(self, recurring_rule_type, interval):
"""Return a relativedelta for one period.
When added to the first day of the period,
it gives the first day of the next period.
"""
if recurring_rule_type == 'daily': if recurring_rule_type == 'daily':
return relativedelta(days=interval) return relativedelta(days=interval)
elif recurring_rule_type == 'weekly': elif recurring_rule_type == 'weekly':
@ -739,7 +738,7 @@ class ContractLine(models.Model):
elif recurring_rule_type == 'monthly': elif recurring_rule_type == 'monthly':
return relativedelta(months=interval) return relativedelta(months=interval)
elif recurring_rule_type == 'monthlylastday': elif recurring_rule_type == 'monthlylastday':
return relativedelta(months=interval, day=31)
return relativedelta(months=interval, day=1)
else: else:
return relativedelta(years=interval) return relativedelta(years=interval)

Loading…
Cancel
Save