Browse Source

WIP - Implementação de layout ginfes, susesu, simpliss

pull/37/merge
Danimar Ribeiro 9 years ago
parent
commit
c35307f772
  1. 21
      pytrustnfe/__init__.py
  2. 32
      pytrustnfe/nfse/ariss/templates/EnviarNota.xml
  3. 32
      pytrustnfe/nfse/ariss/templates/Nota.xml
  4. 87
      pytrustnfe/nfse/simpliss/__init__.py
  5. 20
      pytrustnfe/nfse/simpliss/templates/CancelarNfse.xml
  6. 15
      pytrustnfe/nfse/simpliss/templates/ConsultarLoteRps.xml
  7. 32
      pytrustnfe/nfse/simpliss/templates/ConsultarNfse.xml
  8. 22
      pytrustnfe/nfse/simpliss/templates/ConsultarNfsePorRps.xml
  9. 16
      pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLoteRps.xml
  10. 20
      pytrustnfe/nfse/simpliss/templates/RecepcionarLoteRps.xml
  11. 124
      pytrustnfe/nfse/simpliss/templates/Rps.xml
  12. 5
      pytrustnfe/nfse/simpliss/templates/SoapRequest.xml
  13. 19
      pytrustnfe/nfse/susesu/__init__.py
  14. 4
      pytrustnfe/nfse/susesu/templates/EnviarNota.xml
  15. 14
      pytrustnfe/nfse/susesu/templates/EnviarNotaRetornaurlNota.xml
  16. 32
      pytrustnfe/nfse/susesu/templates/Nota.xml
  17. 6
      pytrustnfe/test/test_ginfes.py
  18. 58
      pytrustnfe/test/test_simpliss.py
  19. 13
      pytrustnfe/test/test_susesu.py
  20. 1
      setup.py

21
pytrustnfe/__init__.py

@ -1,3 +1,24 @@
# -*- coding: utf-8 -*-
# © 2016 Danimar Ribeiro, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import requests
class HttpClient(object):
def __init__(self, url):
self.url = url
def _headers(self, action):
return {
u'Content-type':
u'text/xml; charset=utf-8;',
u'Accept': u'application/soap+xml; charset=utf-8',
u'SOAPAction': action
}
def post_soap(self, xml_soap, action):
header = self._headers(action)
res = requests.post(self.url, data=xml_soap, headers=header)
return res.text

32
pytrustnfe/nfse/ariss/templates/EnviarNota.xml

@ -1,32 +0,0 @@
<NOTA>
<NUMERO_NOTA>6053</NUMERO_NOTA>
<DATA_EMISSAO>21/05/2016</DATA_EMISSAO>
<CODIGO_GERAL_ATIVIDADE>09.00</CODIGO_GERAL_ATIVIDADE>
<CODIGO_ATIVIDADE/>
<OUTRAS_INFORMACOES>NOTA FISCAL DE PRESTAÇÃO DE SERVIÇOS</OUTRAS_INFORMACOES>
<DESCRICAO_SERVICOS>DESCRIÇÃO DO SERVIÇO</DESCRICAO_SERVICOS>
<VALOR_TOTAL_NOTA>440,00</VALOR_TOTAL_NOTA>
<STATUS_ISS_NOTA>1</STATUS_ISS_NOTA>
<IRRF>0,00</IRRF>
<INSS>0,00</INSS>
<PIS>0,00</PIS>
<COFINS>0,00</COFINS>
<CONTRIBUICAO_SOCIAL>0,00</CONTRIBUICAO_SOCIAL>
<VALOR_LIQUIDO>440,00</VALOR_LIQUIDO>
<VALOR_DEDUCAO_MATERIAIS>0,00</VALOR_DEDUCAO_MATERIAIS>
<COD_MUNICIPIO_EXECUCAO_SERVICO>3550407</COD_MUNICIPIO_EXECUCAO_SERVICO>
<LOCAL_EXECUCAO_SERVICO>LOCAL EXECUÇÃO</LOCAL_EXECUCAO_SERVICO>
<TOMADOR_ESTRANGEIRO>N</TOMADOR_ESTRANGEIRO>
<TOMADOR_DOCUMENTO>00000000000</TOMADOR_DOCUMENTO>
<TOMADOR_RAZAO>TOMADOR RAZAO/NOME</TOMADOR_RAZAO>
<TOMADOR_LOGRADOURO>LOGRADOURO</TOMADOR_LOGRADOURO>
<TOMADOR_BAIRRO>BAIRRO</TOMADOR_BAIRRO>
<TOMADOR_CEP>13400000</TOMADOR_CEP>
<TOMADOR_INSCRICAO_ESTADUAL>ISENTO</TOMADOR_INSCRICAO_ESTADUAL>
<TOMADOR_INSCRICAO_MUNICIPAL>ISENTO</TOMADOR_INSCRICAO_MUNICIPAL>
<TOMADOR_EMAIL>email@email.com</TOMADOR_EMAIL>
<TOMADOR_TELEFONE>1912345678</TOMADOR_TELEFONE>
<TOMADOR_MUNICIPIO>3506003</TOMADOR_MUNICIPIO>
<ALIQUOTA>3,00</ALIQUOTA>
<PORCENTAGEM_REGIME_ESPECIAL>0</PORCENTAGEM_REGIME_ESPECIAL>
</NOTA>

