Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adaptacoes para a versao limpada da nfelib https://github.com/akretion/nfelib #30

Merged
merged 7 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-e git://github.com/erpbrasil/nfelib.git@feature/distribuicao#egg=nfelib
-e git://github.com/akretion/nfelib.git@master_gen_v4_00#egg=nfelib
nfselib.ginfes
nfselib.issnet
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ line_length = 120
known_first_party = erpbrasil.edoc
default_section = THIRDPARTY
forced_separate = test_erpbrasil.edoc
not_skip = __init__.py
skip = migrations
# don't isort nfe.py so imports can be grouped by schema:
skip = src/erpbrasil/edoc/nfe.py
43 changes: 31 additions & 12 deletions src/erpbrasil/edoc/mde.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
from __future__ import print_function
from __future__ import unicode_literals

import re

from erpbrasil.transmissao import TransmissaoSOAP
from lxml import etree

from erpbrasil.edoc.nfe import NFe
from erpbrasil.edoc.nfe import localizar_url
from erpbrasil.edoc.resposta import analisar_retorno_raw
from erpbrasil.edoc.resposta import RetornoSoap

try:
from nfelib.v4_00 import leiauteConfRecebto
from nfelib.v4_00 import retEnvEvento
from nfelib.v4_00.leiauteConfRecebtoManifestacao import TEnvEvento as TEnvEventoManifestacao # noga
from nfelib.v4_00.leiauteConfRecebtoManifestacao import TEvento as TEventoManifestacao # noga
from nfelib.v4_00.leiauteConfRecebtoManifestacao import descEventoType as descEventoManifestacao # noga
from nfelib.v4_00.leiauteConfRecebtoManifestacao import detEventoType as detEventoManifestacao # noga
from nfelib.v4_00.leiauteConfRecebtoManifestacao import infEventoType as infEventoManifestacao # noga
from nfelib.v4_00.leiauteConfRecebtoManifestacao import tpEventoType as eventoManifestacao # noga
from nfelib.v4_00 import retEnvConfRecebto
from nfelib.v4_00.retEnvConfRecebto import TEnvEvento as TEnvEventoManifestacao # noga
from nfelib.v4_00.retEnvConfRecebto import TEvento as TEventoManifestacao # noga
from nfelib.v4_00.retEnvConfRecebto import descEventoType as descEventoManifestacao # noga
from nfelib.v4_00.retEnvConfRecebto import detEventoType as detEventoManifestacao # noga
from nfelib.v4_00.retEnvConfRecebto import infEventoType as infEventoManifestacao # noga
from nfelib.v4_00.retEnvConfRecebto import tpEventoType as eventoManifestacao # noga
except ImportError:
pass

Expand Down Expand Up @@ -93,7 +94,7 @@ def nfe_recepcao_envia_lote_evento(self, lista_eventos, numero_lote=False):

# Converte o xml_assinado para um objeto pelo
# parser do esquema leiauteConfRecebto
xml_object = leiauteConfRecebto.parseString(xml_assinado)
xml_object = retEnvConfRecebto.parseString(xml_assinado)

# Adiciona o xml_object na lista de eventos. Desse modo a lista
# de eventos terá um evento assinado corretamente
Expand All @@ -105,7 +106,7 @@ def nfe_recepcao_envia_lote_evento(self, lista_eventos, numero_lote=False):
localizar_url(WS_NFE_RECEPCAO_EVENTO, str(91), self.mod,
int(self.ambiente)),
'nfeRecepcaoEventoNF',
retEnvEvento
retEnvConfRecebto
)

def nfe_recepcao_monta_evento(self, chave, cnpj_cpf, tpEvento, descEvento,
Expand Down Expand Up @@ -216,6 +217,24 @@ def operacao_nao_realizada(self, chave, cnpj_cpf):
xJust=''.zfill(15)
)

def analisar_retorno_raw(self, operacao, raiz, xml, retorno, classe):
"""
Semelhante ao metodo generico, mas usando o primeiro filho
do XML da resposta.
"""
retorno.raise_for_status()
match = re.search('<soap:Body>(.*?)</soap:Body>',
retorno.text.replace('\n', ''))
if match:
xml_resposta = match.group(1)
xml = etree.fromstring(xml_resposta)[0]
if "nfeDistDFeInteresseResult" in xml.tag:
xml = xml[0] # unwrapp retDistDFeInt
resultado = etree.tostring(xml)
classe.Validate_simpletypes_ = False
resposta = classe.parseString(resultado, silence=True)
return RetornoSoap(operacao, raiz, xml, retorno, resposta)

