From 788aa1ef924c60eb7e63d245b283425f0a2db7de Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Thu, 20 Dec 2018 21:50:30 +0100 Subject: [PATCH] [FIX] - as date_start is required, constraints on it become useless [FIX] - for finished contract _get_lines_to_invoice should return False --- contract/models/contract.py | 8 +++++--- contract/models/contract_line.py | 9 --------- contract/tests/test_contract.py | 5 ----- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/contract/models/contract.py b/contract/models/contract.py index 87156c85..abe72816 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -297,9 +297,11 @@ class AccountAnalyticAccount(models.Model): :return: contract lines (account.analytic.invoice.line recordset) """ self.ensure_one() - return self.recurring_invoice_line_ids.filtered( - lambda l: not l.is_canceled and l.recurring_next_date - and l.recurring_next_date <= date_ref) + if date_ref: + return self.recurring_invoice_line_ids.filtered( + lambda l: not l.is_canceled and l.recurring_next_date + and l.recurring_next_date <= date_ref) + return False @api.multi def _prepare_recurring_invoices_values(self, date_ref=False): diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index c87abf91..d0addafb 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -282,15 +282,6 @@ class AccountAnalyticInvoiceLine(models.Model): % rec.name ) - @api.constrains('date_start') - def _check_date_start_recurring_invoices(self): - for line in self.filtered('contract_id.recurring_invoices'): - if not line.date_start: - raise ValidationError( - _("You must supply a start date for contract line '%s'") - % line.name - ) - @api.constrains('date_start', 'date_end') def _check_start_end_dates(self): for line in self.filtered('date_end'): diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index b1482d03..a15fb0e6 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -417,11 +417,6 @@ class TestContract(TestContractBase): self.contract.write({'recurring_invoices': True}) self.acct_line.write({'recurring_next_date': False}) - def test_check_date_start_recurring_invoices(self): - with self.assertRaises(ValidationError): - self.contract.write({'recurring_invoices': True}) - self.acct_line.write({'date_start': False}) - def test_onchange_contract_template_id(self): """It should change the contract values to match the template.""" self.contract.contract_template_id = self.template