32
pytrustnfe/nfse/ariss/templates/Nota.xml

@ -1,32 +0,0 @@
<NOTA>
<NUMERO_NOTA>200</NUMERO_NOTA>
<DATA_EMISSAO>21/05/2016</DATA_EMISSAO>
<CODIGO_GERAL_ATIVIDADE>09.00</CODIGO_GERAL_ATIVIDADE>
<CODIGO_ATIVIDADE/>
<OUTRAS_INFORMACOES>NOTA FISCAL DE PRESTAÇÃO DE SERVIÇOS</OUTRAS_INFORMACOES>
<DESCRICAO_SERVICOS>DESCRIÇÃO DO SERVIÇO</DESCRICAO_SERVICOS>
<VALOR_TOTAL_NOTA>440,00</VALOR_TOTAL_NOTA>
<STATUS_ISS_NOTA>1</STATUS_ISS_NOTA>
<IRRF>0,00</IRRF>
<INSS>0,00</INSS>
<PIS>0,00</PIS>
<COFINS>0,00</COFINS>
<CONTRIBUICAO_SOCIAL>0,00</CONTRIBUICAO_SOCIAL>
<VALOR_LIQUIDO>440,00</VALOR_LIQUIDO>
<VALOR_DEDUCAO_MATERIAIS>0,00</VALOR_DEDUCAO_MATERIAIS>
<COD_MUNICIPIO_EXECUCAO_SERVICO>3550407</COD_MUNICIPIO_EXECUCAO_SERVICO>
<LOCAL_EXECUCAO_SERVICO>LOCAL EXECUÇÃO</LOCAL_EXECUCAO_SERVICO>
<TOMADOR_ESTRANGEIRO>N</TOMADOR_ESTRANGEIRO>
<TOMADOR_DOCUMENTO>00000000000</TOMADOR_DOCUMENTO>
<TOMADOR_RAZAO>TOMADOR RAZAO/NOME</TOMADOR_RAZAO>
<TOMADOR_LOGRADOURO>LOGRADOURO</TOMADOR_LOGRADOURO>
<TOMADOR_BAIRRO>BAIRRO</TOMADOR_BAIRRO>
<TOMADOR_CEP>13400000</TOMADOR_CEP>
<TOMADOR_INSCRICAO_ESTADUAL>ISENTO</TOMADOR_INSCRICAO_ESTADUAL>
<TOMADOR_INSCRICAO_MUNICIPAL>ISENTO</TOMADOR_INSCRICAO_MUNICIPAL>
<TOMADOR_EMAIL>email@email.com</TOMADOR_EMAIL>
<TOMADOR_TELEFONE>1912345678</TOMADOR_TELEFONE>
<TOMADOR_MUNICIPIO>3506003</TOMADOR_MUNICIPIO>
<ALIQUOTA>3,00</ALIQUOTA>
<PORCENTAGEM_REGIME_ESPECIAL>0</PORCENTAGEM_REGIME_ESPECIAL>
</NOTA>

87
pytrustnfe/nfse/simpliss/__init__.py