def _post(self, raiz, url, operacao, classe):
from .nfe import SIGLA_ESTADO

Expand All @@ -231,7 +250,7 @@ def _post(self, raiz, url, operacao, classe):
retorno = self._transmissao.enviar(
operacao, xml_etree, **kwargs
)
return analisar_retorno_raw(
return self.analisar_retorno_raw(
operacao, raiz, xml_string, retorno, classe
)

Expand Down
33 changes: 22 additions & 11 deletions src/erpbrasil/edoc/nfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@
from erpbrasil.edoc.edoc import DocumentoEletronico

try:
from nfelib.v4_00 import distDFeInt
from nfelib.v4_00 import leiauteCCe
from nfelib.v4_00 import leiauteInutNFe
from nfelib.v4_00 import retConsReciNFe
from nfelib.v4_00 import retConsSitNFe
# nfelib imports
# xsd NFe
from nfelib.v4_00 import retInutNFe
from nfelib.v4_00 import retConsStatServ
from nfelib.v4_00 import retConsSitNFe
from nfelib.v4_00 import retEnviNFe
from nfelib.v4_00 import retConsReciNFe

# xsd Distribuiçao NFe
from nfelib.v4_00 import distDFeInt
from nfelib.v4_00 import retDistDFeInt

# xsd Evento Generico
from nfelib.v4_00 import retEnvEvento

# xsd Evento Cancelamento
from nfelib.v4_00 import retEnvEventoCancNFe
from nfelib.v4_00 import retEnviNFe

# xsd CCe
from nfelib.v4_00 import retEnvCCe

except ImportError:
pass

Expand Down Expand Up @@ -803,7 +814,7 @@ def envia_documento(self, edoc):
)

def envia_inutilizacao(self, evento):
tinut = leiauteInutNFe.TInutNFe(
tinut = retInutNFe.TInutNFe(
versao=self.versao,
infInut=evento,
Signature=None)
Expand All @@ -818,7 +829,7 @@ def envia_inutilizacao(self, evento):
localizar_url(WS_NFE_INUTILIZACAO, str(self.uf), self.mod,
int(self.ambiente)),
'nfeInutilizacaoNF',
leiauteInutNFe
retInutNFe
)

def consulta_recibo(self, numero=False, proc_envio=False):
Expand Down Expand Up @@ -896,7 +907,7 @@ def cancela_documento(self, chave, protocolo_autorizacao, justificativa,
def carta_correcao(self, chave, sequencia, justificativa,
data_hora_evento=False):
tipo_evento = '110110'
raiz = leiauteCCe.infEventoType(
raiz = retEnvCCe.infEventoType(
Id='ID' + tipo_evento + chave + sequencia.zfill(2),
cOrgao=self.uf,
tpAmb=self.ambiente,
Expand All @@ -907,7 +918,7 @@ def carta_correcao(self, chave, sequencia, justificativa,
tpEvento=tipo_evento,
nSeqEvento=sequencia,
verEvento='1.00',
detEvento=leiauteCCe.detEventoType(
detEvento=retEnvCCe.detEventoType(
versao="1.00",
descEvento='Carta de Correcao',
xCorrecao=justificativa,
Expand All @@ -921,7 +932,7 @@ def inutilizacao(self, cnpj, mod, serie, num_ini, num_fin,
justificativa):
ano = str(datetime.date.today().year)[2:]
uf = str(self.uf)
raiz = leiauteInutNFe.infInutType(
raiz = retInutNFe.infInutType(
Id='ID' + uf + ano + cnpj + mod + serie.zfill(3) +
str(num_ini).zfill(9) + str(num_fin).zfill(9),
tpAmb=self.ambiente,
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ commands =
python setup.py check --strict --metadata --restructuredtext
check-manifest {toxinidir}
flake8 src tests setup.py
isort --verbose --check-only --diff --recursive src tests setup.py
isort --verbose --check-only --diff src tests setup.py

[testenv:spell]
setenv =
Expand Down