diff --git a/l10n_br_mdfe/models/document.py b/l10n_br_mdfe/models/document.py index 55a0a552be42..0c52a8f80273 100644 --- a/l10n_br_mdfe/models/document.py +++ b/l10n_br_mdfe/models/document.py @@ -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: @@ -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 diff --git a/l10n_br_mdfe/tests/__init__.py b/l10n_br_mdfe/tests/__init__.py index 8e2700191841..c1c2ce64ec10 100644 --- a/l10n_br_mdfe/tests/__init__.py +++ b/l10n_br_mdfe/tests/__init__.py @@ -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 diff --git a/l10n_br_mdfe/tests/test_mdfe_document.py b/l10n_br_mdfe/tests/test_mdfe_document.py index 0cdcd6e7de15..ee61699bf7f3 100644 --- a/l10n_br_mdfe/tests/test_mdfe_document.py +++ b/l10n_br_mdfe/tests/test_mdfe_document.py @@ -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(), } ) @@ -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 = [