@ -1,49 +1,62 @@
# -*- coding: utf-8 -*-
# © 2016 Danimar Ribeiro, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# Endereços Simpliss Piracicaba
# Homologação: http://wshomologacao.simplissweb.com.br/nfseservice.svc
# Homologação site: http://homologacaonovo.simplissweb.com.br/Account/Login
# Prod:http://sistemas.pmp.sp.gov.br/semfi/simpliss/contrib/Account/Login
# Prod:http://sistemas.pmp.sp.gov.br/semfi/simpliss/ws_nfse/nfseservice.svc
import os
import suds
from lxml import etree
from pytrustnfe import HttpClient
from pytrustnfe.xml import render_xml, sanitize_response
from pytrustnfe.client import get_authenticated_client
from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key
from pytrustnfe.nfse.assinatura import Assinatura
def _send(certificado, method, **kwargs):
# A little hack to test
def _render_xml(certificado, method, **kwargs):
path = os.path.join(os.path.dirname(__file__), 'templates')
xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
cert, key = extract_cert_and_key_from_pfx(
certificado.pfx, certificado.password)
cert, key = save_cert_key(cert, key)
pfx_path = certificado.save_pfx()
signer = Assinatura(pfx_path, certificado.password)
xml_send = signer.assina_xml(xml_send, '')
return xml_send
def _validate(method, xml):
path = os.path.join(os.path.dirname(__file__), 'templates')
schema = os.path.join(path, '%s.xsd' % method)
from lxml import etree
nfe = etree.fromstring(xml_send)
nfe = etree.fromstring(xml)
esquema = etree.XMLSchema(etree.parse(schema))
esquema.validate(nfe)
erros = [x.message for x in esquema.error_log]
return erros
# 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)
cert, key = save_cert_key(cert, key)
client = get_authenticated_client(base_url, cert, key)
def _send(method, **kwargs):
if kwargs['ambiente'] == 'producao':
base_url = 'http://sistemas.pmp.sp.gov.br/semfi/simpliss/ws_nfse/nfseservice.svc?WSDL' # noqa
else:
base_url = 'http://wshomologacao.simplissweb.com.br/nfseservice.svc?WSDL' # noqa
#pfx_path = certificado.save_pfx()
#signer = Assinatura(pfx_path, certificado.password)
#xml_send = signer.assina_xml(xml_send, '')
xml_send = kwargs["xml"].replace('<?xml version="1.0"?>', '')
path = os.path.join(os.path.dirname(__file__), 'templates')
soap = render_xml(path, 'SoapRequest.xml', False, soap_body=xml_send)
act = 'http://www.sistema.com.br/Sistema.Ws.Nfse/INfseService/%s' % method
client = HttpClient(base_url)
response = client.post_soap(soap, act)
try:
response = getattr(client.service, method)(xml_send)
except suds.WebFault, e:
return {
'sent_xml': xml_send,
'received_xml': e.fault.faultstring,
'object': None
}
print response
response, obj = sanitize_response(response)
return {
@ -53,25 +66,37 @@ def _send(certificado, method, **kwargs):
}
def xml_recepcionar_lote_rps(certificado, **kwargs):
return _render_xml(certificado, 'RecepcionarLoteRps', **kwargs)
def recepcionar_lote_rps(certificado, **kwargs):
return _send(certificado, 'RecepcionarLoteRps', **kwargs)
if "xml" not in kwargs:
kwargs['xml'] = xml_recepcionar_lote_rps(certificado, **kwargs)
return _send('RecepcionarLoteRps', **kwargs)
def xml_consultar_situacao_lote(certificado, **kwargs):
return _render_xml(certificado, 'ConsultarSituacaoLoteRps', **kwargs)
def consultar_situacao_lote(certificado, **kwargs):
return _send(certificado, 'ConsultarSituacaoLoteRps', **kwargs)
if "xml" not in kwargs:
kwargs['xml'] = xml_consultar_situacao_lote(certificado, **kwargs)
return _send('ConsultarSituacaoLoteRps', **kwargs)
def consultar_nfse_por_rps(certificado, **kwargs):
return _send(certificado, 'ConsultarNfsePorRps', **kwargs)
return _send('ConsultarNfsePorRps', **kwargs)
def consultar_lote_rps(certificado, **kwargs):
return _send(certificado, 'ConsultarLoteRps', **kwargs)
return _send('ConsultarLoteRps', **kwargs)
def consultar_nfse(certificado, **kwargs):
return _send(certificado, 'ConsultarNfse', **kwargs)
return _send('ConsultarNfse', **kwargs)
def cancelar_nfse(certificado, **kwargs):
return _send(certificado, 'CancelarNfse', **kwargs)
return _send('CancelarNfse', **kwargs)

20
pytrustnfe/nfse/simpliss/templates/CancelarNfse.xml

@ -1,13 +1,19 @@
<CancelarNfseEnvio xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Pedido>
<CancelarNfse xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse">
<CancelarNfseEnvio>
<Pedido xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<InfPedidoCancelamento>
<IdentificacaoNfse>
<Numero>{{ cancelar.numero_nfse }}</Numero>
<Cnpj>{{ cancelar.cnpj_prestador }}</Cnpj>
<InscricaoMunicipal>{{ cancelar.inscricao_prestador }}</InscricaoMunicipal>
<CodigoMunicipio>{{ cancelar.codigo_municipio }}</CodigoMunicipio>
<Numero>[nonNegativeInteger?]</Numero>
<Cnpj>[string?]</Cnpj>
<InscricaoMunicipal>[string?]</InscricaoMunicipal>
<CodigoMunicipio>[int]</CodigoMunicipio>
</IdentificacaoNfse>
<CodigoCancelamento>{{ cancelar.codigo_cancelamento }}</CodigoCancelamento>
<CodigoCancelamento>[string?]</CodigoCancelamento>
</InfPedidoCancelamento>
</Pedido>
</CancelarNfseEnvio>
<pParam>
<P1 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P1>
<P2 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P2>
</pParam>
</CancelarNfse>

15
pytrustnfe/nfse/simpliss/templates/ConsultarLoteRps.xml

