From cb416fdcf55b6f3a07cbb77d299a4bd9afbf99bc Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Sun, 17 Nov 2024 18:32:50 -0300 Subject: [PATCH] [IMP] l10n_br_cte: add res_partner tests --- l10n_br_cte/tests/__init__.py | 1 + l10n_br_cte/tests/test_res_partner.py | 71 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 l10n_br_cte/tests/test_res_partner.py diff --git a/l10n_br_cte/tests/__init__.py b/l10n_br_cte/tests/__init__.py index 0928ea02e723..70c0e034c995 100644 --- a/l10n_br_cte/tests/__init__.py +++ b/l10n_br_cte/tests/__init__.py @@ -5,3 +5,4 @@ from . import test_cte_structure from . import test_cte_res_partner from . import test_cte_document +from . import test_res_partner diff --git a/l10n_br_cte/tests/test_res_partner.py b/l10n_br_cte/tests/test_res_partner.py new file mode 100644 index 000000000000..1c22f27d0402 --- /dev/null +++ b/l10n_br_cte/tests/test_res_partner.py @@ -0,0 +1,71 @@ +# Copyright 2024 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestResPartner(TransactionCase): + def setUp(self): + super(TestResPartner, self).setUp() + # Basic setup for the test + self.partner_model = self.env["res.partner"] + self.partner = self.partner_model.create( + { + "name": "Test Partner", + "cnpj_cpf": "87697453000105", + "zip": "12345000", + "phone": "(11) 91234-5678", + "email": "test@company.com", + "country_id": self.env.ref("base.br").id, + "is_company": True, + } + ) + + def test_compute_cte40_xEnder(self): + """Test the computation of the field cte40_xEnder""" + self.partner.write( + { + "street": "Test Street", + "street2": "Apt 101", + "district": "Downtown", + } + ) + self.partner._compute_cte40_xEnder() + self.assertEqual( + self.partner.cte40_xEnder, + "Test Street - Apt 101 - Downtown", + "The cte40_xEnder field was not computed correctly", + ) + + def test_compute_cte_data(self): + """Test the computation of fields related to CNPJ/CPF""" + self.partner._compute_cte_data() + self.assertEqual( + self.partner.cte40_CNPJ, "87697453000105", "CNPJ was not computed correctly" + ) + self.assertIsNone(self.partner.cte40_CPF, "CPF should not be set for companies") + + def test_inverse_cte40_CNPJ(self): + """Test the inverse method for the CNPJ field""" + self.partner.cte40_CNPJ = "21524956000162" + self.partner._inverse_cte40_CNPJ() + self.assertEqual( + self.partner.cnpj_cpf, + "21.524.956/0001-62", + "CNPJ was not formatted correctly", + ) + + def test_inverse_cte40_CEP(self): + """Test the inverse method for the ZIP code""" + self.partner.cte40_CEP = "12345999" + self.partner._inverse_cte40_CEP() + self.assertEqual( + self.partner.zip, "12345-999", "ZIP code was not formatted correctly" + ) + + def test_match_or_create_m2o(self): + """Test the match_or_create_m2o method""" + parent_dict = {"cte40_CNPJ": "87697453000105"} + rec_dict = {} + result_id = self.partner_model.match_or_create_m2o(rec_dict, parent_dict) + self.assertTrue(result_id, "Could not create or find a Many2One record")