Skip to content

Commit

Permalink
[FIX] bugs on exporting data
Browse files Browse the repository at this point in the history
  • Loading branch information
felipezago committed Sep 27, 2023
1 parent 14a92cb commit 44faaa5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions l10n_br_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ def _serialize(self, edocs):
for record in self.with_context(lang="pt_BR").filtered(
filter_processador_edoc_nfe
):
record = record.with_context(module="l10n_br_nfe")
inf_nfe = record.export_ds()[0]

inf_nfe_supl = None
Expand Down
43 changes: 22 additions & 21 deletions spec_driven_model/models/spec_export.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2019 KMEE
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html).
import inspect
import logging
import sys
from io import StringIO
Expand All @@ -15,7 +14,11 @@ class AbstractSpecMixin(models.AbstractModel):

@api.model
def _get_binding_class(self, class_obj):
binding_module = sys.modules[class_obj._binding_module]
origin_class = self._get_origin_class()
module_name = (
origin_class and origin_class._binding_module or class_obj._binding_module
)
binding_module = sys.modules[module_name]
for attr in class_obj._binding_type.split("."):
binding_module = getattr(binding_module, attr)
return binding_module
Expand Down Expand Up @@ -203,7 +206,7 @@ def _export_datetime(self, field_name):
).isoformat("T")
)

def _build_generateds(self, class_name=False, origin_class=False):
def _build_generateds(self, class_name=False):
"""
Iterate over an Odoo record and its m2o and o2m sub-records
using a pre-order tree traversal and maps the Odoo record values
Expand All @@ -214,18 +217,17 @@ def _build_generateds(self, class_name=False, origin_class=False):
sub binding instances already properly instanciated.
"""
self.ensure_one()
if origin_class:

if not class_name:
origin_class = self._get_origin_class()
if not origin_class:
origin_class = self

if hasattr(origin_class, "_stacked"):
class_name = origin_class._stacked
else:
class_name = origin_class._name

if not class_name:
if hasattr(self, "_stacked"):
class_name = self._stacked
else:
class_name = self._name

class_obj = self.env[class_name]

xsd_fields = (
Expand All @@ -247,12 +249,12 @@ def _build_generateds(self, class_name=False, origin_class=False):
binding_instance = binding_class(**sliced_kwargs)
return binding_instance

def export_xml(self, origin_class, print_xml=True):
def export_xml(self, print_xml=True):
self.ensure_one()
result = []

if hasattr(origin_class, "_stacked"):
binding_instance = self._build_generateds(origin_class=origin_class)
if hasattr(self, "_stacked"):
binding_instance = self._build_generateds()
if print_xml:
self._print_xml(binding_instance)
result.append(binding_instance)
Expand All @@ -268,15 +270,14 @@ def export_xml(self, origin_class, print_xml=True):

def export_ds(self):
self.ensure_one()
module_name = inspect.currentframe().f_back.f_locals["__class__"]._module
return self.export_xml(print_xml=False)

def _get_origin_class(self):
module_name = self._context.get("module", False)
if not module_name:
return False

for klass in self.__class__.__bases__:
module = klass.__module__.split(".")
if module_name == module[2]:
origin_class = klass
break

if not origin_class:
origin_class = self

return self.export_xml(print_xml=False, origin_class=origin_class)
return klass

0 comments on commit 44faaa5

Please sign in to comment.