@ -1,6 +1,13 @@
<ConsultarLoteRpsEnvio xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Prestador>
<Cnpj>{{ consulta.cnpj_prestador }}</Cnpj>
<ConsultarLoteRps xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse">
<ConsultarLoteRpsEnvio>
<Prestador xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Cnpj>[string?]</Cnpj>
<InscricaoMunicipal>[string?]</InscricaoMunicipal>
</Prestador>
<Protocolo>{{ consulta.protocolo }}</Protocolo>
<Protocolo xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">[string?]</Protocolo>
</ConsultarLoteRpsEnvio>
<pParam>
<P1 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P1>
<P2 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P2>
</pParam>
</ConsultarLoteRps>

32
pytrustnfe/nfse/simpliss/templates/ConsultarNfse.xml

@ -1,6 +1,30 @@
<ConsultarNfseEnvio xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Prestador>
<Cnpj>{{ consulta.cnpj_prestador }}</Cnpj>
<ConsultarNfse xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse">
<ConsultarNfseEnvio>
<Prestador xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Cnpj>[string?]</Cnpj>
<InscricaoMunicipal>[string?]</InscricaoMunicipal>
</Prestador>
<NumeroNfse>{{ consulta.numero_nfse }}</NumeroNfse>
<NumeroNfse xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">[nonNegativeInteger?]</NumeroNfse>
<PeriodoEmissao xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<DataInicial>[date]</DataInicial>
<DataFinal>[date]</DataFinal>
</PeriodoEmissao>
<Tomador xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<CpfCnpj>
<Cnpj>[string?]</Cnpj>
</CpfCnpj>
<InscricaoMunicipal>[string?]</InscricaoMunicipal>
</Tomador>
<IntermediarioServico xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<RazaoSocial>[string?]</RazaoSocial>
<CpfCnpj>
<Cnpj>[string?]</Cnpj>
</CpfCnpj>
<InscricaoMunicipal>[string?]</InscricaoMunicipal>
</IntermediarioServico>
</ConsultarNfseEnvio>
<pParam>
<P1 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P1>
<P2 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P2>
</pParam>
</ConsultarNfse>

22
pytrustnfe/nfse/simpliss/templates/ConsultarNfsePorRps.xml

@ -1,11 +1,17 @@
<ConsultarNfseRpsEnvio xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<IdentificacaoRps>
<Numero>{{ consulta.numero_rps }}</Numero>
<Serie>{{ consulta.serie_rps }}</Serie>
<Tipo>{{ consulta.tipo_rps }}</Tipo>
<ConsultarNfsePorRps xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse">
<ConsultarNfseRpsEnvio>
<IdentificacaoRps xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Numero>[nonNegativeInteger?]</Numero>
<Serie>[string?]</Serie>
<Tipo>[byte]</Tipo>
</IdentificacaoRps>
<Prestador>
<Cnpj>{{ consulta.cnpj_prestador }}</Cnpj>
<InscricaoMunicipal>{{ consulta.inscricao_prestador }}</InscricaoMunicipal>
<Prestador xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Cnpj>[string?]</Cnpj>
<InscricaoMunicipal>[string?]</InscricaoMunicipal>
</Prestador>
</ConsultarNfseRpsEnvio>
<pParam>
<P1 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P1>
<P2 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P2>
</pParam>
</ConsultarNfsePorRps>

16
pytrustnfe/nfse/simpliss/templates/ConsultarSituacaoLoteRps.xml

@ -1,7 +1,13 @@
<ConsultarSituacaoLoteRpsEnvio xmlns:tns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Prestador>
<Cnpj>{{ consulta.cnpj_prestador }}</Cnpj>
<InscricaoMunicipal>{{ consulta.inscricao_prestador }}</InscricaoMunicipal>
<ConsultarSituacaoLoteRps xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse">
<ConsultarSituacaoLoteRpsEnvio>
<Prestador xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<Cnpj>[string?]</Cnpj>
<InscricaoMunicipal>[string?]</InscricaoMunicipal>
</Prestador>
<Protocolo>{{ consulta.protocolo }}</Protocolo>
<Protocolo xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">[string?]</Protocolo>
</ConsultarSituacaoLoteRpsEnvio>
<pParam>
<P1 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P1>
<P2 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">[string?]</P2>
</pParam>
</ConsultarSituacaoLoteRps>

20
pytrustnfe/nfse/simpliss/templates/RecepcionarLoteRps.xml

