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 10, 2024
1 parent cf58486 commit 8a2b1cb
Showing 1 changed file with 33 additions and 39 deletions.
72 changes: 33 additions & 39 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@

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

# TODO: precisa tratar
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 @@ -1384,33 +1382,29 @@ def _serialize(self, edocs):
edocs.append(cte)
return edocs

# 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

# params = {
# "transmissao": TransmissaoCTE(certificado, session),
# "uf": self.company_id.state_id.ibge_code,
# "versao": self.cte_version,
# "ambiente": self.cte_environment,
# }
# return edoc_cte(**params)

def _edoc_processor(self):
pass
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 @@ -1423,8 +1417,8 @@ def _document_export(self, pretty_print=True):
)
record.authorization_event_id = event_id

# 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 Expand Up @@ -1620,17 +1614,17 @@ def _cte_correction(self, justificative):
file_response_xml=process.retorno.content.decode("utf-8"),
)

# def _document_qrcode(self):
# super()._document_qrcode()

# for record in self.filtered(filter_processador_edoc_cte):
# record.cte40_infCTeSupl = self.env[
# "l10n_br_fiscal.document.supplement"
# ].create(
# {
# "qrcode": record.get_cte_qrcode(),
# }
# )
def _document_qrcode(self):
super()._document_qrcode()

for record in self.filtered(filter_processador_edoc_cte):
record.cte40_infCTeSupl = self.env[
"l10n_br_fiscal.document.supplement"
].create(
{
"qrcode": record.get_cte_qrcode(),
}
)

def get_cte_qrcode(self):
if self.document_type != MODELO_FISCAL_CTE:
Expand Down

0 comments on commit 8a2b1cb

Please sign in to comment.