Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
210 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# © 2019 Danimar Ribeiro, Trustcode | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
import os | ||
from requests import Session | ||
from zeep import Client | ||
from zeep.transports import Transport | ||
from requests.packages.urllib3 import disable_warnings | ||
|
||
from pytrustnfe.xml import render_xml, sanitize_response | ||
from pytrustnfe.certificado import extract_cert_and_key_from_pfx, save_cert_key | ||
from pytrustnfe.nfe.assinatura import Assinatura | ||
|
||
|
||
def _render(certificado, method, **kwargs): | ||
path = os.path.join(os.path.dirname(__file__), 'templates') | ||
xml_send = render_xml(path, '%s.xml' % method, True, **kwargs) | ||
|
||
reference = '' | ||
signer = Assinatura(certificado.pfx, certificado.password) | ||
xml_send = signer.assina_xml(xml_send, reference) | ||
return xml_send | ||
|
||
|
||
def _send(certificado, method, **kwargs): | ||
base_url = '' | ||
if kwargs['ambiente'] == 'producao': | ||
base_url = 'https://aparecida.siltecnologia.com.br/tbw/services/Abrasf10?wsdl' | ||
else: | ||
base_url = 'https://aparecida.siltecnologia.com.br/tbwhomologacao/services/Abrasf10?wsdl' | ||
|
||
cert, key = extract_cert_and_key_from_pfx( | ||
certificado.pfx, certificado.password) | ||
cert, key = save_cert_key(cert, key) | ||
|
||
disable_warnings() | ||
session = Session() | ||
session.cert = (cert, key) | ||
session.verify = False | ||
transport = Transport(session=session) | ||
|
||
client = Client(base_url, transport=transport) | ||
|
||
xml_send = kwargs['xml'] | ||
response = client.service[method](xml_send) | ||
response, obj = sanitize_response(response) | ||
return { | ||
'sent_xml': xml_send, | ||
'received_xml': response, | ||
'object': obj | ||
} | ||
|
||
|
||
def xml_recepcionar_lote_rps(certificado, **kwargs): | ||
return _render(certificado, 'recepcionarLoteRps', **kwargs) | ||
|
||
|
||
def recepcionar_lote_rps(certificado, **kwargs): | ||
if "xml" not in kwargs: | ||
kwargs['xml'] = xml_recepcionar_lote_rps(certificado, **kwargs) | ||
return _send(certificado, 'recepcionarLoteRps', **kwargs) | ||
|
||
|
||
def xml_consultar_lote_rps(certificado, **kwargs): | ||
return _render(certificado, 'consultarLoteRps', **kwargs) | ||
|
||
|
||
def consultar_lote_rps(certificado, **kwargs): | ||
if "xml" not in kwargs: | ||
kwargs['xml'] = xml_consultar_lote_rps(certificado, **kwargs) | ||
return _send(certificado, 'consultarLoteRps', **kwargs) | ||
|
||
|
||
def xml_cancelar_nfse(certificado, **kwargs): | ||
return _render(certificado, 'cancelarNfse', **kwargs) | ||
|
||
|
||
def cancelar_nfse(certificado, **kwargs): | ||
if "xml" not in kwargs: | ||
kwargs['xml'] = xml_cancelar_nfse(certificado, **kwargs) | ||
return _send(certificado, 'cancelarNfse', **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<Rps> | ||
<InfRps Id="rps{{ rps.numero }}"> | ||
<IdentificacaoRps> | ||
<Numero>{{ rps.numero }}</Numero> | ||
<Serie>{{ rps.serie }}</Serie> | ||
<Tipo>{{ rps.tipo_rps }}</Tipo> | ||
</IdentificacaoRps> | ||
<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>{{ rps.numero_substituido }}</Numero> | ||
<Serie>{{ rps.serie_substituido }}</Serie> | ||
<Tipo>{{ rps.tipo_substituido }}</Tipo> | ||
</RpsSubstituido> | ||
<Servico> | ||
<Valores> | ||
<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_issqn }}</Aliquota> | ||
<ValorLiquidoNfse>{{ rps.valor_liquido_nfse }}</ValorLiquidoNfse> | ||
<DescontoIncondicionado>{{ rps.desconto_incondicionado }}</DescontoIncondicionado> | ||
<DescontoCondicionado>{{ rps.desconto_condicionado }}</DescontoCondicionado> | ||
</Valores> | ||
<ItemListaServico>{{ rps.codigo_servico }}</ItemListaServico> | ||
<CodigoCnae>{{ rps.cnae_servico }}</CodigoCnae> | ||
<CodigoTributacaoMunicipio>{{ rps.codigo_tributacao_municipio }}</CodigoTributacaoMunicipio> | ||
<Discriminacao>{{ rps.descricao }}</Discriminacao> | ||
<CodigoMunicipio>{{ rps.codigo_municipio }}</CodigoMunicipio> | ||
</Servico> | ||
<Prestador> | ||
<Cnpj>{{ rps.prestador.cnpj }}</Cnpj> | ||
<InscricaoMunicipal>{{ rps.prestador.inscricao_municipal }}</InscricaoMunicipal> | ||
</Prestador> | ||
<Tomador> | ||
<IdentificacaoTomador> | ||
<CpfCnpj> | ||
{% if rps.tomador.cnpj_cpf|length == 14 %} | ||
<Cnpj>{{ rps.tomador.cnpj_cpf }}</Cnpj> | ||
{% endif %} | ||
{% if rps.tomador.cnpj_cpf|length == 11 %} | ||
<Cpf>{{ rps.tomador.cnpj_cpf }}</Cpf> | ||
{% endif %} | ||
</CpfCnpj> | ||
<InscricaoMunicipal>{{ rps.tomador.inscricao_municipal }}</InscricaoMunicipal> | ||
</IdentificacaoTomador> | ||
<RazaoSocial>{{ rps.tomador.razao_social }}</RazaoSocial> | ||
<Endereco> | ||
<Endereco>{{ rps.tomador.logradouro }}</Endereco> | ||
<Numero>{{ rps.tomador.numero }}</Numero> | ||
<Complemento>{{ rps.tomador.complemento }}</Complemento> | ||
<Bairro>{{ rps.tomador.bairro }}</Bairro> | ||
<CodigoMunicipio>{{ rps.tomador.cidade }}</CodigoMunicipio> | ||
<Uf>{{ rps.tomador.uf }}</Uf> | ||
<Cep>{{ rps.tomador.cep }}</Cep> | ||
</Endereco> | ||
<Contato> | ||
<Telefone>{{ rps.tomador.telefone }}</Telefone> | ||
<Email>{{ rps.tomador.email }}</Email> | ||
</Contato> | ||
</Tomador> | ||
{% if rps.intermediario is defined -%} | ||
<IntermediarioServico> | ||
<RazaoSocial>{{ rps.intermediario.razao_social }}</RazaoSocial> | ||
<CpfCnpj> | ||
<Cnpj>{{ rps.intermediario.cnpj }}</Cnpj> | ||
</CpfCnpj> | ||
<InscricaoMunicipal>{{ rps.intermediario.inscricao_municipal }}</InscricaoMunicipal> | ||
</IntermediarioServico> | ||
{% 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<CancelarNfseEnvio xmlns="http://nfse.abrasf.org.br"> | ||
<Pedido> | ||
<InfPedidoCancelamento Id="1"> | ||
<IdentificacaoNfse> | ||
<Numero>{{ cancelamento.numero_nfse }}</Numero> | ||
<CpfCnpj> | ||
<Cnpj>{{ cancelamento.cnpj_prestador }}</Cnpj> | ||
</CpfCnpj> | ||
<InscricaoMunicipal>{{ cancelamento.inscricao_municipal }}</InscricaoMunicipal> | ||
<CodigoMunicipio>{{ cancelamento.cidade }}</CodigoMunicipio> | ||
</IdentificacaoNfse> | ||
<CodigoCancelamento>{{ cancelamento.codigo_cancelamento }}</CodigoCancelamento> | ||
</InfPedidoCancelamento> | ||
</Pedido> | ||
</CancelarNfseEnvio> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<ConsultarLoteRpsEnvio xmlns="http://nfse.abrasf.org.br"> | ||
<Prestador> | ||
<Cnpj>{{ consulta.cnpj_prestador }}</Cnpj> | ||
<InscricaoMunicipal>{{ consulta.inscricao_municipal }}</InscricaoMunicipal> | ||
</Prestador> | ||
<Protocolo>{{ consulta.protocolo }}</Protocolo> | ||
</ConsultarLoteRpsEnvio> |
13 changes: 13 additions & 0 deletions
13
pytrustnfe/nfse/aparecida/templates/recepcionarLoteRps.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<EnviarLoteRpsEnvio> | ||
<LoteRps Id="lote{{ nfse.numero_lote }}"> | ||
<NumeroLote>{{ nfse.numero_lote }}</NumeroLote> | ||
<Cnpj>{{ nfse.cnpj_prestador }}</Cnpj> | ||
<InscricaoMunicipal>{{ nfse.inscricao_municipal }}</InscricaoMunicipal> | ||
<QuantidadeRps>{{ nfse.lista_rps|length }}</QuantidadeRps> | ||
<ListaRps> | ||
{% for rps in nfse.lista_rps -%} | ||
{% include 'Rps.xml' %} | ||
{% endfor %} | ||
</ListaRps> | ||
</LoteRps> | ||
</EnviarLoteRpsEnvio> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters