From 9558ed1a8fd042b4c162ff48be495468673a1e1b Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 14 Mar 2019 15:15:14 +0100 Subject: [PATCH] [FIX] - forecast should continue after contract line date_end if ot is set to auto_renew --- contract_forecast/models/contract_line.py | 13 +++++---- .../test_contract_line_forecast_period.py | 28 +++++++++++++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/contract_forecast/models/contract_line.py b/contract_forecast/models/contract_line.py index 30c31e58..a2b61b94 100644 --- a/contract_forecast/models/contract_line.py +++ b/contract_forecast/models/contract_line.py @@ -54,11 +54,11 @@ class AccountAnalyticInvoiceLine(models.Model): if self.is_canceled or not self.active: return False contract_forecast_end_date = self._get_contract_forecast_end_date() - if not self.date_end: - return period_date_end <= contract_forecast_end_date + if not self.date_end or self.is_auto_renew: + return period_date_end < contract_forecast_end_date return ( period_date_end < self.date_end - and period_date_end <= contract_forecast_end_date + and period_date_end < contract_forecast_end_date ) @api.multi @@ -71,7 +71,7 @@ class AccountAnalyticInvoiceLine(models.Model): last_date_invoiced = ( rec.last_date_invoiced if rec.last_date_invoiced - else rec.date_start + else rec.date_start - relativedelta(days=1) ) period_date_end = last_date_invoiced recurring_next_date = rec.recurring_next_date @@ -79,7 +79,9 @@ class AccountAnalyticInvoiceLine(models.Model): period_date_end ): period_dates = rec._get_period_to_invoice( - last_date_invoiced, recurring_next_date + last_date_invoiced, + recurring_next_date, + stop_at_date_end=not rec.is_auto_renew, ) period_date_start, period_date_end, recurring_next_date = ( period_dates @@ -124,6 +126,7 @@ class AccountAnalyticInvoiceLine(models.Model): "recurring_interval", "is_canceled", "active", + "is_auto_renew", ] @api.multi diff --git a/contract_forecast/tests/test_contract_line_forecast_period.py b/contract_forecast/tests/test_contract_line_forecast_period.py index c729e250..ca4716d0 100644 --- a/contract_forecast/tests/test_contract_line_forecast_period.py +++ b/contract_forecast/tests/test_contract_line_forecast_period.py @@ -115,3 +115,31 @@ class TestContractLineForecastPeriod(TestContractBase): ) self.assertTrue(self.acct_line.forecast_period_ids) self.assertEqual(len(self.acct_line.forecast_period_ids), 1) + + @mute_logger("odoo.addons.queue_job.models.base") + def test_forecast_period_on_contract_line_update_7(self): + self.acct_line.write( + { + 'date_end': "2019-6-05", + 'recurring_rule_type': "monthlylastday", + 'recurring_invoicing_type': 'pre-paid', + 'is_auto_renew': True, + } + ) + self.acct_line._onchange_date_start() + self.assertTrue(self.acct_line.forecast_period_ids) + self.assertEqual(len(self.acct_line.forecast_period_ids), 13) + + @mute_logger("odoo.addons.queue_job.models.base") + def test_forecast_period_on_contract_line_update_8(self): + self.acct_line.write( + { + 'date_start': "2019-01-14", + 'recurring_next_date': "2019-01-31", + 'date_end': "2019-01-14", + 'recurring_rule_type': "monthlylastday", + 'recurring_invoicing_type': 'post-paid', + } + ) + self.assertTrue(self.acct_line.forecast_period_ids) + self.assertEqual(len(self.acct_line.forecast_period_ids), 1)