|
|
|
@ -4,10 +4,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
|
from lxml import etree |
|
|
|
from .comunicacao import executar_consulta, Comunicacao |
|
|
|
from .assinatura import sign_xml, Assinatura |
|
|
|
from pytrustnfe import utils |
|
|
|
from .comunicacao import executar_consulta |
|
|
|
from .assinatura import Assinatura |
|
|
|
from pytrustnfe.xml import render_xml |
|
|
|
from pytrustnfe.utils import CabecalhoSoap |
|
|
|
|
|
|
|
@ -31,81 +29,49 @@ def _send(certificado, method, **kwargs): |
|
|
|
return executar_consulta(certificado, cabecalho, xml_signed) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def autorizar_nfe(certificado, **kwargs): # Assinar |
|
|
|
_send(certificado, 'NfeAutorizacao', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def retorno_autorizar_nfe(certificado, **kwargs): |
|
|
|
_send(certificado, 'NfeRetAutorizacao', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def recepcao_evento_cancelamento(certificado, **kwargs): # Assinar |
|
|
|
_send(certificado, 'RecepcaoEventoCancelamento', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def inutilizar_nfe(certificado, **kwargs): # Assinar |
|
|
|
_send(certificado, 'NfeInutilizacao', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def consultar_protocolo_nfe(certificado, **kwargs): |
|
|
|
_send(certificado, 'NfeConsultaProtocolo', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def nfe_status_servico(certificado, **kwargs): |
|
|
|
_send(certificado, 'NfeStatusServico.', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def consulta_cadastro(certificado, **kwargs): |
|
|
|
_send(certificado, 'NfeConsultaCadastro.', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def recepcao_evento_carta_correcao(certificado, **kwargs): # Assinar |
|
|
|
_send(certificado, 'RecepcaoEventoCarta.', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def recepcao_evento_manifesto(certificado, **kwargs): # Assinar |
|
|
|
_send(certificado, 'RecepcaoEventoManifesto', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def recepcao_evento_epec(certificado, **kwargs): # Assinar |
|
|
|
_send(certificado, 'RecepcaoEventoEPEC', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def consulta_nfe_destinada(certificado, **kwargs): |
|
|
|
_send(certificado, 'NfeConsultaDest', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
def download_nfe(certificado, **kwargs): |
|
|
|
_send(certificado, 'NfeDownloadNF', **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
class NFe(Comunicacao): |
|
|
|
|
|
|
|
def __init__(self, cert, key): |
|
|
|
Comunicacao.__init__(self, cert, key) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def consultar_cadastro(self, cadastro, estado): |
|
|
|
self.url = 'https://cad.sefazrs.rs.gov.br/ws/cadconsultacadastro/cadconsultacadastro2.asmx' |
|
|
|
self.metodo = 'NfeConsultaCadastro' |
|
|
|
|
|
|
|
path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'xml') |
|
|
|
xml = render_xml(path, 'consultar_cadastro.xml', **cadastro) |
|
|
|
|
|
|
|
xml_response, obj = self._executar_consulta(xml) |
|
|
|
|
|
|
|
return { |
|
|
|
'sent_xml': xml, |
|
|
|
'received_xml': xml_response, |
|
|
|
'object': obj.Body.nfeAutorizacaoLoteResult |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def autorizar_nfe(self, nfe, nfe_id): |
|
|
|
self.url = 'https://nfe-homologacao.sefazrs.rs.gov.br/ws/NfeAutorizacao/NFeAutorizacao.asmx' |
|
|
|
self.metodo = 'NfeAutorizacao/nfeAutorizacaoLote' |
|
|
|
|
|
|
|
path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'xml') |
|
|
|
xml = render_xml(path, 'nfeEnv.xml', **nfe) |
|
|
|
|
|
|
|
xmlElem = etree.fromstring(xml) |
|
|
|
xml_signed = sign_xml(xmlElem, self.cert, self.key, '#%s' % nfe_id) |
|
|
|
|
|
|
|
xml_response, obj = self._executar_consulta(xml_signed) |
|
|
|
|
|
|
|
return { |
|
|
|
'sent_xml': xml_signed, |
|
|
|
'received_xml': xml_response, |
|
|
|
'object': obj.Body.nfeAutorizacaoLoteResult |
|
|
|
} |