Browse Source

WIP - Implementação NFSe Betha

feature/betha
Danimar Ribeiro 9 years ago
parent
commit
f8ae6bfa9e
  1. 6
      pytrustnfe/nfse/betha/__init__.py
  2. 2
      pytrustnfe/nfse/betha/templates/GerarNfse.xml
  3. 2
      pytrustnfe/nfse/betha/templates/RecepcionarLoteRps.xml
  4. 2
      pytrustnfe/nfse/betha/templates/RecepcionarLoteRpsSincrono.xml
  5. 2
      pytrustnfe/nfse/betha/templates/SubstituirNfse.xml
  6. 118
      pytrustnfe/test/test_nfse_betha.py

6
pytrustnfe/nfse/betha/__init__.py

@ -32,10 +32,10 @@ def _send(certificado, method, **kwargs):
sign_tag(certificado, **kwargs)
if kwargs['ambiente'] == 'producao':
url = 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'
else:
url = \
'http://e-gov.betha.com.br/e-nota-contribuinte-test-ws/nfseWS?wsdl'
else:
url = 'http://e-gov.betha.com.br/e-nota-contribuinte-ws/nfseWS?wsdl'
xml_send = render_xml(path, '%s.xml' % method, False, **kwargs)
@ -105,7 +105,7 @@ def consultar_nfse_servico_tomado(certificado, **kwargs):
return _send(certificado, 'ConsultarNfseServicoTomado', **kwargs)
def consulta_nfse_faixe(certificado, **kwargs):
def consulta_nfse_faixa(certificado, **kwargs):
return _send(certificado, 'ConsultarNfseFaixa', **kwargs)

2
pytrustnfe/nfse/betha/templates/GerarNfse.xml

@ -1,3 +1,3 @@
<GerarNfseEnvio xmlns = "http://www.betha.com.br/e-nota-contribuinte-ws">
{% include 'rps.xml' %}
{% include 'Rps.xml' %}
</GerarNfseEnvio>

2
pytrustnfe/nfse/betha/templates/RecepcionarLoteRps.xml

@ -7,7 +7,7 @@
<InscricaoMunicipal>123498</InscricaoMunicipal>
<QuantidadeRps>1</QuantidadeRps>
<ListaRps>
{% include 'rps.xml' %}
{% include 'Rps.xml' %}
</ListaRps>
</LoteRps>
</EnviarLoteRpsEnvio>

2
pytrustnfe/nfse/betha/templates/RecepcionarLoteRpsSincrono.xml

@ -7,7 +7,7 @@
<InscricaoMunicipal>123498</InscricaoMunicipal>
<QuantidadeRps>1</QuantidadeRps>
<ListaRps>
{% include 'rps.xml' %}
{% include 'Rps.xml' %}
</ListaRps>
</LoteRps>
</EnviarLoteRpsSincronoEnvio>

2
pytrustnfe/nfse/betha/templates/SubstituirNfse.xml

@ -13,6 +13,6 @@
<CodigoCancelamento>2</CodigoCancelamento>
</InfPedidoCancelamento>
</Pedido>
{% include 'rps.xml' %}
{% include 'Rps.xml' %}
</SubstituicaoNfse>
</SubstituirNfseEnvio>

118
pytrustnfe/test/test_nfse_betha.py

@ -0,0 +1,118 @@
# coding=utf-8
import mock
import os.path
import unittest
from pytrustnfe.certificado import Certificado
from pytrustnfe.nfse.betha import envio_lote_rps
from pytrustnfe.nfse.betha import cancelar_nfse
class test_nfse_betha(unittest.TestCase):
caminho = os.path.dirname(__file__)
def _get_nfse(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'
}
]
nfse = {
'cpf_cnpj': '12345678901234',
'data_inicio': '2016-08-29',
'data_fim': '2016-08-29',
'lista_rps': rps,
'ambiente': 'homologacao',
}
return nfse
def test_envio_nfse_lote(self):
pfx_source = open(os.path.join(self.caminho, 'teste.pfx'), 'r').read()
pfx = Certificado(pfx_source, '123456')
nfse = self._get_nfse()
retorno = envio_lote_rps(pfx, nfse=nfse, ambiente='homologacao')
self.assertEqual(retorno['object'].Cabecalho.Sucesso, True)
self.assertEqual(
retorno['object'].ChaveNFeRPS.ChaveNFe.NumeroNFe, 446)
self.assertEqual(
retorno['object'].ChaveNFeRPS.ChaveRPS.NumeroRPS, 6)
def _get_cancelamento(self):
return {
'cnpj_remetente': '123',
'assinatura': 'assinatura',
'numero_nfse': '456',
'inscricao_municipal': '654',
'codigo_verificacao': '789',
'ambiente': 'homologacao',
}
def test_cancelamento_nfse_ok(self):
pfx_source = open(os.path.join(self.caminho, 'teste.pfx'), 'r').read()
pfx = Certificado(pfx_source, '123456')
cancelamento = self._get_cancelamento()
path = os.path.join(os.path.dirname(__file__), 'XMLs')
xml_return = open(os.path.join(
path, 'paulistana_canc_ok.xml'), 'r').read()
with mock.patch('pytrustnfe.nfse.betha.get_authenticated_client') as client:
retorno = mock.MagicMock()
client.return_value = retorno
retorno.service.CancelarNfse.return_value = xml_return
retorno = cancelar_nfse(pfx, cancelamento=cancelamento,
ambiente='homologacao')
self.assertEqual(retorno['received_xml'], xml_return)
self.assertEqual(retorno['object'].Cabecalho.Sucesso, True)
def test_cancelamento_nfse_com_erro(self):
pfx_source = open(os.path.join(self.caminho, 'teste.pfx'), 'r').read()
pfx = Certificado(pfx_source, '123456')
cancelamento = self._get_cancelamento()
path = os.path.join(os.path.dirname(__file__), 'XMLs')
xml_return = open(os.path.join(
path, 'paulistana_canc_errado.xml'), 'r').read()
with mock.patch('pytrustnfe.nfse.betha.get_authenticated_client') as client:
retorno = mock.MagicMock()
client.return_value = retorno
retorno.service.CancelarNfse.return_value = xml_return
retorno = cancelar_nfse(pfx, cancelamento=cancelamento,
ambiente='homologacao')
self.assertEqual(retorno['received_xml'], xml_return)
self.assertEqual(retorno['object'].Cabecalho.Sucesso, False)
self.assertEqual(
retorno['object'].Erro.ChaveNFe.NumeroNFe, 446)
Loading…
Cancel
Save