Skip to content

Commit

Permalink
[REF] l10n_br_nfe: further multi-schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Nov 29, 2024
1 parent 77d7a48 commit 38a186a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
1 change: 0 additions & 1 deletion l10n_br_nfe/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env["nfe.40.infnfe"]._register_hook()
cr.execute("select demo from ir_module_module where name='l10n_br_nfe';")
is_demo = cr.fetchone()[0]
if is_demo:
Expand Down
15 changes: 10 additions & 5 deletions l10n_br_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ 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"]
_inherit = ["l10n_br_fiscal.document", "nfe.40.infnfe"]

_nfe40_odoo_module = "odoo.addons.l10n_br_nfe_spec.models.v4_0.leiaute_nfe_v4_00"
_nfe40_stacking_mixin = "nfe.40.infnfe"
Expand Down Expand Up @@ -684,7 +684,7 @@ def _export_many2one(self, field_name, xsd_required, class_obj=None):
fields = [
f
for f in comodel._fields
if f.startswith(self._field_prefix)
if f.startswith(self._spec_prefix())
and f in self._fields.keys()
and f
# don't try to nfe40_fat id when reading nfe40_cobr for instance
Expand All @@ -694,7 +694,7 @@ def _export_many2one(self, field_name, xsd_required, class_obj=None):
if not any(
v
for k, v in sub_tag_read.items()
if k.startswith(self._field_prefix)
if k.startswith(self._spec_prefix())
):
return False

Expand Down Expand Up @@ -1068,9 +1068,13 @@ def _exec_after_SITUACAO_EDOC_AUTORIZADA(self, old_state, new_state):
return super()._exec_after_SITUACAO_EDOC_AUTORIZADA(old_state, new_state)

def _generate_key(self):
for record in self.filtered(filter_processador_edoc_nfe):
date = fields.Datetime.context_timestamp(record, record.document_date)
if self.document_type_id.code not in [
MODELO_FISCAL_NFE,
MODELO_FISCAL_NFCE,
]:
return super()._generate_key()

for record in self.filtered(filter_processador_edoc_nfe):
required_fields_gen_edoc = []
if not record.company_cnpj_cpf:
required_fields_gen_edoc.append("CNPJ/CPF")
Expand All @@ -1088,6 +1092,7 @@ def _generate_key(self):
_("To Generate EDoc Key, you need to fill the %s field.") % field
)

date = fields.Datetime.context_timestamp(record, record.document_date)
chave_edoc = ChaveEdoc(
ano_mes=date.strftime("%y%m").zfill(4),
cnpj_cpf_emitente=record.company_cnpj_cpf,
Expand Down
5 changes: 0 additions & 5 deletions l10n_br_nfe/tests/test_nfe_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@


class NFeImportTest(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env["spec.mixin.nfe"]._register_hook()

def test_import_in_nfe_dry_run(self):
res_items = (
"nfe",
Expand Down
1 change: 0 additions & 1 deletion l10n_br_nfe/tests/test_nfe_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
class TestNFeExport(TransactionCase):
def setUp(self, nfe_list):
super().setUp()
self.env["spec.mixin.nfe"]._register_hook()
self.nfe_list = nfe_list
for nfe_data in self.nfe_list:
nfe = self.env.ref(nfe_data["record_ref"])
Expand Down
1 change: 0 additions & 1 deletion l10n_br_nfe/tests/test_nfe_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class NFeStructure(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env["spec.mixin.nfe"]._register_hook()

@classmethod
def get_stacked_tree(cls, klass):
Expand Down

0 comments on commit 38a186a

Please sign in to comment.