From c39162637e1e283936c4fe15f09e7726d5a4aa72 Mon Sep 17 00:00:00 2001 From: Andrea Cometa Date: Sat, 21 May 2022 14:22:06 +0200 Subject: [PATCH] fix typo and add tests --- contract_sequence/models/contract.py | 2 +- contract_sequence/tests/__init__.py | 4 + .../tests/test_contract_sequence.py | 90 +++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 contract_sequence/tests/__init__.py create mode 100644 contract_sequence/tests/test_contract_sequence.py diff --git a/contract_sequence/models/contract.py b/contract_sequence/models/contract.py index 9176affd92f..6aab9a7936d 100644 --- a/contract_sequence/models/contract.py +++ b/contract_sequence/models/contract.py @@ -13,7 +13,7 @@ class ContractContract(models.Model): tracking=True, help="Set to '/' and save if you want a new internal reference " "to be proposed.", - copy="False", + copy=False, ) def get_default_sequence(self): diff --git a/contract_sequence/tests/__init__.py b/contract_sequence/tests/__init__.py new file mode 100644 index 00000000000..69ae3ab8acb --- /dev/null +++ b/contract_sequence/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2022 Andrea Cometa - Apulia Software (www.apuliasoftware.it) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_contract_sequence diff --git a/contract_sequence/tests/test_contract_sequence.py b/contract_sequence/tests/test_contract_sequence.py new file mode 100644 index 00000000000..5243c8c8380 --- /dev/null +++ b/contract_sequence/tests/test_contract_sequence.py @@ -0,0 +1,90 @@ +# Copyright 2022 Andrea Cometa - Apulia Software (www.apuliasoftware.it) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase, tagged + +from ..hooks import pre_init_hook + + +@tagged("post_install", "-at_install") +class TestContractSequence(TransactionCase): + """Tests for creating Contract with and without Sequence""" + + def setUp(self): + super(TestContractSequence, self).setUp() + self.contract_contract = self.env["contract.contract"] + self.contract_template = self.env["contract.template"].create( + { + "name": "Test Contract template", + } + ) + self.pricelist = self.env["product.pricelist"].create( + { + "name": "pricelist for contract test", + } + ) + self.partner = self.env["res.partner"].create( + { + "name": "partner test contract", + "property_product_pricelist": self.pricelist.id, + "email": "demo@demo.com", + } + ) + + def test_contract_create_with_manual_code(self): + contract = self.contract_contract.create( + { + "name": "C/22/0001", + "code": "Contract with manual code", + "partner_id": self.partner.id, + } + ) + self.assertEqual(contract.name, "C/22/0001") + contract_new = self.contract_contract.create( + { + "code": "Contract with template", + "partner_id": self.partner.id, + "contract_template_id": self.contract_template.id, + } + ) + self.assertTrue(contract_new.name) + + def test_contract_create_without_code(self): + contract_1 = self.contract_contract.create( + { + "code": "Contract nr 1", + "name": "/", + "partner_id": self.partner.id, + } + ) + self.assertRegex(str(contract_1.name), r"CON/*") + + def test_contract_copy(self): + contract_2 = self.contract_contract.create( + { + "code": "Contract nr 2", + "name": "CON/22/0002", + "partner_id": self.partner.id, + } + ) + contract_2.flush() + copy_contract_2 = contract_2.copy() + self.assertTrue(copy_contract_2.name[:11] != contract_2.name) + + def test_pre_init_hook(self): + contract_3 = self.contract_contract.create( + { + "code": "Contract nr 3", + "name": "CON/22/0003", + "partner_id": self.partner.id, + } + ) + self.cr.execute( + "update contract_contract set name='/' where id=%s", + (tuple(contract_3.ids),), + ) + contract_3.invalidate_cache() + self.assertEqual(contract_3.name, "/") + pre_init_hook(self.cr) + contract_3.invalidate_cache() + self.assertEqual(contract_3.name, "!!mig!!{}".format(contract_3.id))