From d2a0c26b1a7162cc75d01d07ef8a259ef69f7c00 Mon Sep 17 00:00:00 2001 From: Felipe Date: Fri, 22 Dec 2017 11:09:17 -0200 Subject: [PATCH] =?UTF-8?q?mudan=C3=A7a=20nfse=20campinas=20para=20dsf,=20?= =?UTF-8?q?adicionadas=20outras=20cidades=20tamb=C3=A9m=20emitidas=20pela?= =?UTF-8?q?=20dsf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytrustnfe/nfse/campinas/__init__.py | 103 -------------------- pytrustnfe/nfse/campinas/templates/cancelar.xml | 18 ---- .../nfse/campinas/templates/consulta_notas.xml | 11 --- .../nfse/campinas/templates/consultarLote.xml | 10 -- pytrustnfe/nfse/campinas/templates/enviar.xml | 108 --------------------- pytrustnfe/nfse/campinas/templates/soap_header.xml | 12 --- pytrustnfe/nfse/dsf/__init__.py | 103 ++++++++++++++++++++ pytrustnfe/nfse/dsf/templates/cancelar.xml | 18 ++++ pytrustnfe/nfse/dsf/templates/consulta_notas.xml | 11 +++ pytrustnfe/nfse/dsf/templates/consultarLote.xml | 10 ++ pytrustnfe/nfse/dsf/templates/enviar.xml | 108 +++++++++++++++++++++ pytrustnfe/nfse/dsf/templates/soap_header.xml | 12 +++ setup.py | 2 +- 13 files changed, 263 insertions(+), 263 deletions(-) delete mode 100644 pytrustnfe/nfse/campinas/__init__.py delete mode 100644 pytrustnfe/nfse/campinas/templates/cancelar.xml delete mode 100644 pytrustnfe/nfse/campinas/templates/consulta_notas.xml delete mode 100644 pytrustnfe/nfse/campinas/templates/consultarLote.xml delete mode 100644 pytrustnfe/nfse/campinas/templates/enviar.xml delete mode 100644 pytrustnfe/nfse/campinas/templates/soap_header.xml create mode 100644 pytrustnfe/nfse/dsf/__init__.py create mode 100644 pytrustnfe/nfse/dsf/templates/cancelar.xml create mode 100644 pytrustnfe/nfse/dsf/templates/consulta_notas.xml create mode 100644 pytrustnfe/nfse/dsf/templates/consultarLote.xml create mode 100644 pytrustnfe/nfse/dsf/templates/enviar.xml create mode 100644 pytrustnfe/nfse/dsf/templates/soap_header.xml diff --git a/pytrustnfe/nfse/campinas/__init__.py b/pytrustnfe/nfse/campinas/__init__.py deleted file mode 100644 index 80d839d..0000000 --- a/pytrustnfe/nfse/campinas/__init__.py +++ /dev/null @@ -1,103 +0,0 @@ -# -*- encoding: utf-8 -*- -# © 2017 Fábio Luna, Trustcode -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -import os -import suds -from lxml import etree -from pytrustnfe.xml import render_xml, sanitize_response -from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key -from pytrustnfe.nfse.assinatura import Assinatura -from pytrustnfe.client import get_client - - -def _render(certificado, method, **kwargs): - path = os.path.join(os.path.dirname(__file__), 'templates') - if method == "testeEnviar": - xml_send = render_xml(path, 'enviar.xml', True, **kwargs) - else: - xml_send = render_xml(path, '%s.xml' % method, False, **kwargs) - - if type(xml_send) != str: - xml_send = etree.tostring(xml_send) - - return xml_send - - -def _get_url(**kwargs): - - try: - cod_cidade = kwargs['CodCidade'] - except (KeyError, TypeError): - return '' - - urls = { - # Belém - PA - '2715': 'http://www.issdigitalbel.com.br/WsNFe2/LoteRps.jws', - # Sorocaba - SP - '5363': 'http://issdigital.sorocaba.sp.gov.br/WsNFe2/LoteRps.jws', - # Teresina - PI - '3182': 'http://www.issdigitalthe.com.br/WsNFe2/LoteRps.jws', - # Campinas - SP - '4888': 'http://issdigital.campinas.sp.gov.br/WsNFe2/LoteRps.jws?wsdl', - # Uberlandia - MG - '2170': 'http://udigital.uberlandia.mg.gov.br/WsNFe2/LoteRps.jws', - # São Luis - MA - '1314': 'https://stm.semfaz.saoluis.ma.gov.br/WsNFe2/LoteRps?wsdl', - # Campo Grande - MS - '2218': 'http://issdigital.pmcg.ms.gov.br/WsNFe2/LoteRps.jws', - } - - return urls[str(cod_cidade)] - - -def _send(certificado, method, **kwargs): - url = _get_url(**kwargs) - - path = os.path.join(os.path.dirname(__file__), 'templates') - - xml_send = _render(path, method, **kwargs) - client = get_client(url) - - if certificado: - cert, key = extract_cert_and_key_from_pfx( - certificado.pfx, certificado.password) - cert, key = save_cert_key(cert, key) - signer = Assinatura(cert, key, certificado.password) - xml_send = signer.assina_xml(xml_send, '') - - try: - response = getattr(client.service, method)(xml_send) - response, obj = sanitize_response(response.encode()) - except suds.WebFault as e: - return { - 'sent_xml': xml_send, - 'received_xml': e.fault.faultstring, - 'object': None - } - - return { - 'sent_xml': xml_send, - 'received_xml': response, - 'object': obj - } - - -def enviar(certificado, **kwargs): - return _send(certificado, 'enviar', **kwargs) - - -def teste_enviar(certificado, **kwargs): - return _send(certificado, 'testeEnviar', **kwargs) - - -def cancelar(certificado, ** kwargs): - return _send(certificado, 'cancelar', **kwargs) - - -def consulta_lote(**kwargs): - return _send(False, 'consultarLote', **kwargs) - - -def consultar_lote_rps(certificado, **kwarg): - return _send(certificado, 'consultarNFSeRps', **kwarg) diff --git a/pytrustnfe/nfse/campinas/templates/cancelar.xml b/pytrustnfe/nfse/campinas/templates/cancelar.xml deleted file mode 100644 index d72086b..0000000 --- a/pytrustnfe/nfse/campinas/templates/cancelar.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - {{ cancelamento.cidade }} - {{ cancelamento.cpf_cnpj }} - true - 1 - - - - {{ cancelamento.inscricao_municipal }} - {{ cancelamento.nota_id }} - {{ cancelamento.assinatura }} - {{ cancelamento.motivo }} - - - diff --git a/pytrustnfe/nfse/campinas/templates/consulta_notas.xml b/pytrustnfe/nfse/campinas/templates/consulta_notas.xml deleted file mode 100644 index 4a666d0..0000000 --- a/pytrustnfe/nfse/campinas/templates/consulta_notas.xml +++ /dev/null @@ -1,11 +0,0 @@ - - -{{ consulta.cidade }} -{{ consulta.cpf_cnpj }} -{{ consulta.inscricao_municipal }} -{{ consulta.data_inicio }} -{{ consulta.data_final }} -{{ consulta.nota_inicial }} -1 - - \ No newline at end of file diff --git a/pytrustnfe/nfse/campinas/templates/consultarLote.xml b/pytrustnfe/nfse/campinas/templates/consultarLote.xml deleted file mode 100644 index 24afc5d..0000000 --- a/pytrustnfe/nfse/campinas/templates/consultarLote.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - {{ consulta.cidade }} - {{ consulta.cpf_cnpj }} - 1 - {{ consulta.lote }} - - \ No newline at end of file diff --git a/pytrustnfe/nfse/campinas/templates/enviar.xml b/pytrustnfe/nfse/campinas/templates/enviar.xml deleted file mode 100644 index 7e4b178..0000000 --- a/pytrustnfe/nfse/campinas/templates/enviar.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - {{ nfse.cidade }} - {{ nfse.cpf_cnpj }} - {{ nfse.remetente }} - {{ nfse.transacao }} - {{ nfse.data_inicio|format_date }} - {{ nfse.data_fim|format_date }} - {{ nfse.total_rps }} - {{ nfse.total_servicos }} - {{ nfse.total_deducoes }} - 1 - WS - - - {% for rps in nfse.lista_rps -%} - - {{ rps.assinatura }} - {{ rps.prestador.inscricao_municipal }} - - {{ rps.prestador.razao_social }} - RPS - {{ rps.serie }} - {{ rps.numero }} - {{ rps.data_emissao|format_datetime }} - - {{ rps.situacao }} - - 0 - 0 - 1900-01-01 - {{ rps.serie_prestacao }} - {{ rps.tomador.inscricao_municipal }} - {{ rps.tomador.cpf_cnpj }} - {{ rps.tomador.razao_social }} - - {{ rps.tomador.tipo_logradouro }} - - {{ rps.tomador.logradouro }} - {{ rps.tomador.numero }} - - {{ rps.tomador.tipo_bairro }} - {{ rps.tomador.bairro }} - {{ rps.tomador.cidade }} - {{ rps.tomador.cidade_descricao }} - - {{ rps.tomador.cep }} - {{ rps.tomador.email }} - {{ rps.codigo_atividade }} - {{ rps.aliquota_atividade }} - {{ rps.tipo_recolhimento }} - {{ rps.municipio_prestacao }} - - {{ rps.municipio_descricao_prestacao }} - - {{ rps.operacao }} - {{ rps.tributacao }} - {{ rps.valor_pis }} - {{ rps.valor_cofins }} - {{ rps.valor_inss }} - {{ rps.valor_ir }} - {{ rps.valor_csll }} - {{ rps.aliquota_pis }} - {{ rps.aliquota_cofins }} - {{ rps.aliquota_inss }} - {{ rps.aliquota_ir }} - {{ rps.aliquota_csll }} - {{ rps.descricao }} - {{ rps.prestador.ddd }} - {{ rps.prestador.telefone }} - {{ rps.tomador.ddd }} - {{ rps.tomador.telefone }} - {{ rps.motivo_cancelamento }} - {% if rps.deducoes|count > 0 %} - - {% for deducao in rps.deducoes -%} - - {{ deducao.por }} - {{ deducao.tipo }} - {{ deducao.cnpj_referencia }} - {{ deducao.nf_referencia }} - {{ deducao.valor_referencia }} - {{ deducao.percentual_deduzir }} - {{ deducao.valor_deduzir }} - - {% endfor %} - - {% endif %} - {% if rps.deducoes|count == 0 %} - - {% endif %} - - {% for item in rps.itens -%} - - {{ item.descricao }} - {{ item.quantidade }} - {{ item.valor_unitario }} - {{ item.valor_total }} - S - - {% endfor %} - - - {% endfor %} - - diff --git a/pytrustnfe/nfse/campinas/templates/soap_header.xml b/pytrustnfe/nfse/campinas/templates/soap_header.xml deleted file mode 100644 index e9d1dd2..0000000 --- a/pytrustnfe/nfse/campinas/templates/soap_header.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/pytrustnfe/nfse/dsf/__init__.py b/pytrustnfe/nfse/dsf/__init__.py new file mode 100644 index 0000000..80d839d --- /dev/null +++ b/pytrustnfe/nfse/dsf/__init__.py @@ -0,0 +1,103 @@ +# -*- encoding: utf-8 -*- +# © 2017 Fábio Luna, Trustcode +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import os +import suds +from lxml import etree +from pytrustnfe.xml import render_xml, sanitize_response +from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key +from pytrustnfe.nfse.assinatura import Assinatura +from pytrustnfe.client import get_client + + +def _render(certificado, method, **kwargs): + path = os.path.join(os.path.dirname(__file__), 'templates') + if method == "testeEnviar": + xml_send = render_xml(path, 'enviar.xml', True, **kwargs) + else: + xml_send = render_xml(path, '%s.xml' % method, False, **kwargs) + + if type(xml_send) != str: + xml_send = etree.tostring(xml_send) + + return xml_send + + +def _get_url(**kwargs): + + try: + cod_cidade = kwargs['CodCidade'] + except (KeyError, TypeError): + return '' + + urls = { + # Belém - PA + '2715': 'http://www.issdigitalbel.com.br/WsNFe2/LoteRps.jws', + # Sorocaba - SP + '5363': 'http://issdigital.sorocaba.sp.gov.br/WsNFe2/LoteRps.jws', + # Teresina - PI + '3182': 'http://www.issdigitalthe.com.br/WsNFe2/LoteRps.jws', + # Campinas - SP + '4888': 'http://issdigital.campinas.sp.gov.br/WsNFe2/LoteRps.jws?wsdl', + # Uberlandia - MG + '2170': 'http://udigital.uberlandia.mg.gov.br/WsNFe2/LoteRps.jws', + # São Luis - MA + '1314': 'https://stm.semfaz.saoluis.ma.gov.br/WsNFe2/LoteRps?wsdl', + # Campo Grande - MS + '2218': 'http://issdigital.pmcg.ms.gov.br/WsNFe2/LoteRps.jws', + } + + return urls[str(cod_cidade)] + + +def _send(certificado, method, **kwargs): + url = _get_url(**kwargs) + + path = os.path.join(os.path.dirname(__file__), 'templates') + + xml_send = _render(path, method, **kwargs) + client = get_client(url) + + if certificado: + cert, key = extract_cert_and_key_from_pfx( + certificado.pfx, certificado.password) + cert, key = save_cert_key(cert, key) + signer = Assinatura(cert, key, certificado.password) + xml_send = signer.assina_xml(xml_send, '') + + try: + response = getattr(client.service, method)(xml_send) + response, obj = sanitize_response(response.encode()) + except suds.WebFault as e: + return { + 'sent_xml': xml_send, + 'received_xml': e.fault.faultstring, + 'object': None + } + + return { + 'sent_xml': xml_send, + 'received_xml': response, + 'object': obj + } + + +def enviar(certificado, **kwargs): + return _send(certificado, 'enviar', **kwargs) + + +def teste_enviar(certificado, **kwargs): + return _send(certificado, 'testeEnviar', **kwargs) + + +def cancelar(certificado, ** kwargs): + return _send(certificado, 'cancelar', **kwargs) + + +def consulta_lote(**kwargs): + return _send(False, 'consultarLote', **kwargs) + + +def consultar_lote_rps(certificado, **kwarg): + return _send(certificado, 'consultarNFSeRps', **kwarg) diff --git a/pytrustnfe/nfse/dsf/templates/cancelar.xml b/pytrustnfe/nfse/dsf/templates/cancelar.xml new file mode 100644 index 0000000..d72086b --- /dev/null +++ b/pytrustnfe/nfse/dsf/templates/cancelar.xml @@ -0,0 +1,18 @@ + + + {{ cancelamento.cidade }} + {{ cancelamento.cpf_cnpj }} + true + 1 + + + + {{ cancelamento.inscricao_municipal }} + {{ cancelamento.nota_id }} + {{ cancelamento.assinatura }} + {{ cancelamento.motivo }} + + + diff --git a/pytrustnfe/nfse/dsf/templates/consulta_notas.xml b/pytrustnfe/nfse/dsf/templates/consulta_notas.xml new file mode 100644 index 0000000..4a666d0 --- /dev/null +++ b/pytrustnfe/nfse/dsf/templates/consulta_notas.xml @@ -0,0 +1,11 @@ + + +{{ consulta.cidade }} +{{ consulta.cpf_cnpj }} +{{ consulta.inscricao_municipal }} +{{ consulta.data_inicio }} +{{ consulta.data_final }} +{{ consulta.nota_inicial }} +1 + + \ No newline at end of file diff --git a/pytrustnfe/nfse/dsf/templates/consultarLote.xml b/pytrustnfe/nfse/dsf/templates/consultarLote.xml new file mode 100644 index 0000000..24afc5d --- /dev/null +++ b/pytrustnfe/nfse/dsf/templates/consultarLote.xml @@ -0,0 +1,10 @@ + + + {{ consulta.cidade }} + {{ consulta.cpf_cnpj }} + 1 + {{ consulta.lote }} + + \ No newline at end of file diff --git a/pytrustnfe/nfse/dsf/templates/enviar.xml b/pytrustnfe/nfse/dsf/templates/enviar.xml new file mode 100644 index 0000000..7e4b178 --- /dev/null +++ b/pytrustnfe/nfse/dsf/templates/enviar.xml @@ -0,0 +1,108 @@ + + + {{ nfse.cidade }} + {{ nfse.cpf_cnpj }} + {{ nfse.remetente }} + {{ nfse.transacao }} + {{ nfse.data_inicio|format_date }} + {{ nfse.data_fim|format_date }} + {{ nfse.total_rps }} + {{ nfse.total_servicos }} + {{ nfse.total_deducoes }} + 1 + WS + + + {% for rps in nfse.lista_rps -%} + + {{ rps.assinatura }} + {{ rps.prestador.inscricao_municipal }} + + {{ rps.prestador.razao_social }} + RPS + {{ rps.serie }} + {{ rps.numero }} + {{ rps.data_emissao|format_datetime }} + + {{ rps.situacao }} + + 0 + 0 + 1900-01-01 + {{ rps.serie_prestacao }} + {{ rps.tomador.inscricao_municipal }} + {{ rps.tomador.cpf_cnpj }} + {{ rps.tomador.razao_social }} + + {{ rps.tomador.tipo_logradouro }} + + {{ rps.tomador.logradouro }} + {{ rps.tomador.numero }} + + {{ rps.tomador.tipo_bairro }} + {{ rps.tomador.bairro }} + {{ rps.tomador.cidade }} + {{ rps.tomador.cidade_descricao }} + + {{ rps.tomador.cep }} + {{ rps.tomador.email }} + {{ rps.codigo_atividade }} + {{ rps.aliquota_atividade }} + {{ rps.tipo_recolhimento }} + {{ rps.municipio_prestacao }} + + {{ rps.municipio_descricao_prestacao }} + + {{ rps.operacao }} + {{ rps.tributacao }} + {{ rps.valor_pis }} + {{ rps.valor_cofins }} + {{ rps.valor_inss }} + {{ rps.valor_ir }} + {{ rps.valor_csll }} + {{ rps.aliquota_pis }} + {{ rps.aliquota_cofins }} + {{ rps.aliquota_inss }} + {{ rps.aliquota_ir }} + {{ rps.aliquota_csll }} + {{ rps.descricao }} + {{ rps.prestador.ddd }} + {{ rps.prestador.telefone }} + {{ rps.tomador.ddd }} + {{ rps.tomador.telefone }} + {{ rps.motivo_cancelamento }} + {% if rps.deducoes|count > 0 %} + + {% for deducao in rps.deducoes -%} + + {{ deducao.por }} + {{ deducao.tipo }} + {{ deducao.cnpj_referencia }} + {{ deducao.nf_referencia }} + {{ deducao.valor_referencia }} + {{ deducao.percentual_deduzir }} + {{ deducao.valor_deduzir }} + + {% endfor %} + + {% endif %} + {% if rps.deducoes|count == 0 %} + + {% endif %} + + {% for item in rps.itens -%} + + {{ item.descricao }} + {{ item.quantidade }} + {{ item.valor_unitario }} + {{ item.valor_total }} + S + + {% endfor %} + + + {% endfor %} + + diff --git a/pytrustnfe/nfse/dsf/templates/soap_header.xml b/pytrustnfe/nfse/dsf/templates/soap_header.xml new file mode 100644 index 0000000..e9d1dd2 --- /dev/null +++ b/pytrustnfe/nfse/dsf/templates/soap_header.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/setup.py b/setup.py index a4bf038..d047457 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ later (LGPLv2+)', 'nfe/templates/*xml', 'nfe/fonts/*ttf', 'nfse/paulistana/templates/*xml', - 'nfse/campinas/templates/*xml', + 'nfse/dsf/templates/*xml', 'nfse/ginfes/templates/*xml', 'nfse/simpliss/templates/*xml', 'nfse/betha/templates/*xml',