From 5017f0f24aa48c17d76587c26a4f24c833866f40 Mon Sep 17 00:00:00 2001 From: marinaGD Date: Wed, 19 Dec 2018 16:48:27 -0200 Subject: [PATCH] fix disable CE nfce --- pytrustnfe/nfe/__init__.py | 12 ++++++++---- pytrustnfe/nfe/patch.py | 10 ++++++++++ setup.py | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 pytrustnfe/nfe/patch.py diff --git a/pytrustnfe/nfe/__init__.py b/pytrustnfe/nfe/__init__.py index ac5aad6..fd75f1a 100644 --- a/pytrustnfe/nfe/__init__.py +++ b/pytrustnfe/nfe/__init__.py @@ -6,6 +6,7 @@ import os import requests from lxml import etree +from .patch import nfeInutilizacaoCE from .assinatura import Assinatura from pytrustnfe.xml import render_xml, sanitize_response from pytrustnfe.utils import gerar_chave, ChaveNFe @@ -94,11 +95,14 @@ def _send(certificado, method, **kwargs): requests.packages.urllib3.disable_warnings(InsecureRequestWarning) with client.settings(raw_response=True): - response = client.service[first_operation](xml) - response, obj = sanitize_response(response.text) + if kwargs["estado"] == '23': + response = nfeInutilizacaoCE(session, xml_send) + else: + response = client.service[first_operation](nfeDadosMsg=xml) + response_other, obj = sanitize_response(response.text) return { - 'sent_xml': xml_send, - 'received_xml': response, + 'sent_xml': xml_send, # response.request.body.decode('utf-8'), + 'received_xml': response_other, 'object': obj.Body.getchildren()[0] } diff --git a/pytrustnfe/nfe/patch.py b/pytrustnfe/nfe/patch.py new file mode 100644 index 0000000..41e224e --- /dev/null +++ b/pytrustnfe/nfe/patch.py @@ -0,0 +1,10 @@ + + +def nfeInutilizacaoCE(session, xml_send): + soap = '' + xml_send + '' + headers = { + 'SOAPAction': "", + 'Content-Type': 'application/soap+xml; charset="utf-8"' + } + response = session.post('https://nfeh.sefaz.ce.gov.br/nfe4/services/NFeInutilizacao4', data=soap, headers=headers) + return response diff --git a/setup.py b/setup.py index a18369c..1b5c59d 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages -VERSION = "1.0.28" +VERSION = "1.0.29" setup(