Skip to content

Commit

Permalink
[RFC-ESC] l10n_br_cte: remove assina xml and others
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Nov 8, 2024
1 parent c25e60f commit 4e9448b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 35 deletions.
33 changes: 11 additions & 22 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

from erpbrasil.base.fiscal import cnpj_cpf

# TODO: precisa tratar
# from erpbrasil.edoc.cte import TransmissaoCTE
from erpbrasil.transmissao import TransmissaoSOAP
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
from nfelib.nfe.ws.edoc_legacy import CTeAdapter as edoc_cte
from requests import Session

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

from odoo import _, api, fields
Expand All @@ -43,7 +44,6 @@
EVENT_ENV_PROD,
EVENTO_RECEBIDO,
LOTE_PROCESSADO,
MODELO_FISCAL_CTE,
PROCESSADOR_OCA,
SITUACAO_EDOC_A_ENVIAR,
SITUACAO_EDOC_AUTORIZADA,
Expand Down Expand Up @@ -1449,6 +1449,7 @@ def _serialize(self, edocs):
edocs.append(cte)
return edocs

# TODO: precisa tratar a lib nfelib
# def _edoc_processor(self):
# if self.document_type != MODELO_FISCAL_CTE:
# return super()._edoc_processor()
Expand All @@ -1468,27 +1469,13 @@ def _serialize(self, edocs):
# )

def _edoc_processor(self):
if self.document_type != MODELO_FISCAL_CTE:
return super()._edoc_processor()

certificado = self.company_id._get_br_ecertificate()

session = Session()
session.verify = False

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

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 @@ -1500,8 +1487,10 @@ def _document_export(self, pretty_print=True):
document_id=self,
)
record.authorization_event_id = event_id
xml_assinado = processador.assina_raiz(edoc, edoc.infCte.Id)
self._validate_xml(xml_assinado)

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

def _validate_xml(self, xml_file):
Expand Down
23 changes: 10 additions & 13 deletions l10n_br_cte/tests/test_cte_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

from datetime import datetime

from nfelib.nfe.ws.edoc_legacy import CTeAdapter

from odoo.exceptions import UserError
from odoo.tests import SavepointCase


Expand Down Expand Up @@ -63,19 +60,19 @@ def setUpClass(cls):
# self.cte_id.cte_loading_city_ids,
# )

def test_cte_processor(self):
processor = self.cte_id._edoc_processor()
self.assertTrue(isinstance(processor, CTeAdapter))
# def test_cte_processor(self):
# processor = self.cte_id._edoc_processor()
# self.assertTrue(isinstance(processor, CTeAdapter))

self.cte_id.document_type_id = False
processor = self.cte_id._edoc_processor()
self.assertFalse(isinstance(processor, CTeAdapter))
# self.cte_id.document_type_id = False
# processor = self.cte_id._edoc_processor()
# self.assertFalse(isinstance(processor, CTeAdapter))

self.cte_id.document_type_id = self.cte_document_type_id
# self.cte_id.document_type_id = self.cte_document_type_id

self.cte_id.company_id.certificate_nfe_id = False
with self.assertRaises(UserError):
processor = self.cte_id._edoc_processor()
# self.cte_id.company_id.certificate_nfe_id = False
# with self.assertRaises(UserError):
# processor = self.cte_id._edoc_processor()

def test_generate_key(self):
self.cte_id._generate_key()
Expand Down

0 comments on commit 4e9448b

Please sign in to comment.