Browse Source

[WIP] Cleanup of useless code, using zeep for NFe soap, adjust xml files

pull/147/head
Danimar Ribeiro 8 years ago
parent
commit
5cbdd146f5
  1. 86
      pytrustnfe/Servidores.py
  2. 63
      pytrustnfe/nfe/__init__.py
  3. 32
      pytrustnfe/nfe/comunicacao.py
  4. 3
      pytrustnfe/nfe/templates/NfeConsultaProtocolo.xml
  5. 5
      pytrustnfe/nfe/templates/RecepcaoEvento.xml
  6. 21
      pytrustnfe/nfe/templates/RecepcaoEventoCarta.xml
  7. 31
      pytrustnfe/nfe/templates/RecepcaoEventoEPEC.xml
  8. 9
      pytrustnfe/utils.py
  9. 15
      pytrustnfe/xml/__init__.py
  10. 20
      tests/test_comunicacao.py
  11. 12
      tests/test_servidores.py

86
pytrustnfe/Servidores.py

@ -314,25 +314,23 @@ UFAM = {
UFBA = { UFBA = {
AMBIENTE_PRODUCAO: { AMBIENTE_PRODUCAO: {
'servidor': 'nfe.sefaz.ba.gov.br', 'servidor': 'nfe.sefaz.ba.gov.br',
WS_NFE_AUTORIZACAO: 'webservices/NfeAutorizacao/NfeAutorizacao.asmx',
WS_NFE_RET_AUTORIZACAO:
'webservices/NfeRetAutorizacao/NfeRetAutorizacao.asmx',
WS_NFE_CONSULTA: 'webservices/NfeConsulta/NfeConsulta.asmx',
WS_NFE_SITUACAO: 'webservices/NfeStatusServico/NfeStatusServico.asmx',
WS_NFE_INUTILIZACAO: 'webservices/nfenw/nfeinutilizacao2.asmx',
WS_NFE_CADASTRO: 'webservices/nfenw/CadConsultaCadastro2.asmx',
WS_NFE_RECEPCAO_EVENTO: 'webservices/sre/recepcaoevento.asmx',
WS_NFE_INUTILIZACAO: 'webservices/NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl',
WS_NFE_CONSULTA: 'webservices/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl',
WS_NFE_SITUACAO: 'webservices/NFeStatusServico4/NFeStatusServico4.asmx?wsdl',
WS_NFE_RECEPCAO_EVENTO: 'webservices/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl',
WS_NFE_AUTORIZACAO: 'webservices/NFeAutorizacao4/NFeAutorizacao4.asmx?wsdl',
WS_NFE_RET_AUTORIZACAO: 'webservices/NFeRetAutorizacao4/NFeRetAutorizacao4.asmx?wsdl',
WS_NFE_CADASTRO: 'webservices/CadConsultaCadastro4/CadConsultaCadastro4.asmx?wsdl',
}, },
AMBIENTE_HOMOLOGACAO: { AMBIENTE_HOMOLOGACAO: {
'servidor': 'hnfe.sefaz.ba.gov.br', 'servidor': 'hnfe.sefaz.ba.gov.br',
WS_NFE_AUTORIZACAO: 'webservices/NfeAutorizacao/NfeAutorizacao.asmx',
WS_NFE_RET_AUTORIZACAO:
'webservices/NfeRetAutorizacao/NfeRetAutorizacao.asmx',
WS_NFE_CONSULTA: 'webservices/NfeConsulta/NfeConsulta.asmx',
WS_NFE_SITUACAO: 'webservices/NfeStatusServico/NfeStatusServico.asmx',
WS_NFE_INUTILIZACAO: 'webservices/nfenw/nfeinutilizacao2.asmx',
WS_NFE_CADASTRO: 'webservices/nfenw/CadConsultaCadastro2.asmx',
WS_NFE_RECEPCAO_EVENTO: 'webservices/sre/recepcaoevento.asmx',
WS_NFE_INUTILIZACAO: 'webservices/NFeInutilizacao4/NFeInutilizacao4.asmx?wsdl',
WS_NFE_CONSULTA: 'webservices/NFeConsultaProtocolo4/NFeConsultaProtocolo4.asmx?wsdl',
WS_NFE_SITUACAO: 'webservices/NFeStatusServico4/NFeStatusServico4.asmx?wsdl',
WS_NFE_RECEPCAO_EVENTO: 'webservices/NFeRecepcaoEvento4/NFeRecepcaoEvento4.asmx?wsdl',
WS_NFE_AUTORIZACAO: 'webservices/NFeAutorizacao4/NFeAutorizacao4.asmx?wsdl',
WS_NFE_RET_AUTORIZACAO: 'webservices/NFeRetAutorizacao4/NFeRetAutorizacao4.asmx?wsdl',
WS_NFE_CADASTRO: 'webservices/CadConsultaCadastro4/CadConsultaCadastro4.asmx?wsdl',
} }
} }
@ -363,23 +361,23 @@ UFCE = {
UFGO = { UFGO = {
AMBIENTE_PRODUCAO: { AMBIENTE_PRODUCAO: {
'servidor': 'nfe.sefaz.go.gov.br', 'servidor': 'nfe.sefaz.go.gov.br',
WS_NFE_RECEPCAO_EVENTO: 'nfe/services/v2/RecepcaoEvento',
WS_NFE_AUTORIZACAO: 'nfe/services/v2/NfeAutorizacao',
WS_NFE_RET_AUTORIZACAO: 'nfe/services/v2/NfeRetAutorizacao',
WS_NFE_INUTILIZACAO: 'nfe/services/v2/NfeInutilizacao2',
WS_NFE_CONSULTA: 'nfe/services/v2/NfeConsulta2',
WS_NFE_SITUACAO: 'nfe/services/v2/NfeStatusServico2',
WS_NFE_CADASTRO: 'nfe/services/v2/CadConsultaCadastro2',
WS_NFE_INUTILIZACAO: 'nfe/services/NFeInutilizacao4?wsdl',
WS_NFE_CONSULTA: 'nfe/services/NFeConsultaProtocolo4?wsdl',
WS_NFE_SITUACAO: 'nfe/services/NFeStatusServico4?wsdl',
WS_NFE_RECEPCAO_EVENTO: 'nfe/services/NFeRecepcaoEvento4?wsdl',
WS_NFE_AUTORIZACAO: 'nfe/services/NFeAutorizacao4?wsdl',
WS_NFE_RET_AUTORIZACAO: 'nfe/services/NFeRetAutorizacao4?wsdl',
WS_NFE_CADASTRO: 'nfe/services/CadConsultaCadastro4?wsdl',
}, },
AMBIENTE_HOMOLOGACAO: { AMBIENTE_HOMOLOGACAO: {
'servidor': 'homolog.sefaz.go.gov.br', 'servidor': 'homolog.sefaz.go.gov.br',
WS_NFE_RECEPCAO_EVENTO: 'nfe/services/v2/RecepcaoEvento',
WS_NFE_AUTORIZACAO: 'nfe/services/v2/NfeAutorizacao',
WS_NFE_RET_AUTORIZACAO: 'nfe/services/v2/NfeRetAutorizacao',
WS_NFE_INUTILIZACAO: 'nfe/services/v2/NfeInutilizacao2',
WS_NFE_CONSULTA: 'nfe/services/v2/NfeConsulta2',
WS_NFE_SITUACAO: 'nfe/services/v2/NfeStatusServico2',
WS_NFE_CADASTRO: 'nfe/services/v2/CadConsultaCadastro2',
WS_NFE_INUTILIZACAO: 'nfe/services/NFeInutilizacao4?wsdl',
WS_NFE_CONSULTA: 'nfe/services/NFeConsultaProtocolo4?wsdl',
WS_NFE_SITUACAO: 'nfe/services/NFeStatusServico4?wsdl',
WS_NFE_RECEPCAO_EVENTO: 'nfe/services/NFeRecepcaoEvento4?wsdl',
WS_NFE_AUTORIZACAO: 'nfe/services/NFeAutorizacao4?wsdl',
WS_NFE_RET_AUTORIZACAO: 'nfe/services/NFeRetAutorizacao4?wsdl',
WS_NFE_CADASTRO: 'nfe/services/CadConsultaCadastro4?wsdl',
} }
} }
@ -554,23 +552,23 @@ UFSP = {
NFE_MODELO: { NFE_MODELO: {
AMBIENTE_PRODUCAO: { AMBIENTE_PRODUCAO: {
'servidor': 'nfe.fazenda.sp.gov.br', 'servidor': 'nfe.fazenda.sp.gov.br',
WS_NFE_AUTORIZACAO: 'ws/nfeautorizacao.asmx',
WS_NFE_RET_AUTORIZACAO: 'ws/nferetautorizacao.asmx',
WS_NFE_INUTILIZACAO: 'ws/nfeinutilizacao2.asmx',
WS_NFE_CONSULTA: 'ws/nfeconsulta2.asmx',
WS_NFE_SITUACAO: 'ws/nfestatusservico2.asmx',
WS_NFE_CADASTRO: 'ws/cadconsultacadastro2.asmx',
WS_NFE_RECEPCAO_EVENTO: 'ws/recepcaoevento.asmx',
WS_NFE_INUTILIZACAO: 'ws/nfeinutilizacao4.asmx?wsdl',
WS_NFE_CONSULTA: 'ws/nfeconsultaprotocolo4.asmx?wsdl',
WS_NFE_SITUACAO: 'ws/nfestatusservico4.asmx?wsdl',
WS_NFE_RECEPCAO_EVENTO: 'ws/nferecepcaoevento4.asmx?wsdl',
WS_NFE_AUTORIZACAO: 'ws/nfeautorizacao4.asmx?wsdl',
WS_NFE_RET_AUTORIZACAO: 'ws/nferetautorizacao4.asmx?wsdl',
WS_NFE_CADASTRO: 'ws/cadconsultacadastro4.asmx?wsdl',
}, },
AMBIENTE_HOMOLOGACAO: { AMBIENTE_HOMOLOGACAO: {
'servidor': 'homologacao.nfe.fazenda.sp.gov.br', 'servidor': 'homologacao.nfe.fazenda.sp.gov.br',
WS_NFE_AUTORIZACAO: 'ws/nfeautorizacao.asmx',
WS_NFE_RET_AUTORIZACAO: 'ws/nferetautorizacao.asmx',
WS_NFE_INUTILIZACAO: 'ws/nfeinutilizacao2.asmx',
WS_NFE_CONSULTA: 'ws/nfeconsulta2.asmx',
WS_NFE_SITUACAO: 'ws/nfestatusservico2.asmx',
WS_NFE_CADASTRO: 'ws/cadconsultacadastro2.asmx',
WS_NFE_RECEPCAO_EVENTO: 'ws/recepcaoevento.asmx',
WS_NFE_INUTILIZACAO: 'ws/nfeinutilizacao4.asmx?wsdl',
WS_NFE_CONSULTA: 'ws/nfeconsultaprotocolo4.asmx?wsdl',
WS_NFE_SITUACAO: 'ws/nfestatusservico4.asmx?wsdl',
WS_NFE_RECEPCAO_EVENTO: 'ws/nferecepcaoevento4.asmx?wsdl',
WS_NFE_AUTORIZACAO: 'ws/nfeautorizacao4.asmx?wsdl',
WS_NFE_RET_AUTORIZACAO: 'ws/nferetautorizacao4.asmx?wsdl',
WS_NFE_CADASTRO: 'ws/cadconsultacadastro4.asmx?wsdl',
} }
}, },
NFCE_MODELO: { NFCE_MODELO: {

63
pytrustnfe/nfe/__init__.py

@ -7,14 +7,10 @@ import os
import hashlib import hashlib
import binascii import binascii
from lxml import etree from lxml import etree
from .comunicacao import executar_consulta
from .assinatura import Assinatura from .assinatura import Assinatura
from pytrustnfe.xml import render_xml, sanitize_response from pytrustnfe.xml import render_xml, sanitize_response
from pytrustnfe.utils import CabecalhoSoap
from pytrustnfe.utils import gerar_chave, ChaveNFe from pytrustnfe.utils import gerar_chave, ChaveNFe
from pytrustnfe.Servidores import localizar_url, localizar_qrcode from pytrustnfe.Servidores import localizar_url, localizar_qrcode
from pytrustnfe.xml.validate import valida_nfe
from pytrustnfe.exceptions import NFeValidationException
from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key
# Zeep # Zeep
@ -23,26 +19,6 @@ from zeep import Client
from zeep.transports import Transport from zeep.transports import Transport
def _build_header(method, **kwargs):
action = {
'NfeAutorizacao': ('NfeAutorizacao', '3.10', 'NfeAutorizacao/nfeAutorizacaoLote'),
'NfeRetAutorizacao': ('NfeRetAutorizacao', '3.10', 'NfeRetAutorizacao/nfeRetAutorizacaoLote'),
'NfeConsultaCadastro': ('CadConsultaCadastro2', '2.00', 'CadConsultaCadastro2/consultaCadastro2'),
'NfeInutilizacao': ('NfeInutilizacao2', '3.10', 'NfeInutilizacao2/nfeInutilizacaoNF2'),
'RecepcaoEventoCancelamento': ('RecepcaoEvento', '1.00', 'RecepcaoEvento/nfeRecepcaoEvento'),
'RecepcaoEventoCarta': ('RecepcaoEvento', '1.00', 'RecepcaoEvento/nfeRecepcaoEvento'),
'NFeDistribuicaoDFe': ('NFeDistribuicaoDFe/nfeDistDFeInteresse', '1.00', 'NFeDistribuicaoDFe/nfeDistDFeInteresse'),
'RecepcaoEventoManifesto': ('RecepcaoEvento', '1.00', 'RecepcaoEvento/nfeRecepcaoEvento'),
}
vals = {
'estado': kwargs['estado'],
'method': action[method][0],
'soap_action': action[method][2],
'versao': action[method][1]
}
return CabecalhoSoap(**vals)
def _generate_nfe_id(**kwargs): def _generate_nfe_id(**kwargs):
for item in kwargs['NFes']: for item in kwargs['NFes']:
vals = { vals = {
@ -136,18 +112,6 @@ def _render(certificado, method, sign, **kwargs):
modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod") modelo = xmlElem_send.find(".//{http://www.portalfiscal.inf.br/nfe}mod")
modelo = modelo.text if modelo is not None else '55' modelo = modelo.text if modelo is not None else '55'
if modelo == '65':
pagamento = etree.Element('pag')
tipo_pagamento = etree.Element('tPag')
valor = etree.Element('vPag')
valor_pago = kwargs['NFes'][0]['infNFe']['total']['vNF']
metodo_pagamento = kwargs['NFes'][0]['infNFe']['pagamento']
tipo_pagamento.text, valor.text = metodo_pagamento, valor_pago
pagamento.append(tipo_pagamento)
pagamento.append(valor)
transp = xmlElem_send.find(
".//{http://www.portalfiscal.inf.br/nfe}transp")
transp.addnext(pagamento)
if sign: if sign:
# Caso for autorização temos que adicionar algumas tags tipo # Caso for autorização temos que adicionar algumas tags tipo
@ -161,19 +125,9 @@ def _render(certificado, method, sign, **kwargs):
if method == 'NfeAutorizacao': if method == 'NfeAutorizacao':
xml_send = signer.assina_xml( xml_send = signer.assina_xml(
xmlElem_send, kwargs['NFes'][0]['infNFe']['Id']) xmlElem_send, kwargs['NFes'][0]['infNFe']['Id'])
if 'validate' in kwargs:
erros = valida_nfe(xml_send)
if erros:
raise NFeValidationException('Erro ao validar NFe',
erros=erros,
sent_xml=xml_send)
elif method == 'RecepcaoEventoCancelamento':
elif method == 'RecepcaoEvento':
xml_send = signer.assina_xml( xml_send = signer.assina_xml(
xmlElem_send, kwargs['eventos'][0]['Id']) xmlElem_send, kwargs['eventos'][0]['Id'])
if method == 'RecepcaoEventoCarta':
xml_send = signer.assina_xml(
xmlElem_send, kwargs['Id'])
elif method == 'RecepcaoEventoManifesto': elif method == 'RecepcaoEventoManifesto':
xml_send = signer.assina_xml( xml_send = signer.assina_xml(
xmlElem_send, kwargs['manifesto']['identificador']) xmlElem_send, kwargs['manifesto']['identificador'])
@ -188,8 +142,8 @@ def _render(certificado, method, sign, **kwargs):
def _send(certificado, method, **kwargs): def _send(certificado, method, **kwargs):
xml_send = kwargs["xml"] xml_send = kwargs["xml"]
base_url = localizar_url(method, kwargs['estado'], kwargs['modelo'],
kwargs['ambiente'])
base_url = localizar_url(
method, kwargs['estado'], kwargs['modelo'], kwargs['ambiente'])
cert, key = extract_cert_and_key_from_pfx( cert, key = extract_cert_and_key_from_pfx(
certificado.pfx, certificado.password) certificado.pfx, certificado.password)
@ -208,7 +162,6 @@ def _send(certificado, method, **kwargs):
with client.options(raw_response=True): with client.options(raw_response=True):
response = client.service[first_operation](xml) response = client.service[first_operation](xml)
response, obj = sanitize_response(response.text) response, obj = sanitize_response(response.text)
return { return {
'sent_xml': xml_send, 'sent_xml': xml_send,
'received_xml': response, 'received_xml': response,
@ -238,13 +191,13 @@ def retorno_autorizar_nfe(certificado, **kwargs):
def xml_recepcao_evento_cancelamento(certificado, **kwargs): # Assinar def xml_recepcao_evento_cancelamento(certificado, **kwargs): # Assinar
return _render(certificado, 'RecepcaoEventoCancelamento', True, **kwargs)
return _render(certificado, 'RecepcaoEvento', True, **kwargs)
def recepcao_evento_cancelamento(certificado, **kwargs): # Assinar def recepcao_evento_cancelamento(certificado, **kwargs): # Assinar
if "xml" not in kwargs: if "xml" not in kwargs:
kwargs['xml'] = xml_recepcao_evento_cancelamento(certificado, **kwargs) kwargs['xml'] = xml_recepcao_evento_cancelamento(certificado, **kwargs)
return _send(certificado, 'RecepcaoEventoCancelamento', **kwargs)
return _send(certificado, 'RecepcaoEvento', **kwargs)
def xml_inutilizar_nfe(certificado, **kwargs): def xml_inutilizar_nfe(certificado, **kwargs):
@ -258,7 +211,7 @@ def inutilizar_nfe(certificado, **kwargs):
def xml_consultar_protocolo_nfe(certificado, **kwargs): def xml_consultar_protocolo_nfe(certificado, **kwargs):
return _render(certificado, 'NfeConsultaProtocolo', True, **kwargs)
return _render(certificado, 'NfeConsultaProtocolo', False, **kwargs)
def consultar_protocolo_nfe(certificado, **kwargs): def consultar_protocolo_nfe(certificado, **kwargs):
@ -289,14 +242,14 @@ def consulta_cadastro(certificado, **kwargs):
def xml_recepcao_evento_carta_correcao(certificado, **kwargs): # Assinar def xml_recepcao_evento_carta_correcao(certificado, **kwargs): # Assinar
return _render(certificado, 'RecepcaoEventoCarta', True, **kwargs)
return _render(certificado, 'RecepcaoEvento', True, **kwargs)
def recepcao_evento_carta_correcao(certificado, **kwargs): # Assinar def recepcao_evento_carta_correcao(certificado, **kwargs): # Assinar
if "xml" not in kwargs: if "xml" not in kwargs:
kwargs['xml'] = xml_recepcao_evento_carta_correcao( kwargs['xml'] = xml_recepcao_evento_carta_correcao(
certificado, **kwargs) certificado, **kwargs)
return _send(certificado, 'RecepcaoEventoCarta', **kwargs)
return _send(certificado, 'RecepcaoEvento', **kwargs)
def xml_recepcao_evento_manifesto(certificado, **kwargs): # Assinar def xml_recepcao_evento_manifesto(certificado, **kwargs): # Assinar

32
pytrustnfe/nfe/comunicacao.py

@ -1,32 +0,0 @@
# -*- coding: utf-8 -*-
# © 2016 Danimar Ribeiro, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from pytrustnfe.client import HttpClient
from pytrustnfe.certificado import save_cert_key, extract_cert_and_key_from_pfx
from ..xml import sanitize_response
def _soap_xml(body, cabecalho):
xml = '<?xml version="1.0" encoding="utf-8"?>'
xml += '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header><soap:Body>'
xml += '<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/' + cabecalho.method + '">'
xml += body
xml += '</nfeDadosMsg></soap:Body></soap:Envelope>'
return xml.rstrip('\n')
def executar_consulta(certificado, url, cabecalho, xmlEnviar, send_raw=False):
cert, key = extract_cert_and_key_from_pfx(
certificado.pfx, certificado.password)
cert_path, key_path = save_cert_key(cert, key)
client = HttpClient(url, cert_path, key_path)
xml_enviar = _soap_xml(xmlEnviar, cabecalho)
if send_raw:
xml = '<?xml version="1.0" encoding="utf-8"?>' + xmlEnviar.rstrip('\n')
xml_enviar = xml
xml_retorno = client.post_soap(xml_enviar, cabecalho, send_raw)
return sanitize_response(xml_retorno.encode())

3
pytrustnfe/nfe/templates/NfeConsultaProtocolo.xml

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<consSitNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="2.01">
<consSitNFe xmlns="http://www.portalfiscal.inf.br/nfe" versao="4.00">
<tpAmb>{{ obj.ambiente }}</tpAmb> <tpAmb>{{ obj.ambiente }}</tpAmb>
<xServ>CONSULTAR</xServ> <xServ>CONSULTAR</xServ>
<chNFe>{{ obj.chave_nfe }}</chNFe> <chNFe>{{ obj.chave_nfe }}</chNFe>

5
pytrustnfe/nfe/templates/RecepcaoEventoCancelamento.xml → pytrustnfe/nfe/templates/RecepcaoEvento.xml

@ -8,13 +8,14 @@
<CNPJ>{{ evento.CNPJ }}</CNPJ> <CNPJ>{{ evento.CNPJ }}</CNPJ>
<chNFe>{{ evento.chNFe }}</chNFe> <chNFe>{{ evento.chNFe }}</chNFe>
<dhEvento>{{ evento.dhEvento }}</dhEvento> <dhEvento>{{ evento.dhEvento }}</dhEvento>
<tpEvento>110111</tpEvento>
<tpEvento>{{ evento.tpEvento }}</tpEvento>
<nSeqEvento>{{ evento.nSeqEvento }}</nSeqEvento> <nSeqEvento>{{ evento.nSeqEvento }}</nSeqEvento>
<verEvento>1.00</verEvento> <verEvento>1.00</verEvento>
<detEvento versao="1.00"> <detEvento versao="1.00">
<descEvento>Cancelamento</descEvento>
<descEvento>{{ evento.descEvento }}</descEvento>
<nProt>{{ evento.nProt }}</nProt> <nProt>{{ evento.nProt }}</nProt>
<xJust>{{ evento.xJust|normalize|escape }}</xJust> <xJust>{{ evento.xJust|normalize|escape }}</xJust>
<xCondUso>{{ evento.xCondUso }}.</xCondUso>
</detEvento> </detEvento>
</infEvento> </infEvento>
</evento> </evento>

21
pytrustnfe/nfe/templates/RecepcaoEventoCarta.xml

@ -1,21 +0,0 @@
<envEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00">
<idLote>{{ idLote }}</idLote>
<evento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00">
<infEvento Id="{{ Id }}">
<cOrgao>{{ cOrgao }}</cOrgao>
<tpAmb>{{ tpAmb }}</tpAmb>
<CNPJ>{{ CNPJ }}</CNPJ>
<CPF>{{ CPF }}</CPF>
<chNFe>{{ chNFe }}</chNFe>
<dhEvento>{{ dhEvento }}</dhEvento>
<tpEvento>{{ tpEvento }}</tpEvento>
<nSeqEvento>{{ nSeqEvento }}</nSeqEvento>
<verEvento>1.00</verEvento>
<detEvento versao="1.00">
<descEvento>Carta de Correcao</descEvento>
<xCorrecao>{{ xCorrecao|normalize|escape }}</xCorrecao>
<xCondUso>A Carta de Correcao e disciplinada pelo paragrafo 1o-A do art. 7o do Convenio S/N, de 15 de dezembro de 1970 e pode ser utilizada para regularizacao de erro ocorrido na emissao de documento fiscal, desde que o erro nao esteja relacionado com: I - as variaveis que determinam o valor do imposto tais como: base de calculo, aliquota, diferenca de preco, quantidade, valor da operacao ou da prestacao; II - a correcao de dados cadastrais que implique mudanca do remetente ou do destinatario; III - a data de emissao ou de saida.</xCondUso>
</detEvento>
</infEvento>
</evento>
</envEvento>

31
pytrustnfe/nfe/templates/RecepcaoEventoEPEC.xml

@ -1,31 +0,0 @@
<envEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00">
<idLote>00106151340701</idLote>
<evento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00">
<infEvento Id="ID1101403514081014278500019055001001061513407959995201">
<cOrgao>91</cOrgao>
<tpAmb>2</tpAmb>
<CNPJ>10142785000190</CNPJ>
<chNFe>35140810142785000190550010010615134079599952</chNFe>
<dhEvento>2014-08-07T04:52:51-03:00</dhEvento>
<tpEvento>110140</tpEvento>
<nSeqEvento>1</nSeqEvento>
<verEvento>1.00</verEvento>
<detEvento versao="1.00">
<descEvento>EPEC</descEvento>
<cOrgaoAutor>35</cOrgaoAutor>
<tpAutor>1</tpAutor>
<verAplic>1.26</verAplic>
<dhEmi>2014-08-07T00:00:00-03:00</dhEmi>
<tpNF>1</tpNF>
<IE>495171423115</IE>
<dest>
<UF>SP</UF>
<CPF>00000000191</CPF>
<vNF>86.00</vNF>
<vICMS>6.02</vICMS>
<vST>0</vST>
</dest>
</detEvento>
</infEvento>
</evento>
</envEvento>

9
pytrustnfe/utils.py

@ -8,15 +8,6 @@ from datetime import date, datetime
import lxml.etree as ET import lxml.etree as ET
class CabecalhoSoap(object):
def __init__(self, **kwargs):
self.versao = kwargs.pop('versao', '')
self.estado = kwargs.pop('estado', '')
self.method = kwargs.pop('method', '')
self.soap_action = kwargs.pop('soap_action', '')
class ChaveNFe(object): class ChaveNFe(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):

15
pytrustnfe/xml/__init__.py

@ -15,18 +15,6 @@ def recursively_empty(e):
return all((recursively_empty(c) for c in e.iterchildren())) return all((recursively_empty(c) for c in e.iterchildren()))
def recursively_normalize(vals):
for item in vals:
if type(vals[item]) is str:
vals[item] = vals[item].strip()
elif type(vals[item]) is dict:
recursively_normalize(vals[item])
elif type(vals[item]) is list:
for a in vals[item]:
recursively_normalize(a)
return vals
def render_xml(path, template_name, remove_empty, **nfe): def render_xml(path, template_name, remove_empty, **nfe):
nfe = recursively_normalize(nfe) nfe = recursively_normalize(nfe)
env = Environment( env = Environment(
@ -58,7 +46,8 @@ def render_xml(path, template_name, remove_empty, **nfe):
def sanitize_response(response): def sanitize_response(response):
tree = etree.fromstring(response)
parser = etree.XMLParser(encoding='utf-8')
tree = etree.fromstring(response.encode('UTF-8'), parser=parser)
# Remove namespaces inuteis na resposta # Remove namespaces inuteis na resposta
for elem in tree.getiterator(): for elem in tree.getiterator():
if not hasattr(elem.tag, 'find'): if not hasattr(elem.tag, 'find'):

20
tests/test_comunicacao.py

@ -1,20 +0,0 @@
# coding=utf-8
'''
Created on Jun 16, 2015
@author: danimar
'''
import unittest
import os.path
XML_RETORNO = '<retEnviNFe><cStat>103</cStat>' \
'<cUF>42</cUF></retEnviNFe>'
class test_comunicacao(unittest.TestCase):
caminho = os.path.dirname(__file__)
def test_envio_nfe(self):
pass

12
tests/test_servidores.py

@ -7,22 +7,22 @@ Created on Jun 14, 2015
import unittest import unittest
from pytrustnfe.Servidores import localizar_url, localizar_qrcode from pytrustnfe.Servidores import localizar_url, localizar_qrcode
url_ba = 'https://nfe.sefaz.ba.gov.br/webservices/NfeAutorizacao/NfeAutoriza\
cao.asmx'
url_ba = 'https://nfe.sefaz.ba.gov.br/webservices/NFeAutorizacao4/NFeAutoriza\
cao4.asmx?wsdl'
url_sp = 'https://nfe.fazenda.sp.gov.br/ws/nfeautorizacao.asmx'
url_sp = 'https://nfe.fazenda.sp.gov.br/ws/nfeautorizacao4.asmx?wsdl'
url_qrcode_homologacao_sp = 'https://homologacao.nfce.fazenda.sp.gov.br/NFCEConsultaPublica/Paginas/ConstultaQRCode.aspx' url_qrcode_homologacao_sp = 'https://homologacao.nfce.fazenda.sp.gov.br/NFCEConsultaPublica/Paginas/ConstultaQRCode.aspx'
url_sc = 'https://nfe.svrs.rs.gov.br/ws/NfeAutorizacao/NfeAutorizacao.asmx'
url_sc = 'https://nfe.svrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao4.asmx'
url_rs = 'https://nfe.sefazrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao.asmx' url_rs = 'https://nfe.sefazrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao.asmx'
url_cad_rs = 'https://cad.sefazrs.rs.gov.br/ws/cadconsultacadastro/cadcon\ url_cad_rs = 'https://cad.sefazrs.rs.gov.br/ws/cadconsultacadastro/cadcon\
sultacadastro2.asmx' sultacadastro2.asmx'
url_cad_sc = 'https://cad.svrs.rs.gov.br/ws/CadConsultaCadastro/CadConsult\
aCadastro2.asmx'
url_cad_sc = 'https://cad.svrs.rs.gov.br/ws/cadconsultacadastro/cadconsulta\
cadastro2.asmx'
class test_servidores(unittest.TestCase): class test_servidores(unittest.TestCase):

Loading…
Cancel
Save