diff --git a/pytrustnfe/nfse/simpliss/__init__.py b/pytrustnfe/nfse/simpliss/__init__.py index fb5becb..6e88cf6 100644 --- a/pytrustnfe/nfse/simpliss/__init__.py +++ b/pytrustnfe/nfse/simpliss/__init__.py @@ -15,8 +15,17 @@ def _send(certificado, method, **kwargs): path = os.path.join(os.path.dirname(__file__), 'templates') xml_send = render_xml(path, '%s.xml' % method, False, **kwargs) + schema = os.path.join(path, '%s.xsd' % method) - base_url = 'Achar URL' + from lxml import etree + nfe = etree.fromstring(xml_send) + esquema = etree.XMLSchema(etree.parse(schema)) + esquema.validate(nfe) + erros = [x.message for x in esquema.error_log] + + if erros: + raise Exception('\n'.join(erros)) + base_url = 'http://sistemas.pmp.sp.gov.br/semfi/simpliss/ws_nfse/nfseservice.svc?wsdl' cert, key = extract_cert_and_key_from_pfx( certificado.pfx, certificado.password) @@ -44,8 +53,8 @@ def _send(certificado, method, **kwargs): } -def envio_lote_rps(certificado, **kwargs): - return _send(certificado, 'EnvioLoteRps', **kwargs) +def enviar_lote_rps(certificado, **kwargs): + return _send(certificado, 'EnviarLoteRps', **kwargs) def consultar_situacao_lote(certificado, **kwargs): diff --git a/pytrustnfe/nfse/simpliss/templates/CancelarNFSe.xml b/pytrustnfe/nfse/simpliss/templates/CancelarNFSe.xml index ecb5a16..03f1403 100644 --- a/pytrustnfe/nfse/simpliss/templates/CancelarNFSe.xml +++ b/pytrustnfe/nfse/simpliss/templates/CancelarNFSe.xml @@ -1,15 +1,13 @@ - + - + - 58 - - 45111111111100 - - 123498 - 4204608 + {{ cancelar.numero_nfse }} + {{ cancelar.cnpj_prestador }} + {{ cancelar.inscricao_prestador }} + {{ cancelar.codigo_municipio }} - 1 + {{ cancelar.codigo_cancelamento }} diff --git a/pytrustnfe/nfse/simpliss/templates/CancelarNFSe.xsd b/pytrustnfe/nfse/simpliss/templates/CancelarNFSe.xsd new file mode 100644 index 0000000..216031b --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/CancelarNFSe.xsd @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarLote.xml b/pytrustnfe/nfse/simpliss/templates/ConsultarLote.xml index 3861c49..11a3d06 100644 --- a/pytrustnfe/nfse/simpliss/templates/ConsultarLote.xml +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarLote.xml @@ -1,8 +1,6 @@ - + - - 45111111111100 - + {{ consulta.cnpj_prestador }} - 141542179222170 + {{ consulta.protocolo }} diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarLote.xsd b/pytrustnfe/nfse/simpliss/templates/ConsultarLote.xsd new file mode 100644 index 0000000..689c25c --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarLote.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarNFSe.xml b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSe.xml index 3861c49..88e0a2a 100644 --- a/pytrustnfe/nfse/simpliss/templates/ConsultarNFSe.xml +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSe.xml @@ -1,8 +1,6 @@ - + - - 45111111111100 - + {{ consulta.cnpj_prestador }} - 141542179222170 - + {{ consulta.numero_nfse }} + diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarNFSe.xsd b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSe.xsd new file mode 100644 index 0000000..863f878 --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSe.xsd @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarNFSePorRps.xml b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSePorRps.xml index e86e16b..ab6ccd4 100644 --- a/pytrustnfe/nfse/simpliss/templates/ConsultarNFSePorRps.xml +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSePorRps.xml @@ -1,13 +1,11 @@ - + - 24 - A1 - 1 + {{ consulta.numero_rps }} + {{ consulta.serie_rps }} + {{ consulta.tipo_rps }} - - 45111111111100 - - 123498 + {{ consulta.cnpj_prestador }} + {{ consulta.inscricao_prestador }} diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarNFSePorRps.xsd b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSePorRps.xsd new file mode 100644 index 0000000..a51856f --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarNFSePorRps.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLote.xml b/pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLote.xml index 3861c49..befc15f 100644 --- a/pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLote.xml +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLote.xml @@ -1,8 +1,7 @@ - + - - 45111111111100 - + {{ consulta.cnpj_prestador }} + {{ consulta.inscricao_prestador }} - 141542179222170 - + {{ consulta.protocolo }} + diff --git a/pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLote.xsd b/pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLote.xsd new file mode 100644 index 0000000..918270d --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLote.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/pytrustnfe/nfse/simpliss/templates/EnvioLoteRps.xml b/pytrustnfe/nfse/simpliss/templates/EnviarLoteRps.xml similarity index 100% rename from pytrustnfe/nfse/simpliss/templates/EnvioLoteRps.xml rename to pytrustnfe/nfse/simpliss/templates/EnviarLoteRps.xml diff --git a/pytrustnfe/nfse/simpliss/templates/EnviarLoteRps.xsd b/pytrustnfe/nfse/simpliss/templates/EnviarLoteRps.xsd new file mode 100644 index 0000000..07a9647 --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/EnviarLoteRps.xsd @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/pytrustnfe/nfse/simpliss/templates/nfse_3.xsd b/pytrustnfe/nfse/simpliss/templates/nfse_3.xsd new file mode 100644 index 0000000..ff8b52f --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/nfse_3.xsd @@ -0,0 +1,735 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pytrustnfe/nfse/simpliss/templates/xmldsig-core-schema20020212.xsd b/pytrustnfe/nfse/simpliss/templates/xmldsig-core-schema20020212.xsd new file mode 100644 index 0000000..542b160 --- /dev/null +++ b/pytrustnfe/nfse/simpliss/templates/xmldsig-core-schema20020212.xsd @@ -0,0 +1,316 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pytrustnfe/test/test_ginfes.py b/pytrustnfe/test/test_ginfes.py index b58dd1c..bb350f8 100644 --- a/pytrustnfe/test/test_ginfes.py +++ b/pytrustnfe/test/test_ginfes.py @@ -13,8 +13,8 @@ class test_nfse_ginfes(unittest.TestCase): caminho = os.path.dirname(__file__) def test_consulta_situacao_lote(self): - pfx_source = open('/home/danimar/Downloads/machado.pfx', 'r').read() - pfx = Certificado(pfx_source, '123456789') + pfx_source = open('/home/danimar/Downloads/2016.pfx', 'r').read() + pfx = Certificado(pfx_source, '1234') dados = {'ambiente': 'homologacao'} retorno = consultar_situacao_lote( diff --git a/pytrustnfe/test/test_simpliss.py b/pytrustnfe/test/test_simpliss.py index e69de29..a5eb99d 100644 --- a/pytrustnfe/test/test_simpliss.py +++ b/pytrustnfe/test/test_simpliss.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# © 2016 Danimar Ribeiro, Trustcode +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import os.path +import unittest +from pytrustnfe.certificado import Certificado +from pytrustnfe.nfse.simpliss import consultar_situacao_lote +from pytrustnfe.nfse.simpliss import consultar_nfse_por_rps +from pytrustnfe.nfse.simpliss import consultar_lote +from pytrustnfe.nfse.simpliss import consultar_nfse +from pytrustnfe.nfse.simpliss import cancelar_nfse + + +class test_nfse_simpliss(unittest.TestCase): + + caminho = os.path.dirname(__file__) + + def test_consulta_situacao_lote(self): + pfx_source = open('/home/danimar/Downloads/2016.pfx', 'r').read() + pfx = Certificado(pfx_source, '1234') + + dados = {'cnpj_prestador': '12345678910234', 'inscricao_prestador': '123', 'protocolo': '123'} + response = consultar_situacao_lote( + pfx, consulta=dados, ambiente='homologacao') + print response + + def test_consultar_nfse_rps(self): + pfx_source = open('/home/danimar/Downloads/2016.pfx', 'r').read() + pfx = Certificado(pfx_source, '1234') + + dados = {'cnpj_prestador': '01234567896589', 'inscricao_prestador': '123', + 'tipo_rps': '1', 'serie_rps': 'AZ', 'numero_rps': 123} + consultar_nfse_por_rps( + pfx, consulta=dados, ambiente='homologacao') + + def test_consultar_lote(self): + pfx_source = open('/home/danimar/Downloads/2016.pfx', 'r').read() + pfx = Certificado(pfx_source, '1234') + + dados = {'cnpj_prestador': '01234567896589', 'protocolo': '545455451'} + consultar_lote( + pfx, consulta=dados, ambiente='homologacao') + + + def test_consultar_nfse(self): + pfx_source = open('/home/danimar/Downloads/2016.pfx', 'r').read() + pfx = Certificado(pfx_source, '1234') + + dados = {'cnpj_prestador': '01234567896589', 'numero_nfse': '545455451'} + consultar_nfse( + pfx, consulta=dados, ambiente='homologacao') + + def test_cancelar_nfse(self): + pfx_source = open('/home/danimar/Downloads/2016.pfx', 'r').read() + pfx = Certificado(pfx_source, '1234') + + dados = {'cnpj_prestador': '01234567896589', 'numero_nfse': '545455451', + 'inscricao_prestador': 454564, 'codigo_municipio': 1234567, + 'codigo_cancelamento': '1'} + cancelar_nfse( + pfx, cancelar=dados, ambiente='homologacao')