Skip to content

Commit

Permalink
[IMP] l10n_br_cte: add test_mdfe_document
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Dec 10, 2024
1 parent d884d4c commit d71c694
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions l10n_br_mdfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,21 @@ def _inverse_mdfe30_inf_carrega(self):
record.mdfe_loading_city_ids = [(6, 0, city_ids.ids)]

def _inverse_mdfe30_initial_final_state(self):
country_id = self.env["res.country"].search([("code", "=", "BR")])
for record in self:
initial_state_id = self.env["res.country.state"].search(
[("code", "=", record.mdfe30_UFIni)], limit=1
[
("code", "=", record.mdfe30_UFIni),
("country_id", "=", country_id.id),
],
limit=1,
)
final_state_id = self.env["res.country.state"].search(
[("code", "=", record.mdfe30_UFFim)], limit=1
[
("code", "=", record.mdfe30_UFFim),
("country_id", "=", country_id.id),
],
limit=1,
)

if initial_state_id:
Expand All @@ -346,9 +355,11 @@ def _inverse_mdfe30_initial_final_state(self):
record.mdfe_final_state_id = final_state_id

def _inverse_mdfe30_uf(self):
country_id = self.env["res.country"].search([("code", "=", "BR")])
for record in self:
state_id = self.env["res.country.state"].search(
[("code", "=", record.mdfe30_cUF)], limit=1
[("code", "=", record.mdfe30_cUF), ("country_id", "=", country_id.id)],
limit=1,
)
if state_id:
record.company_id.partner_id.state_id = state_id
Expand Down
1 change: 1 addition & 0 deletions l10n_br_mdfe/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import test_mdfe_structure
from . import test_mdfe_res_partner
from . import test_mdfe_damdfe
from . import test_mdfe_document
5 changes: 2 additions & 3 deletions l10n_br_mdfe/tests/test_mdfe_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ def setUpClass(cls):
cls.acre_state = cls.env.ref("base.state_br_ac")
cls.mdfe_document_type_id = cls.env.ref("l10n_br_fiscal.document_58")
cls.sn_company_id = cls.env.ref("l10n_br_base.empresa_simples_nacional")
cls.sn_company_id.processador_edoc = "erpbrasil.edoc"
cls.mdfe_id = FiscalDocument.create(
{
"document_type_id": cls.mdfe_document_type_id.id,
"company_id": cls.sn_company_id.id,
"document_number": "70000",
"document_serie": "30",
"document_data": datetime.now(),
"document_date": datetime.now(),
}
)

Expand All @@ -43,7 +42,7 @@ def test_mdfe_inverse_fields(self):
self.assertEqual(self.mdfe_id.mdfe_initial_state_id, self.acre_state)
self.assertEqual(self.mdfe_id.mdfe_final_state_id, self.acre_state)

self.mdfe_id.mdfe30_UF = self.acre_state.ibge_code
self.mdfe_id.mdfe30_UF = self.acre_state.code
self.assertEqual(self.mdfe_id.company_id.partner_id.state_id, self.acre_state)

self.mdfe_id.mdfe30_infMunCarrega = [
Expand Down

0 comments on commit d71c694

Please sign in to comment.