@ -1,11 +1,19 @@
<EnviarLoteRpsEnvio xmlns = "http://www.betha.com.br/e-nota-contribuinte-ws">
<LoteRps Id="lote1" versao="2.02">
<NumeroLote>2012024</NumeroLote>
<Cnpj>45111111111100</Cnpj>
<InscricaoMunicipal>123498</InscricaoMunicipal>
<RecepcionarLoteRps xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse">
<EnviarLoteRpsEnvio>
<LoteRps xmlns="http://www.sistema.com.br/Nfse/arquivos/nfse_3.xsd">
<NumeroLote>{{ nfse.numero_lote }}</NumeroLote>
<Cnpj>{{ nfse.cnpj_prestador }}</Cnpj>
<InscricaoMunicipal>{{ nfse.inscricao_municipal }}</InscricaoMunicipal>
<QuantidadeRps>1</QuantidadeRps>
<ListaRps>
{% include 'rps.xml' %}
{% for rps in nfse.lista_rps -%}
{% include 'Rps.xml' %}
{% endfor %}
</ListaRps>
</LoteRps>
</EnviarLoteRpsEnvio>
<pParam>
<P1 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">{{ nfse.cnpj_prestador }}</P1>
<P2 xmlns="http://www.sistema.com.br/Sistema.Ws.Nfse.Cn">{{ nfse.senha }}</P2>
</pParam>
</RecepcionarLoteRps>

124
pytrustnfe/nfse/simpliss/templates/Rps.xml

