Browse Source

Adicionado arquivos de servicos NFe

tags/0.1.5
Danimar Ribeiro 11 years ago
parent
commit
a403b4b382
  1. 2
      docs/conf.py
  2. 0
      pytrustnfe/servicos/Assinatura.py
  3. 27
      pytrustnfe/servicos/Comunicacao.py
  4. 22
      pytrustnfe/servicos/NFeAutorizacao.py
  5. 22
      pytrustnfe/servicos/NFeDistribuicaoDFe.py
  6. 22
      pytrustnfe/servicos/NFeRetAutorizacao.py
  7. 22
      pytrustnfe/servicos/NfeConsultaCadastro.py
  8. 22
      pytrustnfe/servicos/NfeConsultaProtocolo.py
  9. 22
      pytrustnfe/servicos/NfeInutilizacao.py
  10. 22
      pytrustnfe/servicos/NfeStatusServico.py
  11. 22
      pytrustnfe/servicos/RecepcaoEvento.py
  12. 2
      pytrustnfe/test/test_assinatura.py

2
docs/conf.py

@ -111,7 +111,7 @@ todo_include_todos = False
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'alabaster'
html_theme = 'nature'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the

0
pytrustnfe/servicos/assinatura.py → pytrustnfe/servicos/Assinatura.py

27
pytrustnfe/servicos/Comunicacao.py

@ -14,12 +14,14 @@ from pytrustnfe.Certificado import converte_pfx_pem
from pytrustnfe.Strings import CONSULTA_CADASTRO_COMPLETA
class Comunicacao(object):
url = ''
web_service = ''
def __init__(self, certificado, senha):
self.certificado = certificado
self.senha = senha
self.senha = senha
def _preparar_temp_pem(self):
chave_temp = '/tmp/' + uuid4().hex
certificado_temp = '/tmp/' + uuid4().hex
@ -34,7 +36,24 @@ class Comunicacao(object):
arq_temp.close()
return chave_temp, certificado_temp
def _validar_dados(self):
assert self.url != '', "Url servidor não configurada"
assert self.web_service != '', "Web service não especificado"
assert self.certificado != '', "Certificado não configurado"
assert self.senha != '', "Senha não configurada"
def _executar_consulta(self, xmlEnviar):
self._validar_dados()
chave, certificado = self._preparar_temp_pem()
client = HttpClient(self.url, chave, certificado)
xml_retorno = client.post_xml(self.web_service, xmlEnviar)
obj = objectify.fromstring(xml_retorno)
return xml_retorno, obj
def consulta_cadastro(self, obj_consulta):
chave, certificado = self._preparar_temp_pem()

22
pytrustnfe/servicos/NFeAutorizacao.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class NfeAutorizacao(Comunicacao):
def autorizar_nfe(self, nfe, sincrono=True):
xml = None
if isinstance(nfe, DynamicXml):
xml = nfe.render()
if isinstance(nfe, basestring):
xml = nfe
assert xml is not None, "Objeto nfe deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

22
pytrustnfe/servicos/NFeDistribuicaoDFe.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class NfeDistribuicaoDFe(Comunicacao):
def distribuicao(self, dfe):
xml = None
if isinstance(dfe, DynamicXml):
xml = dfe.render()
if isinstance(dfe, basestring):
xml = dfe
assert xml is not None, "Objeto recibo deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

22
pytrustnfe/servicos/NFeRetAutorizacao.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class NfeRetAutorizacao(Comunicacao):
def consulta_autorizacao(self, recibo):
xml = None
if isinstance(recibo, DynamicXml):
xml = recibo.render()
if isinstance(recibo, basestring):
xml = recibo
assert xml is not None, "Objeto recibo deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

22
pytrustnfe/servicos/NfeConsultaCadastro.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class NfeConsultaCadastro(Comunicacao):
def consultar_cadastro(self, cadastro):
xml = None
if isinstance(cadastro, DynamicXml):
xml = cadastro.render()
if isinstance(cadastro, basestring):
xml = cadastro
assert xml is not None, "Objeto cadastro deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

22
pytrustnfe/servicos/NfeConsultaProtocolo.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class NfeConsultaProtocolo(Comunicacao):
def consultar_protocolo(self, recibo):
xml = None
if isinstance(recibo, DynamicXml):
xml = recibo.render()
if isinstance(recibo, basestring):
xml = recibo
assert xml is not None, "Objeto recibo deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

22
pytrustnfe/servicos/NfeInutilizacao.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class NfeInutilizacao(Comunicacao):
def inutilizar(self, inutilizacao):
xml = None
if isinstance(inutilizacao, DynamicXml):
xml = inutilizacao.render()
if isinstance(inutilizacao, basestring):
xml = inutilizacao
assert xml is not None, "Objeto inutilização deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

22
pytrustnfe/servicos/NfeStatusServico.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class NfeStatusServico(Comunicacao):
def status(self, consulta):
xml = None
if isinstance(consulta, DynamicXml):
xml = consulta.render()
if isinstance(consulta, basestring):
xml = consulta
assert xml is not None, "Objeto consulta deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

22
pytrustnfe/servicos/RecepcaoEvento.py

@ -0,0 +1,22 @@
#coding=utf-8
'''
Created on 21/06/2015
@author: danimar
'''
from pytrustnfe.servicos.Comunicacao import Comunicacao
from pytrustnfe.xml import DynamicXml
class RecepcaoEvento(Comunicacao):
def registrar_evento(self, evento):
xml = None
if isinstance(evento, DynamicXml):
xml = evento.render()
if isinstance(evento, basestring):
xml = evento
assert xml is not None, "Objeto recibo deve ser do tipo DynamicXml ou string"
return self._executar_consulta(xml)

2
pytrustnfe/test/test_assinatura.py

@ -6,7 +6,7 @@ Created on Jun 14, 2015
'''
import unittest
import os, os.path
from pytrustnfe.servicos.assinatura import Assinatura
from pytrustnfe.servicos.Assinatura import Assinatura
XML_ASSINAR = '<?xml version="1.0" encoding="UTF-8"?>' \
'<!DOCTYPE Envelope [ ' \

Loading…
Cancel
Save