From 1c43029541637b0260573043fa77d681c39fdaaf Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Fri, 30 Nov 2018 15:36:19 +0100 Subject: [PATCH] [IMP] - don't allow to unlink uncnaceled contrac line --- contract/models/contract_line.py | 9 +++++++++ contract/tests/test_contract.py | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index 3494b0b2..460990a2 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -946,3 +946,12 @@ class AccountAnalyticInvoiceLine(models.Model): return super(AccountAnalyticInvoiceLine, self).fields_view_get( view_id, view_type, toolbar, submenu ) + + @api.multi + def unlink(self): + """stop unlink uncnacled lines""" + if not all(self.mapped('is_canceled')): + raise ValidationError( + _("Contract line must be canceled before delete") + ) + return super(AccountAnalyticInvoiceLine, self).unlink() diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py index 57abfd75..8843ddcc 100644 --- a/contract/tests/test_contract.py +++ b/contract/tests/test_contract.py @@ -431,7 +431,7 @@ class TestContract(TestContractBase): def test_onchange_contract_template_id_lines(self): """It should create invoice lines for the contract lines.""" - + self.acct_line.cancel() self.acct_line.unlink() self.contract.contract_template_id = self.template @@ -1370,3 +1370,7 @@ class TestContract(TestContractBase): first, last = self.acct_line._get_invoiced_period() self.assertEqual(first, to_date('2020-01-05')) self.assertEqual(last, to_date('2020-03-15')) + + def test_unlink(self): + with self.assertRaises(ValidationError): + self.acct_line.unlink()