13 changed files with 361 additions and 59 deletions
-
8pytrustnfe/Servidores.py
-
157pytrustnfe/nfe/danfe.py
-
32pytrustnfe/nfse/floripa/__init__.py
-
2pytrustnfe/nfse/ginfes/templates/Rps.xml
-
76pytrustnfe/nfse/imperial/__init__.py
-
17pytrustnfe/nfse/imperial/templates/CANCELANOTAELETRONICA.xml
-
9pytrustnfe/nfse/imperial/templates/CONSULTANOTASPROTOCOLO.xml
-
9pytrustnfe/nfse/imperial/templates/CONSULTAPROTOCOLO.xml
-
81pytrustnfe/nfse/imperial/templates/PROCESSARPS.xml
-
5pytrustnfe/nfse/imperial/templates/SoapRequest.xml
-
13pytrustnfe/xml/__init__.py
-
6pytrustnfe/xml/filters.py
-
5setup.py
@ -0,0 +1,76 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Danimar Ribeiro, Trustcode |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
import os |
|||
from lxml import etree |
|||
from pytrustnfe import HttpClient |
|||
from pytrustnfe.xml import render_xml, sanitize_response |
|||
|
|||
|
|||
def _render(certificado, method, **kwargs): |
|||
path = os.path.join(os.path.dirname(__file__), 'templates') |
|||
xml_send = render_xml(path, '%s.xml' % method, True, **kwargs) |
|||
return etree.tostring(xml_send) |
|||
|
|||
|
|||
def _send(certificado, method, **kwargs): |
|||
base_url = '' |
|||
if kwargs['ambiente'] == 'producao': |
|||
base_url = 'https://nfe.etransparencia.com.br/rj.petropolis/webservice/aws_nfe.aspx' # noqa |
|||
else: |
|||
base_url = 'https://nfehomologacao.etransparencia.com.br/rj.petropolis/webservice/aws_nfe.aspx' # noqa |
|||
|
|||
xml_send = kwargs["xml"] |
|||
path = os.path.join(os.path.dirname(__file__), 'templates') |
|||
soap = render_xml(path, 'SoapRequest.xml', False, soap_body=xml_send) |
|||
|
|||
client = HttpClient(base_url) |
|||
response = client.post_soap(soap, 'NFeaction/AWS_NFE.%s' % method) |
|||
|
|||
response, obj = sanitize_response(response) |
|||
return { |
|||
'sent_xml': xml_send, |
|||
'received_xml': response, |
|||
'object': obj |
|||
} |
|||
|
|||
|
|||
def xml_processa_rps(certificado, **kwargs): |
|||
return _render(certificado, 'PROCESSARPS', **kwargs) |
|||
|
|||
|
|||
def processa_rps(certificado, **kwargs): |
|||
if "xml" not in kwargs: |
|||
kwargs['xml'] = xml_processa_rps(certificado, **kwargs) |
|||
return _send(certificado, 'PROCESSARPS', **kwargs) |
|||
|
|||
|
|||
def xml_consulta_protocolo(certificado, **kwargs): |
|||
return _render(certificado, 'CONSULTAPROTOCOLO', **kwargs) |
|||
|
|||
|
|||
def consulta_protocolo(certificado, **kwargs): |
|||
if "xml" not in kwargs: |
|||
kwargs['xml'] = xml_consulta_protocolo(certificado, **kwargs) |
|||
return _send(certificado, 'CONSULTAPROTOCOLO', **kwargs) |
|||
|
|||
|
|||
def xml_consulta_notas_protocolo(certificado, **kwargs): |
|||
return _render(certificado, 'CONSULTANOTASPROTOCOLO', **kwargs) |
|||
|
|||
|
|||
def consulta_notas_protocolo(certificado, **kwargs): |
|||
if "xml" not in kwargs: |
|||
kwargs['xml'] = xml_consulta_notas_protocolo(certificado, **kwargs) |
|||
return _send(certificado, 'CONSULTANOTASPROTOCOLO', **kwargs) |
|||
|
|||
|
|||
def xml_cancelar_nfse(certificado, **kwargs): |
|||
return _render(certificado, 'CANCELANOTAELETRONICA', **kwargs) |
|||
|
|||
|
|||
def cancelar_nfse(certificado, **kwargs): |
|||
if "xml" not in kwargs: |
|||
kwargs['xml'] = xml_cancelar_nfse(certificado, **kwargs) |
|||
return _send(certificado, 'CANCELANOTAELETRONICA', **kwargs) |
|||
@ -0,0 +1,17 @@ |
|||
<ws_nfe.CANCELANOTAELETRONICA xmlns="NFe"> |
|||
<Sdt_cancelanfe> |
|||
<Login> |
|||
<CodigoUsuario>{{ cancelamento.codigo_usuario }}</CodigoUsuario> |
|||
<CodigoContribuinte>{{ cancelamento.codigo_contribuinte }}</CodigoContribuinte> |
|||
</Login> |
|||
<Nota> |
|||
<SerieNota>{{ cancelamento.serie_nota }}</SerieNota> |
|||
<NumeroNota>{{ cancelamento.numero_nota }}</NumeroNota> |
|||
<SerieRPS>{{ cancelamento.serie_rps }}</SerieRPS> |
|||
<NumeroRps>{{ cancelamento.numero_rps }}</NumeroRps> |
|||
<ValorNota>{{ cancelamento.valor }}</ValorNota> |
|||
<MotivoCancelamento>{{ cancelamento.motivo }}</MotivoCancelamento> |
|||
<PodeCancelarGuia>{{ cancelamento.cancelar_guia }}</PodeCancelarGuia> |
|||
</Nota> |
|||
</Sdt_cancelanfe> |
|||
</ws_nfe.CANCELANOTAELETRONICA> |
|||
@ -0,0 +1,9 @@ |
|||
<ws_nfe.CONSULTANOTASPROTOCOLO xmlns="NFe"> |
|||
<Sdt_consultanotasprotocoloin> |
|||
<Protocolo>{{ consulta.protocolo }}</Protocolo> |
|||
<Login> |
|||
<CodigoUsuario>{{ consulta.codigo_usuario }}</CodigoUsuario> |
|||
<CodigoContribuinte>{{ consulta.codigo_contribuinte }}</CodigoContribuinte> |
|||
</Login> |
|||
</Sdt_consultanotasprotocoloin> |
|||
</ws_nfe.CONSULTANOTASPROTOCOLO> |
|||
@ -0,0 +1,9 @@ |
|||
<ws_nfe.CONSULTAPROTOCOLO xmlns="NFe"> |
|||
<Sdt_consultaprotocoloin> |
|||
<Protocolo>{{ consulta.protocolo }}</Protocolo> |
|||
<Login> |
|||
<CodigoUsuario>{{ consulta.codigo_usuario }}</CodigoUsuario> |
|||
<CodigoContribuinte>{{ consulta.codigo_contribuinte }}</CodigoContribuinte> |
|||
</Login> |
|||
</Sdt_consultaprotocoloin> |
|||
</ws_nfe.CONSULTAPROTOCOLO> |
|||
@ -0,0 +1,81 @@ |
|||
<ws_nfe.PROCESSARPS xmlns="NFe"> |
|||
<Sdt_processarpsin> |
|||
<Login> |
|||
<CodigoUsuario>{{ nfse.codigo_usuario }}</CodigoUsuario> |
|||
<CodigoContribuinte>{{ nfse.codigo_contribuinte }}</CodigoContribuinte> |
|||
</Login> |
|||
<SDTRPS> |
|||
<Ano>{{ nfse.ano }}</Ano> |
|||
<Mes>{{ nfse.mes }}</Mes> |
|||
<CPFCNPJ>{{ nfse.cnpj_prestador }}</CPFCNPJ> |
|||
<DTIni>{{ nfse.data_emissao }}</DTIni> |
|||
<DTFin>{{ nfse.data_emissao }}</DTFin> |
|||
<TipoTrib>{{ nfse.tipo_tributacao }}</TipoTrib> |
|||
<DtAdeSN>{{ nfse.data_adesao_simples }}</DtAdeSN> |
|||
<AlqIssSN_IP>{{ nfse.aliquota_simples_isencao|comma }}</AlqIssSN_IP> |
|||
<Versao>2.00</Versao> |
|||
{% for rps in nfse.lista_rps -%} |
|||
<Reg20> |
|||
<!-- Optional --> |
|||
<Reg20Item> |
|||
<TipoNFS>{{ rps.tipo_nfse }}</TipoNFS> |
|||
<NumRps>{{ rps.numero }}</NumRps> |
|||
<SerRps>{{ rps.serie }}</SerRps> |
|||
<DtEmi>{{ rps.data_emissao }}</DtEmi> |
|||
<RetFonte>{{ rps.iss_retido }}</RetFonte> |
|||
<CodSrv>{{ rps.codigo_servico }}</CodSrv> |
|||
<DiscrSrv>{{ rps.descricao}}</DiscrSrv> |
|||
<VlNFS>{{ rps.valor_liquido_nfse|comma }}</VlNFS> |
|||
<VlDed>{{ rps.valor_deducao|comma }}</VlDed> |
|||
<DiscrDed>{{ rps.discriminacao_deducao }}</DiscrDed> |
|||
<VlBasCalc>{{ rps.base_calculo|comma }}</VlBasCalc> |
|||
<AlqIss>{{ rps.aliquota_issqn|comma }}</AlqIss> |
|||
<VlIss>{{ rps.valor_iss|comma }}</VlIss> |
|||
<VlIssRet>{{ rps.valor_iss_retido|comma }}</VlIssRet> |
|||
<CpfCnpTom>{{ rps.tomador.cnpj_cpf }}</CpfCnpTom> |
|||
<RazSocTom>{{ rps.tomador.razao_social }}</RazSocTom> |
|||
<TipoLogtom>{{ rps.tomador.tipo_logradouro }}</TipoLogtom> |
|||
<LogTom>{{ rps.tomador.logradouro }}</LogTom> |
|||
<NumEndTom>{{ rps.tomador.numero }}</NumEndTom> |
|||
<ComplEndTom>{{ rps.tomador.complemento }}</ComplEndTom> |
|||
<BairroTom>{{ rps.tomador.bairro }}</BairroTom> |
|||
<MunTom>{{ rps.tomador.municipio }}</MunTom> |
|||
<SiglaUFTom>{{ rps.tomador.uf }}</SiglaUFTom> |
|||
<CepTom>{{ rps.tomador.cep }}</CepTom> |
|||
<Telefone>{{ rps.tomador.telefone }}</Telefone> |
|||
<InscricaoMunicipal>{{ rps.tomador.inscricao_municipal }}</InscricaoMunicipal> |
|||
{% if rps.local_prestacao == 'prestador' %} |
|||
<TipoLogLocPre>{{ rps.prestador.tipo_logradouro }}</TipoLogLocPre> |
|||
<LogLocPre>{{ rps.prestador.logradouro }}</LogLocPre> |
|||
<NumEndLocPre>{{ rps.prestador.numero }}</NumEndLocPre> |
|||
<ComplEndLocPre>{{ rps.prestador.complemento }}</ComplEndLocPre> |
|||
<BairroLocPre>{{ rps.prestador.bairro }}</BairroLocPre> |
|||
<MunLocPre>{{ rps.prestador.municipio }}</MunLocPre> |
|||
<SiglaUFLocpre>{{ rps.prestador.uf }}</SiglaUFLocpre> |
|||
<CepLocPre>{{ rps.prestador.cep }}</CepLocPre> |
|||
{% endif %} |
|||
<Email1>{{ rps.tomador.email }}</Email1> |
|||
{% for imposto in rps.impostos -%} |
|||
<Reg30> |
|||
<Reg30Item> |
|||
<TributoSigla>{{ imposto.sigla }}</TributoSigla> |
|||
<TributoAliquota>{{ imposto.aliquota|comma }}</TributoAliquota> |
|||
<TributoValor>{{ imposto.valor|comma }}</TributoValor> |
|||
</Reg30Item> |
|||
</Reg30> |
|||
{% endfor %} |
|||
</Reg20Item> |
|||
</Reg20> |
|||
{% endfor %} |
|||
<Reg90> |
|||
<QtdRegNormal>{{ nfse.lista_rps|length }}</QtdRegNormal> |
|||
<ValorNFS>{{ nfse.lista_rps|sum(attribute='valor_liquido_nfse')|comma }}</ValorNFS> |
|||
<ValorISS>{{ nfse.lista_rps|sum(attribute='valor_iss')|comma }}</ValorISS> |
|||
<ValorDed>{{ nfse.lista_rps|sum(attribute='valor_deducao')|comma }}</ValorDed> |
|||
<ValorIssRetTom>{{ nfse.lista_rps|sum(attribute='valor_iss_retido')|comma }}</ValorIssRetTom> |
|||
<QtdReg30>{{ nfse.quantidade_impostos }}</QtdReg30> |
|||
<ValorTributos>{{ nfse.valor_tributos|comma }}</ValorTributos> |
|||
</Reg90> |
|||
</SDTRPS> |
|||
</Sdt_processarpsin> |
|||
</ws_nfe.PROCESSARPS> |
|||
@ -0,0 +1,5 @@ |
|||
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> |
|||
<Body> |
|||
{{ soap_body }} |
|||
</Body> |
|||
</Envelope> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue