Skip to content

Commit

Permalink
[IMP] l10n_br_cte: transmissao
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Dec 4, 2024
1 parent fcdac1e commit 7785b03
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
from enum import Enum

from erpbrasil.base.fiscal import cnpj_cpf
from erpbrasil.base.fiscal.edoc import ChaveEdoc

# TODO: precisa tratar
# from erpbrasil.edoc.cte import TransmissaoCTE
from erpbrasil.base.fiscal.edoc import ChaveEdoc
from erpbrasil.edoc.cte import TransmissaoCTE
from lxml import etree
from nfelib.cte.bindings.v4_0.cte_v4_00 import Cte
from nfelib.cte.bindings.v4_0.proc_cte_v4_00 import CteProc

# TODO: precisa tratar nfelib
# from nfelib.nfe.ws.edoc_legacy import CTeAdapter as edoc_cte
from nfelib.nfe.ws.edoc_legacy import CTeAdapter as edoc_cte
from requests import Session
from xsdata.formats.dataclass.parsers import XmlParser

from odoo import _, api, fields
Expand Down Expand Up @@ -1385,32 +1386,29 @@ def _serialize(self, edocs):
return edocs

# TODO: precisa tratar a lib nfelib
# def _edoc_processor(self):
# if self.document_type != MODELO_FISCAL_CTE:
# return super()._edoc_processor()

# if not self.company_id.certificate_nfe_id:
# raise UserError(_("Certificado não encontrado"))

# certificado = self.env.company._get_br_ecertificate()
# session = Session()
# session.verify = False
# transmissao = TransmissaoCTE(certificado, session)
# return edoc_cte(
# transmissao,
# self.company_id.state_id.ibge_code,
# self.cte40_versao,
# self.cte40_tpAmb,
# )

def _edoc_processor(self):
super()._edoc_processor()
if not self.filtered(filter_processador_edoc_cte):
return super()._edoc_processor()

if not self.company_id.certificate_nfe_id:
raise UserError(_("Certificado não encontrado"))

certificado = self.env.company._get_br_ecertificate()
session = Session()
session.verify = False
transmissao = TransmissaoCTE(certificado, session)
return edoc_cte(
transmissao,
self.company_id.state_id.ibge_code,
self.cte40_versao,
self.cte40_tpAmb,
)

def _document_export(self, pretty_print=True):
result = super()._document_export()
for record in self.filtered(filter_processador_edoc_cte):
edoc = record.serialize()[0]
# processador = record._edoc_processor()
processador = record._edoc_processor()
xml_file = edoc.to_xml()
event_id = self.event_ids.create_event_save_xml(
company_id=self.company_id,
Expand All @@ -1424,8 +1422,8 @@ def _document_export(self, pretty_print=True):
record.authorization_event_id = event_id

# TODO: precisa tratar
# xml_assinado = processador.assina_raiz(edoc, edoc.infCte.Id)
# self._validate_xml(xml_assinado)
xml_assinado = processador.assina_raiz(edoc, edoc.infCte.Id)
self._validate_xml(xml_assinado)
return result

def _validate_xml(self, xml_file):
Expand Down

0 comments on commit 7785b03

Please sign in to comment.