diff --git a/pytrustnfe/nfse/paulistana/templates/EnvioLoteRPS.xml b/pytrustnfe/nfse/paulistana/templates/EnvioLoteRPS.xml index bf5e52f..9bb94ac 100644 --- a/pytrustnfe/nfse/paulistana/templates/EnvioLoteRPS.xml +++ b/pytrustnfe/nfse/paulistana/templates/EnvioLoteRPS.xml @@ -70,8 +70,12 @@ {% endif %} {% if rps.tomador.email %}{{ rps.tomador.email }}{% endif %} {{ rps.descricao|normalize|escape }} + {% if rps.valor_carga_tributaria %} {{ rps.valor_carga_tributaria }} + {% endif %} + {% if rps.fonte_carga_tributaria %} {{ rps.fonte_carga_tributaria }} + {% endif %} {% endfor %} diff --git a/tests/XMLs/paulistana_signature.xml b/tests/XMLs/paulistana_signature.xml index 644d7a8..f9a0af4 100644 --- a/tests/XMLs/paulistana_signature.xml +++ b/tests/XMLs/paulistana_signature.xml @@ -1,4 +1,4 @@ -12345678901234false2016-08-292016-08-291E4fpHYkQa7Naxn6IKGb7NwwZu5tPk/KXJ9hCwtZgq0xvKS450aQqqBL+7Iv46lTgqrSMu7+gLrl+LC1qs/8aT2mbHE8uaVFSbzwZ+sF/BkcT6nsFHLMswEiTAEs95Jb7hN1cC91xqQGRH4buw0TzxHKmhuLJ22WwtG/scxyKtjM=12345611RPS2016-08-29NT0.000.000.000.000.00074985.00false123456Trustcode1Vinicius de Moraes, 4242CorregoFloripaSC88037240Venda de servico +12345678901234false2016-08-292016-08-291E4fpHYkQa7Naxn6IKGb7NwwZu5tPk/KXJ9hCwtZgq0xvKS450aQqqBL+7Iv46lTgqrSMu7+gLrl+LC1qs/8aT2mbHE8uaVFSbzwZ+sF/BkcT6nsFHLMswEiTAEs95Jb7hN1cC91xqQGRH4buw0TzxHKmhuLJ22WwtG/scxyKtjM=12345611RPS2016-08-29NT0.000.000.000.000.00074985.00false123456Trustcode1Vinicius de Moraes, 4242CorregoFloripaSC88037240Venda de servico @@ -8,12 +8,12 @@ -Thwvs++WdhRuXOVgMxXTY/9Zih0= +hhkZS9mMYMESJbiswtX0rTq7620= -fvJR0msutiLI9KpUY/8VDPqmDeGYpXt/JvY6LUQZlGjjGb71jM2cLEHotM4lwJLi -WKLvhSBbaLQQm/OFm1KbQ8TRrEJl8NMYv2bABNoH9OxIn5Ecnb4jxCCAaIDN3iXy -B7oYCq5nqtfsFGplU29enQ//1SrRTE4MDsOwoN8bX0c= +Rh6jw1huU4fgTdm8wclRBOaewnccPgOwuT0lya7Z55Ay/GlcXDO/vRRDCgvezhGT +5HkRfXP92gjPgkSnNC23zZMBbTnWzg8Jm8YxDUmwRJujH5RMFBLmNjBIOwfI2o/4 +LhSCoPTBBJ/1JO1nJDABKPFcejWuDeLhIIBj9QqcyW0= MIICMTCCAZqgAwIBAgIQfYOsIEVuAJ1FwwcTrY0t1DANBgkqhkiG9w0BAQUFADBX diff --git a/tests/XMLs/xml_send_rps_batch_to_paulistana.xml b/tests/XMLs/xml_send_rps_batch_to_paulistana.xml index 2eebb3b..63a3c1f 100644 --- a/tests/XMLs/xml_send_rps_batch_to_paulistana.xml +++ b/tests/XMLs/xml_send_rps_batch_to_paulistana.xml @@ -1 +1 @@ -12345678901234false2016-08-292016-08-29512312345610RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345611RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345612RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345613RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345614RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico \ No newline at end of file +12345678901234false2016-08-292016-08-29512312345610RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345611RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345612RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345613RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico12312345614RPS2016-08-29NT0.000.000.000.000.00074985.00false12345678923256123456Trustcode1Vinicius de Moraes, 4242aaaCorregoFloripaSC88037240user@user.comVenda de servico \ No newline at end of file diff --git a/tests/test_nfse_paulistana.py b/tests/test_nfse_paulistana.py index 75f4fea..b094364 100644 --- a/tests/test_nfse_paulistana.py +++ b/tests/test_nfse_paulistana.py @@ -3,16 +3,54 @@ import mock import os.path import unittest + +import pytest +from lxml import etree + +from pytrustnfe import xml from pytrustnfe.certificado import Certificado +from pytrustnfe.nfse import paulistana from pytrustnfe.nfse.paulistana import envio_lote_rps from pytrustnfe.nfse.paulistana import cancelamento_nfe +from pytrustnfe.xml import sanitize_response class test_nfse_paulistana(unittest.TestCase): caminho = os.path.dirname(__file__) + + 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_nfse(self): + def _get_rps_carga_tributaria(self): rps = [ { "assinatura": "123", @@ -39,8 +77,15 @@ class test_nfse_paulistana(unittest.TestCase): "codigo_atividade": "07498", "aliquota_atividade": "5.00", "descricao": "Venda de servico", + "valor_carga_tributaria": "30.00", + "fonte_carga_tributaria": "IBPT" + } ] + return rps + + def _get_nfse(self, rps): + nfse = { "cpf_cnpj": "12345678901234", "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 = 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") 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 = 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") 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["object"].Cabecalho.Sucesso, False) 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") +