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

[FIX] Problema na emissão da NFC-e #81

Merged
merged 4 commits into from
Jul 19, 2024
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
4 changes: 3 additions & 1 deletion src/erpbrasil/edoc/nfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,9 @@ def consultar_distribuicao(
)

def monta_processo(self, edoc, proc_envio, proc_recibo=None):
nfe = proc_envio.envio_raiz.find("{" + self._namespace + "}NFe")
nfe = proc_envio.envio_raiz.find(
"{" + self._namespace + "}NFe"
) # Se proc_envio for 'None', debugar o método 'analisar_retorno_raw'
if proc_recibo:
protocolos = proc_recibo.resposta.protNFe
else:
Expand Down
11 changes: 9 additions & 2 deletions src/erpbrasil/edoc/resposta.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Copyright (C) 2018 - TODAY Luis Felipe Mileo - KMEE INFORMATICA LTDA
# License MIT

import logging
import re

from lxml import etree

combined_pattern = re.compile(
r"<soap:Body>(.*?)</soap:Body>|<[a-zA-Z0-9:]*Body[^>]*>(.*?)</[a-zA-Z0-9:]*Body>"
)


class RetornoSoap:
def __init__(self, webservice, raiz, xml, retorno, resposta):
Expand All @@ -17,9 +22,9 @@ def __init__(self, webservice, raiz, xml, retorno, resposta):

def analisar_retorno_raw(operacao, raiz, xml, retorno, classe):
retorno.raise_for_status()
match = re.search("<soap:Body>(.*?)</soap:Body>", retorno.text.replace("\n", ""))
match = re.search(combined_pattern, retorno.text.replace("\n", ""))
if match:
xml_resposta = match.group(1)
xml_resposta = match.group(1) or match.group(2)
xml_etree = etree.fromstring(xml_resposta)
resultado = xml_etree[0]

Expand All @@ -36,6 +41,8 @@ def analisar_retorno_raw(operacao, raiz, xml, retorno, classe):
classe.Validate_simpletypes_ = False
resposta = classe.parseString(resultado, silence=True)
return RetornoSoap(operacao, raiz, xml, retorno, resposta)
else:
logging.warning("'match' em 'analisar_retorno_raw' é None")


def analisar_retorno(operacao, raiz, xml, retorno, classe):
Expand Down
Loading