From 32a5ba0b05b911d8cbcf8eb45c3d04df02a15985 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Mon, 21 Oct 2024 09:12:56 -0300 Subject: [PATCH] [TEMP] l10n_br_mdfe: ajuste_mdfe_import --- l10n_br_mdfe/tests/test_mdfe_import.py | 117 +++++++++++++------------ 1 file changed, 61 insertions(+), 56 deletions(-) diff --git a/l10n_br_mdfe/tests/test_mdfe_import.py b/l10n_br_mdfe/tests/test_mdfe_import.py index dce032f2423f..0207034ca311 100644 --- a/l10n_br_mdfe/tests/test_mdfe_import.py +++ b/l10n_br_mdfe/tests/test_mdfe_import.py @@ -2,74 +2,79 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging +import nfelib +import pkg_resources +from nfelib.mdfe.bindings.v3_0.mdfe_v3_00 import Tmdfe + +from odoo.models import NewId from odoo.tests import SavepointCase _logger = logging.getLogger(__name__) class MDFeImportTest(SavepointCase): - @classmethod - def setUpClass(cls): - super().setUpClass() + def test_import_in_mdfe_dry_run(self): + res_items = ( + "mdfe", + "samples", + "v3_0", + "41190876676436000167580010000500001000437558-mdfe.xml", + ) - # def test_import_in_mdfe_dry_run(self): - # binding = self._get_xml_binding() - # mdfe = ( - # self.env["mdfe.30.tmdfe_infmdfe"] - # .with_context(tracking_disable=True, edoc_type="in") - # .build_from_binding(binding.infMDFe, dry_run=True) - # ) - # assert isinstance(mdfe.id, NewId) - # self._check_mdfe(mdfe) + resource_path = "/".join(res_items) + mdfe_stream = pkg_resources.resource_stream(nfelib.__name__, resource_path) + binding = Tmdfe.from_xml(mdfe_stream.read().decode()) - # def test_import_in_mdfe(self): - # binding = self._get_xml_binding() - # mdfe = ( - # self.env["mdfe.30.tmdfe_infmdfe"] - # .with_context(tracking_disable=True, edoc_type="in") - # .build_from_binding(binding.infMDFe, dry_run=False) - # ) + mdfe = ( + self.env["mdfe.30.tmdfe_infmdfe"] + .with_context(tracking_disable=True, edoc_type="in") + .build_from_binding("mdfe", "30", binding.infMDFe, dry_run=True) + ) + assert isinstance(mdfe.id, NewId) + self._check_mdfe(mdfe) - # assert isinstance(mdfe.id, int) - # self._check_mdfe(mdfe) + def test_import_in_mdfe(self): + res_items = ( + "mdfe", + "samples", + "v3_0", + "41190876676436000167580010000500001000437558-mdfe.xml", + ) + resource_path = "/".join(res_items) + mdfe_stream = pkg_resources.resource_stream(nfelib.__name__, resource_path) + binding = Tmdfe.from_xml(mdfe_stream.read().decode()) + mdfe = ( + self.env["mdfe.30.tmdfe_infmdfe"] + .with_context(tracking_disable=True, edoc_type="in") + .build_from_binding("mdfe", "30", binding.infMDFe, dry_run=False) + ) - # def _get_xml_binding(self): - # hooks.register_hook( - # self.env, - # "l10n_br_mdfe", - # "odoo.addons.l10n_br_mdfe_spec.models.v3_0.mdfe_tipos_basico_v3_00", - # ) - # xml_path = os.path.join( - # l10n_br_mdfe.__path__[0], - # "tests", - # "mdfe", - # "v3_00", - # "leiauteMDFe", - # "MDFe41190876676436000167580010000500001000437558.xml", - # ) + assert isinstance(mdfe.id, int) + self._check_nfe(mdfe) - # return MdfeProc.from_xml(open(xml_path).read()) + def _check_mdfe(self, mdfe): + self.assertEqual(type(mdfe)._name, "l10n_br_fiscal.document") - # def _check_mdfe(self, mdfe): - # self.assertEqual(type(mdfe)._name, "l10n_br_fiscal.document") + # ide + self.assertEqual(mdfe.mdfe30_cMDF, "00043755") + self.assertEqual(mdfe.mdfe30_infMunCarrega[0].mdfe30_xMunCarrega, "ARAUCARIA") + self.assertEqual(mdfe.mdfe30_UFIni, "PR") + self.assertEqual(mdfe.mdfe30_UFFim, "SC") - # # ide - # self.assertEqual(mdfe.mdfe30_cMDF, "00043755") - # self.assertEqual(mdfe.mdfe30_infMunCarrega[0].mdfe30_xMunCarrega, "ARAUCARIA") - # self.assertEqual(mdfe.mdfe30_UFIni, "PR") - # self.assertEqual(mdfe.mdfe30_UFFim, "SC") + # emit + self.assertEqual( + mdfe.company_id, self.env.ref("l10n_br_base.empresa_lucro_presumido") + ) - # # emit - # self.assertEqual( - # mdfe.company_id, self.env.ref("l10n_br_base.empresa_lucro_presumido") - # ) + # modal + self.assertEqual(mdfe.mdfe30_RNTRC, "12345678") + self.assertEqual(mdfe.mdfe30_cInt, "1") + self.assertEqual(mdfe.mdfe30_placa, "AAA4444") + self.assertEqual(mdfe.mdfe30_tara, "15000") + self.assertEqual( + mdfe.mdfe30_condutor[0].mdfe30_xNome, "MAURICIO ROBERTO MOLLER" + ) + self.assertEqual(len(mdfe.mdfe30_veicReboque), 2) - # # modal - # self.assertEqual(mdfe.mdfe30_RNTRC, "12345678") - # self.assertEqual(mdfe.mdfe30_cInt, "1") - # self.assertEqual(mdfe.mdfe30_placa, "AAA4444") - # self.assertEqual(mdfe.mdfe30_tara, "15000") - # self.assertEqual( - # mdfe.mdfe30_condutor[0].mdfe30_xNome, "MAURICIO ROBERTO MOLLER" - # ) - # self.assertEqual(len(mdfe.mdfe30_veicReboque), 2) + def test_import_out_mdfe(self): + "(can be useful after an ERP migration)"