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 c86efd1
Show file tree
Hide file tree
Showing 2 changed files with 72 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
71 changes: 71 additions & 0 deletions l10n_br_cte/tests/test_res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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": "87697453000105",
"zip": "12345000",
"phone": "(11) 91234-5678",
"email": "[email protected]",
"country_id": self.env.ref("base.br").id,
"is_company": "1",
}
)

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")

0 comments on commit c86efd1

Please sign in to comment.