Skip to content

Commit

Permalink
[TEMP] l10n_br_mdfe: ajuste_mdfe_import
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Oct 21, 2024
1 parent 26b7fd1 commit 32a5ba0
Showing 1 changed file with 61 additions and 56 deletions.
117 changes: 61 additions & 56 deletions l10n_br_mdfe/tests/test_mdfe_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

0 comments on commit 32a5ba0

Please sign in to comment.