From 57d8dc61f8fabbbb92380af926116cf5781aa6f6 Mon Sep 17 00:00:00 2001 From: Danimar Ribeiro Date: Mon, 29 Aug 2016 11:40:25 -0300 Subject: [PATCH] Adiciona assinatura ao cancelamento da NFSe --- pytrustnfe/nfse/paulistana/__init__.py | 19 +++++++++++-------- .../nfse/paulistana/templates/CancelamentoNFe.xml | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pytrustnfe/nfse/paulistana/__init__.py b/pytrustnfe/nfse/paulistana/__init__.py index 596b5f8..fd88892 100644 --- a/pytrustnfe/nfse/paulistana/__init__.py +++ b/pytrustnfe/nfse/paulistana/__init__.py @@ -3,12 +3,10 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import os -import logging import suds from OpenSSL import crypto -from base64 import b64encode, b64decode -from uuid import uuid4 -from pytrustnfe.xml import render_xml, valida_schema, sanitize_response +from base64 import b64encode +from pytrustnfe.xml import render_xml, sanitize_response from pytrustnfe.client import get_authenticated_client from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key from pytrustnfe.nfe.assinatura import Assinatura @@ -17,15 +15,20 @@ from pytrustnfe.nfe.assinatura import Assinatura def sign_tag(certificado, **kwargs): pkcs12 = crypto.load_pkcs12(certificado.pfx, certificado.password) key = pkcs12.get_privatekey() - for item in kwargs['nfse']['lista_rps']: - signed = crypto.sign(key, item['assinatura'], 'SHA1') - item['assinatura'] = b64encode(signed) + if 'nfse' in kwargs: + for item in kwargs['nfse']['lista_rps']: + signed = crypto.sign(key, item['assinatura'], 'SHA1') + item['assinatura'] = b64encode(signed) + if 'cancelamento' in kwargs: + signed = crypto.sign(key, kwargs['cancelamento']['assinatura'], 'SHA1') + kwargs['cancelamento']['assinatura'] = b64encode(signed) def _send(certificado, method, **kwargs): # A little hack to test path = os.path.join(os.path.dirname(__file__), 'templates') - if method == 'TesteEnvioLoteRPS' or method == 'EnvioLoteRPS': + if method == 'TesteEnvioLoteRPS' or method == 'EnvioLoteRPS' \ + or method == 'CancelamentoNFe': sign_tag(certificado, **kwargs) if method == 'TesteEnvioLoteRPS': diff --git a/pytrustnfe/nfse/paulistana/templates/CancelamentoNFe.xml b/pytrustnfe/nfse/paulistana/templates/CancelamentoNFe.xml index 6e31954..6f75dfc 100755 --- a/pytrustnfe/nfse/paulistana/templates/CancelamentoNFe.xml +++ b/pytrustnfe/nfse/paulistana/templates/CancelamentoNFe.xml @@ -1,7 +1,7 @@ - {{ cancelamento.cpf_cnpj }} + {{ cancelamento.cnpj_remetente }} 1