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

Emissão NFe-MS apresenta problemas no SOAP, envio e resposta. #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/erpbrasil/edoc/edoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def _generateds_to_string_etree(self, ds, pretty_print=False):
pretty_print=pretty_print,
)
contents = output.getvalue()
if 'consStatServ' in contents and self.uf == 50:
contents = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://www.w3.org/2003/05/soap-envelope'><soap:Body><nfeDadosMsg xmlns='http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4'>" + contents + "</nfeDadosMsg></soap:Body></soap:Envelope>"
if 'consSitNFe' in contents and self.uf == 50:
contents = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://www.w3.org/2003/05/soap-envelope'><soap:Body><nfeDadosMsg xmlns='http://www.portalfiscal.inf.br/nfe/wsdl/NFeConsultaProtocolo4'>" + contents + "</nfeDadosMsg></soap:Body></soap:Envelope>"
if 'retConsReciNFe' in contents and self.uf == 50:
contents = "<S:Envelope xmlns:S='http://www.w3.org/2003/05/soap-envelope'><S:Body><nfeResultMsg xmlns='http://www.portalfiscal.inf.br/nfe/wsdl/NFeRetAutorizacao4'><retConsReciNFe xmlns='http://www.portalfiscal.inf.br/nfe' versao='4.00'>" + contents + "</retConsReciNFe></nfeResultMsg></S:Body></S:Envelope>"
if 'nfeProc' in contents and '<cStat>100</cStat>' in contents and self.uf == 50:
contents = contents[:contents.find("ds:Signature")-1] + "</protNFe></nfeProc>"
output.close()
return contents, etree.fromstring(contents)

Expand Down Expand Up @@ -148,7 +156,7 @@ def processar_documento(self, edoc):
#
# Deu errado?
#
if not proc_envio.resposta:
if not hasattr(proc_envio, 'resposta') or not proc_envio.resposta:
return

if not self._verifica_resposta_envio_sucesso(proc_envio):
Expand Down
10 changes: 9 additions & 1 deletion src/erpbrasil/edoc/resposta.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ 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>',
match = False
if '<soap:Body>' in retorno.text:
match = re.search('<soap:Body>(.*?)</soap:Body>',
retorno.text.replace('\n', ''))
if '<soapenv:Body>' in retorno.text:
match = re.search('<soapenv:Body>(.*?)</soapenv:Body>',
retorno.text.replace('\n', ''))
if '<S:Body>' in retorno.text:
match = re.search('<S:Body>(.*?)</S:Body>',
retorno.text.replace('\n', ''))
if match:
xml_resposta = match.group(1)
Expand Down