Skip to content

Commit

Permalink
[IMP] l10n_br_cte: add res_partner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Nov 17, 2024
1 parent 305ddad commit 4e2910d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions l10n_br_cte/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
70 changes: 70 additions & 0 deletions l10n_br_cte/tests/test_res_partner.py
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")

0 comments on commit 4e2910d

Please sign in to comment.