@ -1,82 +1,94 @@
<Rps>
<InfRps Id="rps1">
<InfRps>
<IdentificacaoRps>
<Numero>25</Numero>
<Serie>A1</Serie>
<Tipo>1</Tipo>
<Numero>{{ rps.numero }}</Numero>
<Serie>{{ rps.serie }}</Serie>
<Tipo>{{ rps.tipo }}</Tipo>
</IdentificacaoRps>
<DataEmissao>2014-12-06</DataEmissao>
<NaturezaOperacao>1</NaturezaOperacao>
<RegimeEspecialTributacao>1</RegimeEspecialTributacao>
<OptanteSimplesNacional>1</OptanteSimplesNacional>
<IncentivadorCultural>1</IncentivadorCultural>
<Status>1</Status>
<DataEmissao>{{ rps.data_emissao }}</DataEmissao>
<NaturezaOperacao>{{ rps.natureza_operacao }}</NaturezaOperacao>
<RegimeEspecialTributacao>{{ rps.regime_tributacao }}</RegimeEspecialTributacao>
<OptanteSimplesNacional>{{ rps.optante_simples }}</OptanteSimplesNacional>
<IncentivadorCultural>{{ rps.incentivador_cultural }}</IncentivadorCultural>
<Status>{{ rps.status }}</Status>
<RpsSubstituido>
<Numero>1</Numero>
<Serie>1</Serie>
<Tipo>1</Tipo>
<Numero>{{ rps.numero_substituido }}</Numero>
<Serie>{{ rps.serie_substituido }}</Serie>
<Tipo>{{ rps.tipo_substituido }}</Tipo>
</RpsSubstituido>
<OutrasInformacoes>1</OutrasInformacoes>
<Servico>
<Valores>
<ValorServicos>100</ValorServicos>
<ValorDeducoes>0</ValorDeducoes>
<ValorPis>0</ValorPis>
<ValorCofins>0</ValorCofins>
<ValorInss>0</ValorInss>
<ValorIr>0</ValorIr>
<ValorCsll>0</ValorCsll>
<OutrasRetencoes>0</OutrasRetencoes>
<DescontoIncondicionado>0</DescontoIncondicionado>
<DescontoCondicionado>0</DescontoCondicionado>
<ValorServicos>{{ rps.valor_servico }}</ValorServicos>
<ValorDeducoes>{{ rps.valor_deducao }}</ValorDeducoes>
<ValorPis>{{ rps.valor_pis }}</ValorPis>
<ValorCofins>{{ rps.valor_cofins }}</ValorCofins>
<ValorInss>{{ rps.valor_inss }}</ValorInss>
<ValorIr>{{ rps.valor_ir }}</ValorIr>
<ValorCsll>{{ rps.valor_csll }}</ValorCsll>
<IssRetido>{{ rps.iss_retido }}</IssRetido>
<ValorIss>{{ rps.valor_iss }}</ValorIss>
<ValorIssRetido>{{ rps.valor_iss_retido }}</ValorIssRetido>
<OutrasRetencoes>{{ rps.outras_retencoes }}</OutrasRetencoes>
<BaseCalculo>{{ rps.base_calculo }}</BaseCalculo>
<Aliquota>{{ rps.aliquota }}</Aliquota>
<ValorLiquidoNfse>{{ rps.valor_liquido_nfse }}</ValorLiquidoNfse>
<DescontoIncondicionado>{{ rps.desconto_incondicionado }}</DescontoIncondicionado>
<DescontoCondicionado>{{ rps.desconto_condicionado }}</DescontoCondicionado>
</Valores>
<IssRetido>2</IssRetido>
<ItemListaServico>0702</ItemListaServico>
<CodigoTributacaoMunicipio>2525</CodigoTributacaoMunicipio>
<Discriminacao>Prog.</Discriminacao>
<CodigoMunicipio>4204608</CodigoMunicipio>
<ExigibilidadeISS>1</ExigibilidadeISS>
<MunicipioIncidencia>4204608</MunicipioIncidencia>
<ItemListaServico>{{ rps.codigo_servico }}</ItemListaServico>
<CodigoCnae>{{ rps.cnae }}</CodigoCnae>
<CodigoTributacaoMunicipio>{{ rps.codigo_tributacao }}</CodigoTributacaoMunicipio>
<Discriminacao>{{ rps.descricao }}</Discriminacao>
<CodigoMunicipio>{{ rps.codigo_municipio }}</CodigoMunicipio>
{% for item in rps.itens_servico -%}
<ItensServico>
<Descricao>{{ item.descricao }}</Descricao>
<Quantidade>{{ item.quantidade }}</Quantidade>
<ValorUnitario>{{ item.valor_unitario }}</ValorUnitario>
</ItensServico>
{% endfor %}
</Servico>
<Prestador>
<CpfCnpj>
<Cnpj>45111111111100</Cnpj>
</CpfCnpj>
<InscricaoMunicipal>123498</InscricaoMunicipal>
<Cnpj>{{ rps.prestador.cnpj }}</Cnpj>
<InscricaoMunicipal>{{ rps.prestador.inscricao_municipal }}</InscricaoMunicipal>
</Prestador>
<Tomador>
<IdentificacaoTomador>
<CpfCnpj>
<Cnpj>83787494000123</Cnpj>
<Cnpj>{{ rps.tomador.cnpj_cpf }}</Cnpj>
<Cpf>{{ rps.tomador.cnpj_cpf }}</Cpf>
</CpfCnpj>
<InscricaoMunicipal>{{ rps.tomador.inscricao_municipal }}</InscricaoMunicipal>
</IdentificacaoTomador>
<RazaoSocial>INSTITUICAO FINANCEIRA</RazaoSocial>
<RazaoSocial>{{ rps.tomador.razao_social }}</RazaoSocial>
<Endereco>
<Endereco>AV. 7 DE SETEMBRO</Endereco>
<Numero>1505</Numero>
<Complemento>AO LADO DO JOAO AUTOMOVEIS</Complemento>
<Bairro>CENTRO</Bairro>
<CodigoMunicipio>4201406</CodigoMunicipio>
<Uf>SC</Uf>
<Cep>88900000</Cep>
<Endereco>{{ rps.tomador.logradouro }}</Endereco>
<Numero>{{ rps.tomador.numero }}</Numero>
<Complemento>{{ rps.tomador.complemento }}</Complemento>
<Bairro>{{ rps.tomador.bairro }}</Bairro>
<CodigoMunicipio>{{ rps.tomador.codigo_municipio }}</CodigoMunicipio>
<Uf>{{ rps.tomador.uf }}</Uf>
<Cep>{{ rps.tomador.cep }}</Cep>
</Endereco>
<Contato>
<Telefone>4835220026</Telefone>
<Email>luiz.alves@cxpostal.com</Email>
<Telefone>{{ rps.tomador.telefone }}</Telefone>
<Email>{{ rps.tomador.email }}</Email>
</Contato>
</Tomador>
{% if rps.intermediario is defined -%}
<IntermediarioServico>
<IdentificacaoIntermediario>
<RazaoSocial>{{ rps.intermediario.razao_social }}</RazaoSocial>
<CpfCnpj>
<Cnpj>06410987065144</Cnpj>
<Cnpj>{{ rps.intermediario.cnpj }}</Cnpj>
</CpfCnpj>
<InscricaoMunicipal>22252</InscricaoMunicipal>
</IdentificacaoIntermediario>
<RazaoSocial>CONSTRUTORA TERRA FIRME</RazaoSocial>
<InscricaoMunicipal>{{ rps.intermediario.inscricao_municipal }}</InscricaoMunicipal>
</IntermediarioServico>
<ConstrucaoCivil>
<CodigoObra>142</CodigoObra>
<Art>1/2014</Art>
</ConstrucaoCivil>
</InfDeclaracaoPrestacaoServico>
{% endif %}
{% if rps.construcao_civil is defined -%}
<ContrucaoCivil>
<CodigoObra>{{ rps.construcao_civil.codigo_obra }}</CodigoObra>
<Art>{{ rps.construcao_civil.art }}</Art>
</ContrucaoCivil>
{% endif %}
</InfRps>
</Rps>

5
pytrustnfe/nfse/simpliss/templates/SoapRequest.xml

@ -0,0 +1,5 @@
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
{{ soap_body }}
</Body>
</Envelope>

19
pytrustnfe/nfse/ariss/__init__.py → pytrustnfe/nfse/susesu/__init__.py

