From 294f92b7ace3fe7dca82e3ba271a845d68e746ec Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Sat, 21 Dec 2019 14:05:15 +0100 Subject: [PATCH 1/2] [12.0][IMP] - Add failing test for next invoice date before the last date invoiced --- contract/tests/test_contract.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index e406a45e..46deda08 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -2280,3 +2280,12 @@ class TestContract(TestContractBase): self.assertTrue(self.acct_line.recurring_next_date) self.acct_line.stop(self.acct_line.last_date_invoiced) self.assertFalse(self.acct_line.recurring_next_date) + + def test_check_last_date_invoiced_before_next_invoice_date(self): + with self.assertRaises(ValidationError): + self.acct_line.write({ + 'date_start': '2019-01-01', + 'date_end': '2019-12-01', + 'recurring_next_date': '2019-01-01', + 'last_date_invoiced': '2019-06-01', + }) From a0d9fa2c99f8fa6a3a6513a3dc24a37cdf108655 Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Sat, 21 Dec 2019 14:11:43 +0100 Subject: [PATCH 2/2] [12.0][FIX] - raise an error when next invoice date before the last date invoiced --- contract/models/contract_line.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index c9d475bd..94ffb08c 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -569,7 +569,9 @@ class ContractLine(models.Model): % line.name ) - @api.constrains('date_start', 'date_end', 'last_date_invoiced') + @api.constrains( + 'date_start', 'date_end', 'last_date_invoiced', 'recurring_next_date' + ) def _check_last_date_invoiced(self): for rec in self.filtered('last_date_invoiced'): if rec.date_start and rec.date_start > rec.last_date_invoiced: @@ -588,6 +590,17 @@ class ContractLine(models.Model): ) % rec.name ) + if ( + rec.recurring_next_date + and rec.recurring_next_date <= rec.last_date_invoiced + ): + raise ValidationError( + _( + "You can't have the next invoice date before the date " + "of last invoice for the contract line '%s'" + ) + % rec.name + ) @api.constrains('recurring_next_date') def _check_recurring_next_date_recurring_invoices(self):