Skip to content

Commit

Permalink
Merge pull request #81 from kmee/fix/transmissao-nfce
Browse files Browse the repository at this point in the history
[FIX] Problema na emissão da NFC-e
  • Loading branch information
mileo authored Jul 19, 2024
2 parents a51c37f + 63d2df0 commit 2f01752
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 2f01752

Please sign in to comment.