@ -3,16 +3,18 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os
import suds
import unicodedata
from pytrustnfe.xml import render_xml
from pytrustnfe.client import get_client
def _send(method, **kwargs):
def _render_xml(method, **kwargs):
path = os.path.join(os.path.dirname(__file__), 'templates')
xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
return xml_send
def _send(method, **kwargs):
if kwargs['ambiente'] == 'producao':
base_url = 'http://www.susesu.com.br/wsnfd/serviconfd.asmx?WSDL'
else:
@ -20,6 +22,7 @@ def _send(method, **kwargs):
client = get_client(base_url)
try:
xml_send = kwargs["xml"]
result = getattr(client.service, method)(__inject={'msg': xml_send})
except Exception as e:
return {
@ -34,9 +37,21 @@ def _send(method, **kwargs):
}
def xml_enviar_nota(**kwargs):
return _render_xml('EnviarNota', **kwargs)
def enviar_nota(**kwargs):
if "xml" not in kwargs:
kwargs['xml'] = xml_enviar_nota(**kwargs)
return _send('EnviarNota', **kwargs)
def xml_enviar_nota_retorna_url(**kwargs):
return _render_xml('EnviarNotaRetornaurlNota', **kwargs)
def enviar_nota_retorna_url(**kwargs):
if "xml" not in kwargs:
kwargs['xml'] = xml_enviar_nota_retorna_url(**kwargs)
return _send('EnviarNotaRetornaurlNota', **kwargs)

4
pytrustnfe/nfse/ariss/templates/EnviarNotaRetornaurlNota.xml → pytrustnfe/nfse/susesu/templates/EnviarNota.xml

