diff --git a/pynfe/processamento/assinatura.py b/pynfe/processamento/assinatura.py index e19177a..76888f4 100644 --- a/pynfe/processamento/assinatura.py +++ b/pynfe/processamento/assinatura.py @@ -265,8 +265,19 @@ class AssinaturaA1(Assinatura): raise e def assinarConsultaLote(self, xml, retorna_string=True): + tag = 'ns1:ConsultarLoteRpsEnvio' + return self._assinar(xml, tag, retorna_string) + + def assinarConsultaRps(self, xml, retorna_string=True): + tag = 'ns1:ConsultarNfseRpsEnvio' + return self._assinar(xml, tag, retorna_string) + + def _assinar(self, xml, tag, retorna_string=True): + """ Método para assinar xml de NFS-e com tags sem ID + Consulta de Lote e Consulta por RPS + @param tag - raiz do xml que será assinado + """ try: - tag = 'ns1:ConsultarLoteRpsEnvio' xml = etree.fromstring(xml) # No raiz do XML de saida raiz = etree.Element('Signature', xmlns='http://www.w3.org/2000/09/xmldsig#') diff --git a/pynfe/processamento/autorizador_nfse.py b/pynfe/processamento/autorizador_nfse.py index 3465e72..2ac5c6b 100644 --- a/pynfe/processamento/autorizador_nfse.py +++ b/pynfe/processamento/autorizador_nfse.py @@ -1,5 +1,6 @@ from pyxb import BIND from importlib import import_module +from decimal import Decimal, ROUND_HALF_UP class InterfaceAutorizador(): @@ -245,6 +246,7 @@ class SerializacaoGinfes(InterfaceAutorizador): global servico_cancelar_nfse_envio_v03 global servico_consultar_lote_rps_envio_v03 global servico_consultar_situacao_lote_rps_envio_v03 + global servico_consultar_nfse_rps_envio_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') servico_cancelar_nfse_envio_v03 = import_module('pynfe.utils.nfse.ginfes.servico_cancelar_nfse_envio_v03') @@ -252,29 +254,29 @@ class SerializacaoGinfes(InterfaceAutorizador): cabecalho_v03 = import_module('pynfe.utils.nfse.ginfes.cabecalho_v03') servico_consultar_lote_rps_envio_v03 = import_module('pynfe.utils.nfse.ginfes.servico_consultar_lote_rps_envio_v03') servico_consultar_situacao_lote_rps_envio_v03 = import_module('pynfe.utils.nfse.ginfes.servico_consultar_situacao_lote_rps_envio_v03') + servico_consultar_nfse_rps_envio_v03 = import_module('pynfe.utils.nfse.ginfes.servico_consultar_nfse_rps_envio_v03') - def consultar_rps(self, nfse): - """Retorna string de um XML de consulta por Rps gerado a partir do - XML Schema (XSD). Binding gerado pelo modulo PyXB.""" - + def consultar_rps(self, emitente, numero, serie, tipo): + """ Retorna string de um XML de consulta por Rps gerado a partir do + XML Schema (XSD). Binding gerado pelo modulo PyXB. + servico_consultar_nfse_rps_envio_v03.xsd + """ # Rps id_rps = _tipos.tcIdentificacaoRps() - id_rps.Numero = nfse.identificador - id_rps.Serie = nfse.serie - id_rps.Tipo = nfse.tipo + id_rps.Numero = numero + id_rps.Serie = serie + id_rps.Tipo = tipo # Prestador id_prestador = _tipos.tcIdentificacaoPrestador() - id_prestador.CpfCnpj = nfse.emitente.cnpj - id_prestador.InscricaoMunicipal = nfse.emitente.inscricao_municipal + id_prestador.Cnpj = emitente.cnpj + id_prestador.InscricaoMunicipal = emitente.inscricao_municipal consulta = servico_consultar_nfse_rps_envio_v03.ConsultarNfseRpsEnvio() consulta.IdentificacaoRps = id_rps consulta.Prestador = id_prestador - consulta = consulta.toxml(element_name='ns1:ConsultarNfseRpsEnvio') - - return consulta + return consulta.toxml(element_name='ns1:ConsultarNfseRpsEnvio') def consultar_nfse(self, emitente, numero=None, inicio=None, fim=None): # Prestador @@ -308,6 +310,7 @@ class SerializacaoGinfes(InterfaceAutorizador): return consulta.toxml(element_name='ns1:ConsultarLoteRpsEnvio') def consultar_situacao_lote(self, emitente, numero): + "Serializa lote de envio, baseado no servico_consultar_situacao_lote_rps_envio_v03.xsd" # Prestador id_prestador = _tipos.tcIdentificacaoPrestador() id_prestador.Cnpj = emitente.cnpj @@ -317,7 +320,7 @@ class SerializacaoGinfes(InterfaceAutorizador): consulta.Prestador = id_prestador consulta.Protocolo = str(numero) - return consulta.toxml(element_name='ns1:ConsultarSituacaoLoteRps') + return consulta.toxml(element_name='ns1:ConsultarSituacaoLoteRpsEnvio') def serializar_lote_assincrono(self, nfse): "Serializa lote de envio, baseado no servico_enviar_lote_rps_envio_v03.xsd" @@ -325,6 +328,7 @@ class SerializacaoGinfes(InterfaceAutorizador): servico = _tipos.tcDadosServico() valores_servico = _tipos.tcValores() valores_servico.ValorServicos = nfse.servico.valor_servico + #valores_servico.ValorServicos = str(Decimal(nfse.servico.valor_servico.quantize(Decimal('.01'), rounding=ROUND_HALF_UP))) valores_servico.IssRetido = nfse.servico.iss_retido # Dados opcionais if nfse.servico.valor_deducoes: diff --git a/pynfe/processamento/comunicacao.py b/pynfe/processamento/comunicacao.py index 35817ba..eb60913 100644 --- a/pynfe/processamento/comunicacao.py +++ b/pynfe/processamento/comunicacao.py @@ -438,8 +438,11 @@ class ComunicacaoNfse(Comunicacao): if self.autorizador == 'BETHA': # comunica via wsdl return self._post(url, xml, 'consultaRps') + elif self.autorizador == 'GINFES': + return self._post_https(url, xml, 'consultaRps') + # TODO outros autorizadres else: - raise Exception('Este método só esta implementado no autorizador betha.') + raise Exception('Autorizador não encontrado!') def consultar_faixa(self, xml): # url do serviço diff --git a/pynfe/processamento/serializacao.py b/pynfe/processamento/serializacao.py index a4c1313..c077cb4 100644 --- a/pynfe/processamento/serializacao.py +++ b/pynfe/processamento/serializacao.py @@ -627,6 +627,13 @@ class SerializacaoNfse(object): else: raise Exception('Este método só esta implementado no autorizador ginfes.') + def consultar_rps(self, emitente, numero, serie, tipo): + if self.autorizador.lower() == 'ginfes': + from pynfe.processamento.autorizador_nfse import SerializacaoGinfes + return SerializacaoGinfes().consultar_rps(emitente, numero, serie, tipo) + else: + raise Exception('Este método só esta implementado no autorizador ginfes.') + def consultar_situacao_lote(self, emitente, numero): if self.autorizador.lower() == 'ginfes': from pynfe.processamento.autorizador_nfse import SerializacaoGinfes diff --git a/pynfe/utils/nfse/ginfes/servico_consultar_nfse_rps_envio_v03.py b/pynfe/utils/nfse/ginfes/servico_consultar_nfse_rps_envio_v03.py index 819cfcd..5bfb4f9 100644 --- a/pynfe/utils/nfse/ginfes/servico_consultar_nfse_rps_envio_v03.py +++ b/pynfe/utils/nfse/ginfes/servico_consultar_nfse_rps_envio_v03.py @@ -24,8 +24,8 @@ if pyxb.__version__ != _PyXBVersion: raise pyxb.PyXBVersionError(_PyXBVersion) # Import bindings for namespaces imported into schema -import _tipos as _ImportedBinding__tipos -import _dsig as _ImportedBinding__dsig +from pynfe.utils.nfse.ginfes import _tipos as _ImportedBinding__tipos +from pynfe.utils.nfse.ginfes import _dsig as _ImportedBinding__dsig import pyxb.binding.datatypes # NOTE: All namespace declarations are reserved within the binding