Browse Source

RN Fix template for carga tributaria (#10)

* feat(nfse) allowing carga tibutar appear or not on the NF.

* feat(nfse) fixing tests.

* feat(nfse) tests.
pull/276/head
regianenas 6 years ago
committed by GitHub
parent
commit
de831ee38e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      pytrustnfe/nfse/paulistana/templates/EnvioLoteRPS.xml
  2. 10
      tests/XMLs/paulistana_signature.xml
  3. 2
      tests/XMLs/xml_send_rps_batch_to_paulistana.xml
  4. 86
      tests/test_nfse_paulistana.py

4
pytrustnfe/nfse/paulistana/templates/EnvioLoteRPS.xml

@ -70,8 +70,12 @@
{% endif %} {% endif %}
{% if rps.tomador.email %}<EmailTomador>{{ rps.tomador.email }}</EmailTomador>{% endif %} {% if rps.tomador.email %}<EmailTomador>{{ rps.tomador.email }}</EmailTomador>{% endif %}
<Discriminacao>{{ rps.descricao|normalize|escape }}</Discriminacao> <Discriminacao>{{ rps.descricao|normalize|escape }}</Discriminacao>
{% if rps.valor_carga_tributaria %}
<ValorCargaTributaria>{{ rps.valor_carga_tributaria }}</ValorCargaTributaria> <ValorCargaTributaria>{{ rps.valor_carga_tributaria }}</ValorCargaTributaria>
{% endif %}
{% if rps.fonte_carga_tributaria %}
<FonteCargaTributaria>{{ rps.fonte_carga_tributaria }}</FonteCargaTributaria> <FonteCargaTributaria>{{ rps.fonte_carga_tributaria }}</FonteCargaTributaria>
{% endif %}
</RPS> </RPS>
{% endfor %} {% endfor %}
</PedidoEnvioLoteRPS> </PedidoEnvioLoteRPS>

10
tests/XMLs/paulistana_signature.xml

@ -1,4 +1,4 @@
<PedidoEnvioLoteRPS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.prefeitura.sp.gov.br/nfe"><Cabecalho xmlns="" Versao="1"><CPFCNPJRemetente><CNPJ>12345678901234</CNPJ></CPFCNPJRemetente><transacao>false</transacao><dtInicio>2016-08-29</dtInicio><dtFim>2016-08-29</dtFim><QtdRPS>1</QtdRPS><ValorTotalServicos/><ValorTotalDeducoes/></Cabecalho><RPS xmlns=""><Assinatura>E4fpHYkQa7Naxn6IKGb7NwwZu5tPk/KXJ9hCwtZgq0xvKS450aQqqBL+7Iv46lTgqrSMu7+gLrl+LC1qs/8aT2mbHE8uaVFSbzwZ+sF/BkcT6nsFHLMswEiTAEs95Jb7hN1cC91xqQGRH4buw0TzxHKmhuLJ22WwtG/scxyKtjM=</Assinatura><ChaveRPS><InscricaoPrestador>123456</InscricaoPrestador><SerieRPS>1</SerieRPS><NumeroRPS>1</NumeroRPS></ChaveRPS><TipoRPS>RPS</TipoRPS><DataEmissao>2016-08-29</DataEmissao><StatusRPS>N</StatusRPS><TributacaoRPS>T</TributacaoRPS><ValorServicos/><ValorDeducoes/><ValorPIS>0.00</ValorPIS><ValorCOFINS>0.00</ValorCOFINS><ValorINSS>0.00</ValorINSS><ValorIR>0.00</ValorIR><ValorCSLL>0.00</ValorCSLL><CodigoServico>07498</CodigoServico><AliquotaServicos>5.00</AliquotaServicos><ISSRetido>false</ISSRetido><CPFCNPJTomador/><InscricaoMunicipalTomador>123456</InscricaoMunicipalTomador><RazaoSocialTomador>Trustcode</RazaoSocialTomador><EnderecoTomador><TipoLogradouro>1</TipoLogradouro><Logradouro>Vinicius de Moraes, 42</Logradouro><NumeroEndereco>42</NumeroEndereco><Bairro>Corrego</Bairro><Cidade>Floripa</Cidade><UF>SC</UF><CEP>88037240</CEP></EnderecoTomador><Discriminacao>Venda de servico</Discriminacao><ValorCargaTributaria/><FonteCargaTributaria/></RPS><Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<PedidoEnvioLoteRPS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.prefeitura.sp.gov.br/nfe"><Cabecalho xmlns="" Versao="1"><CPFCNPJRemetente><CNPJ>12345678901234</CNPJ></CPFCNPJRemetente><transacao>false</transacao><dtInicio>2016-08-29</dtInicio><dtFim>2016-08-29</dtFim><QtdRPS>1</QtdRPS><ValorTotalServicos/><ValorTotalDeducoes/></Cabecalho><RPS xmlns=""><Assinatura>E4fpHYkQa7Naxn6IKGb7NwwZu5tPk/KXJ9hCwtZgq0xvKS450aQqqBL+7Iv46lTgqrSMu7+gLrl+LC1qs/8aT2mbHE8uaVFSbzwZ+sF/BkcT6nsFHLMswEiTAEs95Jb7hN1cC91xqQGRH4buw0TzxHKmhuLJ22WwtG/scxyKtjM=</Assinatura><ChaveRPS><InscricaoPrestador>123456</InscricaoPrestador><SerieRPS>1</SerieRPS><NumeroRPS>1</NumeroRPS></ChaveRPS><TipoRPS>RPS</TipoRPS><DataEmissao>2016-08-29</DataEmissao><StatusRPS>N</StatusRPS><TributacaoRPS>T</TributacaoRPS><ValorServicos/><ValorDeducoes/><ValorPIS>0.00</ValorPIS><ValorCOFINS>0.00</ValorCOFINS><ValorINSS>0.00</ValorINSS><ValorIR>0.00</ValorIR><ValorCSLL>0.00</ValorCSLL><CodigoServico>07498</CodigoServico><AliquotaServicos>5.00</AliquotaServicos><ISSRetido>false</ISSRetido><CPFCNPJTomador/><InscricaoMunicipalTomador>123456</InscricaoMunicipalTomador><RazaoSocialTomador>Trustcode</RazaoSocialTomador><EnderecoTomador><TipoLogradouro>1</TipoLogradouro><Logradouro>Vinicius de Moraes, 42</Logradouro><NumeroEndereco>42</NumeroEndereco><Bairro>Corrego</Bairro><Cidade>Floripa</Cidade><UF>SC</UF><CEP>88037240</CEP></EnderecoTomador><Discriminacao>Venda de servico</Discriminacao></RPS><Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo> <SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
@ -8,12 +8,12 @@
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/> <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms> </Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>Thwvs++WdhRuXOVgMxXTY/9Zih0=</DigestValue>
<DigestValue>hhkZS9mMYMESJbiswtX0rTq7620=</DigestValue>
</Reference> </Reference>
</SignedInfo> </SignedInfo>
<SignatureValue>fvJR0msutiLI9KpUY/8VDPqmDeGYpXt/JvY6LUQZlGjjGb71jM2cLEHotM4lwJLi
WKLvhSBbaLQQm/OFm1KbQ8TRrEJl8NMYv2bABNoH9OxIn5Ecnb4jxCCAaIDN3iXy
B7oYCq5nqtfsFGplU29enQ//1SrRTE4MDsOwoN8bX0c=</SignatureValue>
<SignatureValue>Rh6jw1huU4fgTdm8wclRBOaewnccPgOwuT0lya7Z55Ay/GlcXDO/vRRDCgvezhGT
5HkRfXP92gjPgkSnNC23zZMBbTnWzg8Jm8YxDUmwRJujH5RMFBLmNjBIOwfI2o/4
LhSCoPTBBJ/1JO1nJDABKPFcejWuDeLhIIBj9QqcyW0=</SignatureValue>
<KeyInfo> <KeyInfo>
<X509Data> <X509Data>
<X509Certificate>MIICMTCCAZqgAwIBAgIQfYOsIEVuAJ1FwwcTrY0t1DANBgkqhkiG9w0BAQUFADBX <X509Certificate>MIICMTCCAZqgAwIBAgIQfYOsIEVuAJ1FwwcTrY0t1DANBgkqhkiG9w0BAQUFADBX

2
tests/XMLs/xml_send_rps_batch_to_paulistana.xml
File diff suppressed because it is too large
View File

86
tests/test_nfse_paulistana.py

@ -3,16 +3,54 @@
import mock import mock
import os.path import os.path
import unittest import unittest
import pytest
from lxml import etree
from pytrustnfe import xml
from pytrustnfe.certificado import Certificado from pytrustnfe.certificado import Certificado
from pytrustnfe.nfse import paulistana
from pytrustnfe.nfse.paulistana import envio_lote_rps from pytrustnfe.nfse.paulistana import envio_lote_rps
from pytrustnfe.nfse.paulistana import cancelamento_nfe from pytrustnfe.nfse.paulistana import cancelamento_nfe
from pytrustnfe.xml import sanitize_response
class test_nfse_paulistana(unittest.TestCase): class test_nfse_paulistana(unittest.TestCase):
caminho = os.path.dirname(__file__) caminho = os.path.dirname(__file__)
def _get_nfse(self):
def _get_rps(self):
rps = [
{
"assinatura": "123",
"serie": "1",
"numero": "1",
"data_emissao": "2016-08-29",
"codigo_atividade": "07498",
"total_servicos": "2.00",
"total_deducoes": "3.00",
"prestador": {"inscricao_municipal": "123456"},
"tomador": {
"tipo_cpfcnpj": "1",
"cpf_cnpj": "12345678923256",
"inscricao_municipal": "123456",
"razao_social": "Trustcode",
"tipo_logradouro": "1",
"logradouro": "Vinicius de Moraes, 42",
"numero": "42",
"bairro": "Corrego",
"cidade": "Floripa",
"uf": "SC",
"cep": "88037240",
},
"codigo_atividade": "07498",
"aliquota_atividade": "5.00",
"descricao": "Venda de servico",
}
]
return rps
def _get_rps_carga_tributaria(self):
rps = [ rps = [
{ {
"assinatura": "123", "assinatura": "123",
@ -39,8 +77,15 @@ class test_nfse_paulistana(unittest.TestCase):
"codigo_atividade": "07498", "codigo_atividade": "07498",
"aliquota_atividade": "5.00", "aliquota_atividade": "5.00",
"descricao": "Venda de servico", "descricao": "Venda de servico",
"valor_carga_tributaria": "30.00",
"fonte_carga_tributaria": "IBPT"
} }
] ]
return rps
def _get_nfse(self, rps):
nfse = { nfse = {
"cpf_cnpj": "12345678901234", "cpf_cnpj": "12345678901234",
"data_inicio": "2016-08-29", "data_inicio": "2016-08-29",
@ -53,7 +98,8 @@ class test_nfse_paulistana(unittest.TestCase):
pfx_source = open(os.path.join(self.caminho, "teste.pfx"), "rb").read() pfx_source = open(os.path.join(self.caminho, "teste.pfx"), "rb").read()
pfx = Certificado(pfx_source, "123456") pfx = Certificado(pfx_source, "123456")
nfse = self._get_nfse()
rps = self._get_rps()
nfse = self._get_nfse(rps)
path = os.path.join(os.path.dirname(__file__), "XMLs") path = os.path.join(os.path.dirname(__file__), "XMLs")
xml_return = open(os.path.join(path, "paulistana_resultado.xml"), "r").read() xml_return = open(os.path.join(path, "paulistana_resultado.xml"), "r").read()
@ -75,7 +121,8 @@ class test_nfse_paulistana(unittest.TestCase):
pfx_source = open(os.path.join(self.caminho, "teste.pfx"), "rb").read() pfx_source = open(os.path.join(self.caminho, "teste.pfx"), "rb").read()
pfx = Certificado(pfx_source, "123456") pfx = Certificado(pfx_source, "123456")
nfse = self._get_nfse()
rps = self._get_rps()
nfse = self._get_nfse(rps)
path = os.path.join(os.path.dirname(__file__), "XMLs") path = os.path.join(os.path.dirname(__file__), "XMLs")
xml_sent = open(os.path.join(path, "paulistana_signature.xml"), "r").read() xml_sent = open(os.path.join(path, "paulistana_signature.xml"), "r").read()
@ -138,3 +185,36 @@ class test_nfse_paulistana(unittest.TestCase):
self.assertEqual(retorno["received_xml"], xml_return) self.assertEqual(retorno["received_xml"], xml_return)
self.assertEqual(retorno["object"].Cabecalho.Sucesso, False) self.assertEqual(retorno["object"].Cabecalho.Sucesso, False)
self.assertEqual(retorno["object"].Erro.ChaveNFe.NumeroNFe, 446) self.assertEqual(retorno["object"].Erro.ChaveNFe.NumeroNFe, 446)
def test_nfse_com_carga_tributaria(self):
rps = self._get_rps_carga_tributaria()
nfse = self._get_nfse(rps)
path = os.path.join(os.path.dirname(paulistana.__file__), 'templates')
xml_send = xml.render_xml(path, 'EnvioLoteRPS.xml', False, nfse=nfse)
_, xml_send_obj = sanitize_response(xml_send)
self.assertEqual(xml_send_obj.RPS.ValorCargaTributaria, 30.00)
self.assertEqual(xml_send_obj.RPS.FonteCargaTributaria, "IBPT")
def test_nfse_sem_carga_tributaria(self):
rps = self._get_rps()
nfse = self._get_nfse(rps)
path = os.path.join(os.path.dirname(paulistana.__file__), 'templates')
xml_send = xml.render_xml(path, 'EnvioLoteRPS.xml', False, nfse=nfse)
_, xml_send_obj = sanitize_response(xml_send)
with pytest.raises(AttributeError) as error:
xml_send_obj.RPS.ValorCargaTributaria
self.assertEqual(error.match, "no such child: ValorCargaTributaria")
xml_send_obj.RPS.FonteCargaTributaria
self.assertEqual(error.match, "no such child: FonteCargaTributaria")
Loading…
Cancel
Save