@ -1,6 +1,6 @@
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<EnviarNotaRetornaurlNota xmlns="http://susesu.com.br/">
<EnviarNota xmlns="http://susesu.com.br/">
<codPrefeitura>{{ codigo_prefeitura }}</codPrefeitura>
<notaFiscal>
<![CDATA[
@ -9,6 +9,6 @@
</notaFiscal>
<cnpjPrestador>{{ cnpj_prestador }}</cnpjPrestador>
<senhaNFD>{{ senha_nfd }}</senhaNFD>
</EnviarNotaRetornaurlNota>
</EnviarNota>
</soap:Body>
</soap:Envelope>

14
pytrustnfe/nfse/susesu/templates/EnviarNotaRetornaurlNota.xml

@ -0,0 +1,14 @@
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<EnviarNotaRetornaurlNota xmlns="http://susesu.com.br/">
<codPrefeitura>{{ nfse.codigo_prefeitura }}</codPrefeitura>
<notaFiscal>
<![CDATA[
{% include 'Nota.xml' %}
]]>
</notaFiscal>
<cnpjPrestador>{{ nfse.cnpj_prestador }}</cnpjPrestador>
<senhaNFD>{{ nfse.senha_nfd }}</senhaNFD>
</EnviarNotaRetornaurlNota>
</soap:Body>
</soap:Envelope>

32
pytrustnfe/nfse/susesu/templates/Nota.xml

@ -0,0 +1,32 @@
<NOTA>
<NUMERO_NOTA>{{ nfse.numero }}</NUMERO_NOTA>
<DATA_EMISSAO>{{ nfse.data_emissao }}</DATA_EMISSAO>
<CODIGO_GERAL_ATIVIDADE>{{ nfse.codigo_atividade }}</CODIGO_GERAL_ATIVIDADE>
<CODIGO_ATIVIDADE/>
<OUTRAS_INFORMACOES>{{ nfse.observacoes}}</OUTRAS_INFORMACOES>
<DESCRICAO_SERVICOS>{{ nfse.descricao }}</DESCRICAO_SERVICOS>
<VALOR_TOTAL_NOTA>{{ nfse.total_servicos }}</VALOR_TOTAL_NOTA>
<STATUS_ISS_NOTA>1</STATUS_ISS_NOTA>
<IRRF>{{ nfse.valor_ir }}</IRRF>
<INSS>{{ nfse.valor_inss }}</INSS>
<PIS>{{ nfse.valor_pis }}</PIS>
<COFINS>{{ nfse.valor_pis }}</COFINS>
<CONTRIBUICAO_SOCIAL>0,00</CONTRIBUICAO_SOCIAL>
<VALOR_LIQUIDO>{{ nfse.total_servicos }}</VALOR_LIQUIDO>
<VALOR_DEDUCAO_MATERIAIS>{{ nfse.valor_deducao }}</VALOR_DEDUCAO_MATERIAIS>
<COD_MUNICIPIO_EXECUCAO_SERVICO>{{ nfse.prestador.cidade }}</COD_MUNICIPIO_EXECUCAO_SERVICO>
<LOCAL_EXECUCAO_SERVICO>{{ nfse.prestador.cidade_descricao }}</LOCAL_EXECUCAO_SERVICO>
<TOMADOR_ESTRANGEIRO>N</TOMADOR_ESTRANGEIRO>
<TOMADOR_DOCUMENTO>{{ nfse.tomador.cpf_cnpj }}</TOMADOR_DOCUMENTO>
<TOMADOR_RAZAO>{{ nfse.tomador.razao_social }}</TOMADOR_RAZAO>
<TOMADOR_LOGRADOURO>{{ nfse.tomador.logradouro }}</TOMADOR_LOGRADOURO>
<TOMADOR_BAIRRO>{{ nfse.tomador.bairro }}</TOMADOR_BAIRRO>
<TOMADOR_CEP>{{ nfse.tomador.cep }}</TOMADOR_CEP>
<TOMADOR_INSCRICAO_ESTADUAL>{{ nfse.tomador.inscricao_estadual }}</TOMADOR_INSCRICAO_ESTADUAL>
<TOMADOR_INSCRICAO_MUNICIPAL>{{ nfse.tomador.inscricao_municipal }}</TOMADOR_INSCRICAO_MUNICIPAL>
<TOMADOR_EMAIL>{{ nfse.tomador.email }}</TOMADOR_EMAIL>
<TOMADOR_TELEFONE>{{ nfse.tomador.telefone }}</TOMADOR_TELEFONE>
<TOMADOR_MUNICIPIO>{{ nfse.tomador.cidade }}</TOMADOR_MUNICIPIO>
<ALIQUOTA>{{ nfse.tomador.aliquota_atividade }}</ALIQUOTA>
<PORCENTAGEM_REGIME_ESPECIAL>0</PORCENTAGEM_REGIME_ESPECIAL>
</NOTA>

6
pytrustnfe/test/test_ginfes.py

@ -5,7 +5,6 @@ import os.path
import unittest
from pytrustnfe.certificado import Certificado
from pytrustnfe.nfse.ginfes import consultar_situacao_lote
from pytrustnfe.nfse.ginfes import consultar_nfse
class test_nfse_ginfes(unittest.TestCase):
@ -13,13 +12,12 @@ class test_nfse_ginfes(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')
pfx_source = open('/home/danimar/Downloads/machado.pfx', 'r').read()
pfx = Certificado(pfx_source, '123456789')
dados = {'ambiente': 'homologacao'}
retorno = consultar_situacao_lote(
pfx, consulta=dados, ambiente='homologacao')
print retorno
self.assertNotEqual(retorno['received_xml'], '')
self.assertEqual(retorno['object'].Cabecalho.Sucesso, True)

58
pytrustnfe/test/test_simpliss.py

@ -3,63 +3,21 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os.path
import unittest
from unittest import skip
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_rps
from pytrustnfe.nfse.simpliss import consultar_nfse
from pytrustnfe.nfse.simpliss import cancelar_nfse
from pytrustnfe.nfse.simpliss import recepcionar_lote_rps
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')
def test_recepcionar_lote(self):
pfx_source = open('/home/danimar/Downloads/machado.pfx', 'r').read()
pfx = Certificado(pfx_source, '123456789')
dados = {'cnpj_prestador': '12345678910234', 'inscricao_prestador': '123', 'protocolo': '123'}
response = consultar_situacao_lote(
dados = {'cnpj_prestador': '12345678910234',
'inscricao_prestador': '123',
'protocolo': '123'}
response = recepcionar_lote_rps(
pfx, consulta=dados, ambiente='homologacao')
print response
@skip
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')
@skip
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_rps(
pfx, consulta=dados, ambiente='homologacao')
@skip
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')
@skip
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')

13
pytrustnfe/test/test_ariss.py → pytrustnfe/test/test_susesu.py

@ -3,24 +3,21 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os.path
import unittest
from pytrustnfe.nfse.ariss import enviar_nota
from pytrustnfe.nfse.ariss import enviar_nota_retorna_url
from pytrustnfe.nfse.susesu import enviar_nota_retorna_url
class test_nfse_arisss(unittest.TestCase):
class test_nfse_susesu(unittest.TestCase):
caminho = os.path.dirname(__file__)
def test_enviar_nota_url_nota(self):
nota = {
}
dados = {
'cnpj_prestador': '21118045000135',
'codigo_prefeitura': 3150,
'senha_nfd': 'fiscalb',
'nota': nota
'prestador': {},
'tomador': {}
}
response = enviar_nota_retorna_url(ambiente='homologacao', **dados)
response = enviar_nota_retorna_url(ambiente='homologacao', nfse=dados)
self.assertEqual(response['received_xml'],
'0-Numero da nota fiscal invalido.')

1
setup.py

@ -26,6 +26,7 @@ later (LGPLv2+)',
'nfse/ginfes/templates/*xml',
'nfse/simpliss/templates/*xml',
'nfse/betha/templates/*xml',
'nfse/susesu/templates/*xml',
'xml/schemas/*xsd',
]},
url='https://github.com/danimaribeiro/PyTrustNFe',

Loading…
Cancel
Save