-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_br_cte: add res_partner tests
- Loading branch information
1 parent
305ddad
commit 4e2910d
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Copyright 2024 - TODAY, Marcel Savegnago <[email protected]> | ||
# 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": "78961893000129", | ||
"zip": "12345000", | ||
"phone": "(11) 91234-5678", | ||
"email": "[email protected]", | ||
"country_id": self.env.ref("base.br").id, | ||
} | ||
) | ||
|
||
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, "12345678000195", "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 = "98765432000123" | ||
self.partner._inverse_cte40_CNPJ() | ||
self.assertEqual( | ||
self.partner.cnpj_cpf, | ||
"98.765.432/0001-23", | ||
"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": "78961893000129"} | ||
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") |