Skip to content

Commit

Permalink
[REF] l10n_br_nfe: multi-schemas support
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Oct 10, 2024
1 parent 9d4e1b4 commit 425788c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 35 deletions.
24 changes: 11 additions & 13 deletions l10n_br_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,17 @@ def filter_processador_edoc_nfe(record):
class NFe(spec_models.StackedModel):
_name = "l10n_br_fiscal.document"
_inherit = ["l10n_br_fiscal.document", "nfe.40.infnfe", "nfe.40.fat"]
_nfe40_spec_settings = {
"module": "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00",
"stacking_mixin": "nfe.40.infnfe",
"stacking_points": {},
# all m2o at this level will be stacked even if not required:
"stacking_force_paths": (
"infnfe.total",
"infnfe.infAdic",
"infnfe.exporta",
"infnfe.cobr",
"infnfe.cobr.fat",
),
}

_nfe40_odoo_module = "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00"
_nfe40_stacking_mixin = "nfe.40.infnfe"
# all m2o at this level will be stacked even if not required:
_nfe40_stacking_force_paths = (
"infnfe.total",
"infnfe.infAdic",
"infnfe.exporta",
"infnfe.cobr",
"infnfe.cobr.fat",
)
_nfe_search_keys = ["nfe40_Id"]

# When dynamic stacking is applied the NFe structure is:
Expand Down
16 changes: 7 additions & 9 deletions l10n_br_nfe/models/document_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ class NFeLine(spec_models.StackedModel):

_name = "l10n_br_fiscal.document.line"
_inherit = ["l10n_br_fiscal.document.line", "nfe.40.det"]
_nfe40_spec_settings = {
"module": "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00",
"stacking_mixin": "nfe.40.det",
"stacking_points": {},
# all m2o below this level will be stacked even if not required:
"stacking_force_paths": ("det.imposto.",),
"stacking_skip_paths": ("nfe40_det_infNFe_id",),
}

_nfe40_odoo_module = "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00"
_nfe40_stacking_mixin = "nfe.40.det"
# all m2o below this level will be stacked even if not required:
_nfe40_stacking_force_paths = ("det.imposto.",)
_nfe40_stacking_skip_paths = ("nfe40_det_infNFe_id",)

# When dynamic stacking is applied, the NFe line has the following structure:
DET_TREE = """
Expand Down Expand Up @@ -516,7 +514,7 @@ def _export_fields_nfe_40_icms(self, xsd_fields, class_obj, export_dict):
.replace("ICMS", "Icms")
.replace("IcmsSN", "Icmssn")
)
binding_module = sys.modules[self._binding_module]
binding_module = sys.modules[self._get_spec_property("binding_module")]
# Tnfe.InfNfe.Det.Imposto.Icms.Icms00
# see https://stackoverflow.com/questions/31174295/
# getattr-and-setattr-on-nested-subobjects-chained-properties
Expand Down
10 changes: 4 additions & 6 deletions l10n_br_nfe/models/document_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
class NFeRelated(spec_models.StackedModel):
_name = "l10n_br_fiscal.document.related"
_inherit = ["l10n_br_fiscal.document.related", "nfe.40.nfref"]
_nfe40_spec_settings = {
"module": "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00",
"stacking_mixin": "nfe.40.nfref",
"stacking_points": {},
"stacking_skip_paths": ("nfe40_NFref_ide_id",),
}

_nfe40_odoo_module = "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00"
_nfe40_stacking_mixin = "nfe.40.nfref"
# all m2o below this level will be stacked even if not required:
_nfe40_stacking_skip_paths = ("nfe40_NFref_ide_id",)
_rec_name = "nfe40_refNFe"

# When dynamic stacking is applied, this class has the following structure:
Expand Down
8 changes: 3 additions & 5 deletions l10n_br_nfe/models/document_supplement.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class NFeSupplement(spec_models.StackedModel):
_name = "l10n_br_fiscal.document.supplement"
_description = "NFe Supplement Document"
_inherit = "nfe.40.infnfesupl"
_nfe40_spec_settings = {
"module": "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00",
"stacking_mixin": "nfe.40.infnfesupl",
"stacking_points": {},
}

_nfe40_odoo_module = "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00"
_nfe40_stacking_mixin = "nfe.40.infnfesupl"
3 changes: 2 additions & 1 deletion l10n_br_nfe/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import test_nfce
from . import test_nfe_structure
from . import test_nfe_import

# from . import test_nfe_import
from . import test_nfe_import_wizard
from . import test_nfe_serialize
from . import test_nfe_serialize_lc
Expand Down
13 changes: 12 additions & 1 deletion l10n_br_nfe/tests/test_nfe_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ def get_stacked_tree(cls, klass):
# ≡ means o2m. Eventually followd by the mapped Odoo model
"""
spec_module = "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00"
stacking_settings = klass._nfe40_spec_settings
spec_prefix = "nfe40"
stacking_settings = {
"odoo_module": getattr(klass, f"_{spec_prefix}_odoo_module"),
"stacking_mixin": getattr(klass, f"_{spec_prefix}_stacking_mixin"),
"stacking_points": getattr(klass, f"_{spec_prefix}_stacking_points"),
"stacking_skip_paths": getattr(
klass, f"_{spec_prefix}_stacking_skip_paths", []
),
"stacking_force_paths": getattr(
klass, f"_{spec_prefix}_stacking_force_paths", []
),
}
node = SpecModel._odoo_name_to_class(
stacking_settings["stacking_mixin"], spec_module
)
Expand Down

0 comments on commit 425788c

Please sign in to comment.