Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brunovcosta committed Nov 8, 2024
1 parent 597050e commit dad327f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
14 changes: 5 additions & 9 deletions abstra_notas/nfse/sp/sao_paulo/envio_rps.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from dataclasses import dataclass
from typing import Literal, Union, List
from lxml.etree import Element, fromstring
from lxml.etree import Element, fromstring, tostring
import base64
from abstra_notas.validacoes.email import validar_email
from abstra_notas.validacoes.cidades import validar_codigo_cidade, normalizar_uf
from abstra_notas.validacoes.cpf import normalizar_cpf
from abstra_notas.validacoes.cnpj import normalizar_cnpj
from abstra_notas.validacoes.cpfcnpj import normalizar_cpf_ou_cnpj
from abstra_notas.validacoes.cpfcnpj import normalizar_cpf_ou_cnpj, cpf_ou_cnpj
from .codigos_de_servico import codigos_de_servico_validos
from datetime import date
from .pedido import Pedido
Expand Down Expand Up @@ -46,7 +44,6 @@ def ler_xml(xml: str):
class RetornoEnvioRpsErro:
codigo: int
descricao: str
chave_rps_inscricao_prestador: str

@property
def sucesso(self):
Expand All @@ -57,7 +54,6 @@ def ler_xml(xml: Element):
return RetornoEnvioRPS.RetornoEnvioRpsErro(
codigo=int(xml.find(".//Codigo").text),
descricao=xml.find(".//Descricao").text,
chave_rps_inscricao_prestador=xml.find(".//InscricaoPrestador").text,
)

@staticmethod
Expand Down Expand Up @@ -236,7 +232,7 @@ def assinatura(self, assinador: Assinador) -> str:

@property
def tomador_tipo(self) -> Literal["CPF", "CNPJ"]:
return normalizar_cpf_ou_cnpj(self.tomador)
return cpf_ou_cnpj(self.tomador)


@dataclass
Expand All @@ -262,7 +258,7 @@ def classe_retorno(self):

@property
def remetente_tipo(self) -> Literal["CPF", "CNPJ"]:
return normalizar_cpf_ou_cnpj(self.remetente)
return cpf_ou_cnpj(self.remetente)

def executar(
self, cliente: Cliente
Expand Down Expand Up @@ -313,7 +309,7 @@ def valor_total_deducoes(self):

@property
def remetente_tipo(self) -> Literal["CPF", "CNPJ"]:
return normalizar_cpf_ou_cnpj(self.remetente)
return cpf_ou_cnpj(self.remetente)


class TesteEnvioLoteRps(EnvioLoteRps): ...
11 changes: 8 additions & 3 deletions abstra_notas/nfse/sp/sao_paulo/exemplos/envio_rps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
from datetime import date
from dotenv import load_dotenv
from os import getenv
from pathlib import Path

load_dotenv()


cliente = Cliente(
caminho_pfx=load_dotenv("NFSE_PFX_PATH"), senha_pfx=getenv("NFSE_PFX_PASSWORD")
caminho_pfx=Path(getenv("NFSE_PFX_PATH")), senha_pfx=getenv("NFSE_PFX_PASSWORD")
)

pedido = EnvioRPS(
remetente=getenv("NFSE_CNPJ_REMETENTE"),
tomador=getenv("NFSE_CNPJ_TOMADOR"),
aliquota_servicos=2.0,
aliquota_servicos=0.01,
codigo_servico=1,
data_emissao=date(2021, 1, 1),
endereco_bairro="Bairro",
Expand Down Expand Up @@ -45,4 +46,8 @@

retorno: RetornoEnvioRPS = cliente.executar(pedido)

print(retorno.sucesso)
if retorno.sucesso:
print("RPS enviado com sucesso")
print(retorno)
else:
print(retorno.descricao)
2 changes: 1 addition & 1 deletion abstra_notas/nfse/sp/sao_paulo/templates/EnvioLoteRPS.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<ValorTotalDeducoes>{{ valor_toral_deducoes }}</ValorTotalDeducoes>
</Cabecalho>
{% fo rps in lista_rps %}
{{ rps | safe }}
{{ rps|safe }}
{% endfor %}
</PedidoEnvioLoteRPS>
16 changes: 8 additions & 8 deletions abstra_notas/nfse/sp/sao_paulo/templates/EnvioRPS.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<PedidoEnvioRPS 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 Versao="1" xmlns="">
<CPFCNPJRemetente>
<{{ remetente_tipo }}>{{ remetente }}</{{ remetente_tipo }}>
</CPFCNPJRemetente>
</Cabecalho>
{{ rps | safe }}
<PedidoEnvioRPS 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 Versao="1" xmlns="">
<CPFCNPJRemetente>
<{{ remetente_tipo }}>{{ remetente }}</{{ remetente_tipo }}>
</CPFCNPJRemetente>
</Cabecalho>
{{ rps|safe }}
</PedidoEnvioRPS>

0 comments on commit dad327f

Please sign in to comment.