diff --git a/pytrustnfe/Servidores.py b/pytrustnfe/Servidores.py index f5ac4d1..44dda58 100644 --- a/pytrustnfe/Servidores.py +++ b/pytrustnfe/Servidores.py @@ -153,6 +153,7 @@ SVRS = { NFE_AMBIENTE_PRODUCAO: { 'servidor': 'nfe.svrs.rs.gov.br', WS_NFE_RECEPCAO_EVENTO: 'ws/recepcaoevento/recepcaoevento.asmx', + WS_NFE_CANCELAMENTO: 'ws/recepcaoevento/recepcaoevento.asmx', WS_NFE_AUTORIZACAO: 'ws/NfeAutorizacao/NfeAutorizacao.asmx', WS_NFE_RET_AUTORIZACAO: 'ws/NfeRetAutorizacao/NfeRetAutorizacao.asmx', WS_NFE_CADASTRO: 'ws/CadConsultaCadastro/CadConsultaCadastro2.asmx', @@ -163,6 +164,7 @@ SVRS = { NFE_AMBIENTE_HOMOLOGACAO: { 'servidor': 'nfe-homologacao.svrs.rs.gov.br', WS_NFE_RECEPCAO_EVENTO: 'ws/recepcaoevento/recepcaoevento.asmx', + WS_NFE_CANCELAMENTO: 'ws/recepcaoevento/recepcaoevento.asmx', WS_NFE_AUTORIZACAO: 'ws/NfeAutorizacao/NfeAutorizacao.asmx', WS_NFE_RET_AUTORIZACAO: 'ws/NfeRetAutorizacao/NfeRetAutorizacao.asmx', WS_NFE_CADASTRO: 'ws/CadConsultaCadastro/CadConsultaCadastro2.asmx', @@ -508,6 +510,7 @@ UFRS = { WS_NFE_INUTILIZACAO: 'ws/NfeInutilizacao/NfeInutilizacao2.asmx', WS_NFE_CONSULTA: 'ws/NfeConsulta/NfeConsulta2.asmx', WS_NFE_SITUACAO: 'ws/NfeStatusServico/NfeStatusServico2.asmx', + WS_NFE_CANCELAMENTO: 'ws/recepcaoevento/recepcaoevento.asmx', }, NFE_AMBIENTE_HOMOLOGACAO: { 'servidor': 'nfe-homologacao.sefazrs.rs.gov.br', @@ -520,6 +523,7 @@ UFRS = { WS_NFE_INUTILIZACAO: 'ws/NfeInutilizacao/NfeInutilizacao2.asmx', WS_NFE_CONSULTA: 'ws/NfeConsulta/NfeConsulta2.asmx', WS_NFE_SITUACAO: 'ws/NfeStatusServico/NfeStatusServico2.asmx', + WS_NFE_CANCELAMENTO: 'ws/recepcaoevento/recepcaoevento.asmx', } } @@ -534,6 +538,7 @@ UFSP = { WS_NFE_SITUACAO: 'ws/nfestatusservico2.asmx', WS_NFE_CADASTRO: 'ws/cadconsultacadastro2.asmx', WS_NFE_RECEPCAO_EVENTO: 'ws/recepcaoevento.asmx', + WS_NFE_CANCELAMENTO: 'ws/recepcaoevento.asmx', }, NFE_AMBIENTE_HOMOLOGACAO: { 'servidor': 'homologacao.nfe.fazenda.sp.gov.br', @@ -544,6 +549,7 @@ UFSP = { WS_NFE_SITUACAO: 'ws/nfestatusservico2.asmx', WS_NFE_CADASTRO: 'ws/cadconsultacadastro2.asmx', WS_NFE_RECEPCAO_EVENTO: 'ws/recepcaoevento.asmx', + WS_NFE_CANCELAMENTO: 'ws/recepcaoevento.asmx', } } diff --git a/pytrustnfe/nfe/__init__.py b/pytrustnfe/nfe/__init__.py index 1d7636a..bd900f0 100644 --- a/pytrustnfe/nfe/__init__.py +++ b/pytrustnfe/nfe/__init__.py @@ -18,6 +18,7 @@ def _build_header(method, **kwargs): 'NfeAutorizacao': ('NfeAutorizacao', '3.10'), 'NfeRetAutorizacao': ('NfeRetAutorizacao', '3.10'), 'NfeConsultaCadastro': ('CadConsultaCadastro2', '2.00'), + 'RecepcaoEventoCancelamento': ('RecepcaoEvento', '1.00') } vals = {'estado': kwargs['estado'], 'soap_action': action[method][0], @@ -55,7 +56,7 @@ def _add_required_node(elemTree): cEan = etree.Element('cEAN') cEANTrib = etree.Element('cEANTrib') prod.insert(1, cEan) - vProd = prod.find('ns:vProd', namespaces = ns) + vProd = prod.find('ns:vProd', namespaces=ns) prod.insert(prod.index(vProd) + 1, cEANTrib) return elemTree diff --git a/pytrustnfe/nfe/assinatura.py b/pytrustnfe/nfe/assinatura.py index 9520ace..7104e9b 100644 --- a/pytrustnfe/nfe/assinatura.py +++ b/pytrustnfe/nfe/assinatura.py @@ -33,6 +33,10 @@ class Assinatura(object): signed_root = signer.sign( xml_element, key=key, cert=cert, reference_uri=('#%s' % reference)) - if len(signed_root) > 3: - signed_root[2].append(signed_root[3]) + element_signed = signed_root.find(".//*[@Id='%s']" % reference) + signature = signed_root.find( + ".//{http://www.w3.org/2000/09/xmldsig#}Signature") + if element_signed and signature: + parent = element_signed.getparent() + parent.append(signature) return etree.tostring(signed_root)