Browse Source

Correção de importação do pxb cabecalho ginfes

pull/7/head
Junior Tada 10 years ago
parent
commit
112bd464a0
  1. 4
      pynfe/processamento/assinatura.py
  2. 10
      pynfe/processamento/autorizador_nfse.py
  3. 35
      pynfe/processamento/comunicacao.py
  4. 2
      pynfe/utils/nfse/ginfes/cabecalho_v03.py

4
pynfe/processamento/assinatura.py

@ -171,7 +171,7 @@ class AssinaturaA1(Assinatura):
# Escreve no arquivo depois de remover caracteres especiais e parse string
with open('nfse.xml', 'w') as arquivo:
arquivo.write(remover_acentos(etree.tostring(xml, encoding="unicode", pretty_print=False).replace('ns1:', '').replace(':ns1', '')))
arquivo.write(remover_acentos(etree.tostring(xml, encoding="unicode", pretty_print=False).replace('ns1:', '').replace(':ns1', '').replace('\n','')))
subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', tag, 'nfse.xml'])
xml = etree.parse('funfa.xml').getroot()
@ -209,7 +209,7 @@ class AssinaturaA1(Assinatura):
# Escreve no arquivo depois de remover caracteres especiais e parse string
with open('nfse.xml', 'w') as arquivo:
arquivo.write(remover_acentos(etree.tostring(xml, encoding="unicode", pretty_print=False)))
arquivo.write(remover_acentos(etree.tostring(xml, encoding="unicode", pretty_print=False).replace('\n','')))
subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', tag, 'nfse.xml'])
xml = etree.parse('funfa.xml').getroot()

10
pynfe/processamento/autorizador_nfse.py

@ -243,9 +243,10 @@ class SerializacaoBetha(InterfaceAutorizador):
class SerializacaoGinfes(InterfaceAutorizador):
def __init__(self):
# importa
global _tipos, servico_consultar_nfse_envio_v03
global _tipos, servico_consultar_nfse_envio_v03, cabecalho_v03
_tipos = import_module('pynfe.utils.nfse.ginfes._tipos')
servico_consultar_nfse_envio_v03 = import_module('pynfe.utils.nfse.ginfes.servico_consultar_nfse_envio_v03')
cabecalho_v03 = import_module('pynfe.utils.nfse.ginfes.cabecalho_v03')
def consultar_rps(self, nfse):
"""Retorna string de um XML de consulta por Rps gerado a partir do
@ -288,3 +289,10 @@ class SerializacaoGinfes(InterfaceAutorizador):
consulta.PeriodoEmissao.DataFinal = fim
return consulta.toxml(element_name='ConsultarNfseEnvio')
def cabecalho(self):
# info
cabecalho = cabecalho_v03.cabecalho()
cabecalho.versao = '3'
cabecalho.versaoDados = '3'
return cabecalho.toxml(element_name='cabecalho')

35
pynfe/processamento/comunicacao.py

@ -197,6 +197,23 @@ class ComunicacaoSefaz(Comunicacao):
# Chama método que efetua a requisição POST no servidor SOAP
return self._post(url, xml)
def download(self, cnpj, chave):
# url do serviço
url = self._get_url_AN(consulta='DOWNLOAD')
# Monta XML do corpo da requisição
raiz = etree.Element('downloadNFe', versao='1.00', xmlns=NAMESPACE_NFE)
etree.SubElement(raiz, 'versao').text = '1.00'
etree.SubElement(raiz, 'tpAmb').text = str(self._ambiente)
etree.SubElement(raiz, 'xServ').text = 'DOWNLOAD NFE'
etree.SubElement(raiz, 'CNPJ').text = str(cnpj)
etree.SubElement(raiz, 'chNFe').text = str(chave)
# Monta XML para envio da requisição
xml = self._construir_xml_status_pr(cabecalho=self._cabecalho_soap(metodo='NfeDownloadNF'), metodo='NfeDownloadNF', dados=raiz)
print (url)
#return xml
return self._post(url, xml)
def inutilizar_faixa_numeracao(self, numero_inicial, numero_final, emitente, certificado, senha, ano=None, serie='1', justificativa=''):
post = '/nfeweb/services/nfestatusservico.asmx'
metodo = 'NfeInutilizacao2'
@ -303,6 +320,8 @@ class ComunicacaoSefaz(Comunicacao):
etree.SubElement(raiz, 'versaoDados').text = '1.00'
elif metodo == 'NfeConsultaDest':
etree.SubElement(raiz, 'versaoDados').text = '1.01'
elif metodo == 'NfeDownloadNF':
etree.SubElement(raiz, 'versaoDados').text = '1.00'
else:
etree.SubElement(raiz, 'versaoDados').text = VERSAO_PADRAO
etree.SubElement(raiz, 'cUF').text = CODIGOS_ESTADOS[self.uf.upper()]
@ -381,10 +400,12 @@ class ComunicacaoNfse(Comunicacao):
def consulta(self, autorizador, xml):
if autorizador.upper() == 'GINFES':
self._namespace = 'http://www.ginfes.com.br/servico_consultar_nfse_envio_v03.xsd'
self._versao = '3.00'
self._namespace = 'http://www.ginfes.com.br/cabecalho_v03.xsd'
self._versao = '3'
# url do serviço
url = self._get_url(autorizador)
# xml
xml = '<?xml version="1.0" encoding="UTF-8"?>' + xml
# comunica via wsdl
return self._post_https(url, xml, 'consulta')
@ -420,7 +441,7 @@ class ComunicacaoNfse(Comunicacao):
def _cabecalho(self, retorna_string=True):
u"""Monta o XML do cabeçalho da requisição wsdl"""
xml_declaration='<?xml version="1.0" encoding="UTF-8"?>'
xml_declaration='<?xml version="1.0" encoding="utf-8"?>'
# cabecalho
raiz = etree.Element('cabecalho', xmlns=self._namespace, versao=self._versao)
@ -433,6 +454,11 @@ class ComunicacaoNfse(Comunicacao):
else:
return raiz
def _cabecalho_ginfes(self):
""" Retorna o XML do cabeçalho gerado pelo xsd"""
from pynfe.processamento.autorizador_nfse import SerializacaoGinfes
return SerializacaoGinfes().cabecalho()
def _get_url(self, autorizador):
""" Retorna a url para comunicação com o webservice """
if self._ambiente == 1:
@ -469,7 +495,8 @@ class ComunicacaoNfse(Comunicacao):
def _post_https(self, url, xml, metodo):
# cabecalho
cabecalho = self._cabecalho()
#cabecalho = self._cabecalho()
cabecalho = self._cabecalho_ginfes()
# comunicacao wsdl
try:
from suds.client import Client

2
pynfe/utils/nfse/ginfes/cabecalho_v03.py

@ -24,7 +24,7 @@ if pyxb.__version__ != _PyXBVersion:
raise pyxb.PyXBVersionError(_PyXBVersion)
# Import bindings for namespaces imported into schema
import _tipos as _ImportedBinding__tipos
from pynfe.utils.nfse.ginfes import _tipos as _ImportedBinding__tipos
import pyxb.binding.datatypes
# NOTE: All namespace declarations are reserved within the binding

Loading…
Cancel
Save