Skip to content

Commit

Permalink
multiplos detalhes por consulta de cnpj
Browse files Browse the repository at this point in the history
  • Loading branch information
brunovcosta committed Dec 5, 2024
1 parent b0ce50d commit 9607950
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
24 changes: 19 additions & 5 deletions abstra_notas/nfse/sp/sao_paulo/consulta_cnpj.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
from .pedido import Pedido
from .retorno import Retorno
from dataclasses import dataclass
from lxml.etree import Element, fromstring, ElementBase
from lxml.etree import Element, fromstring, ElementBase, tostring
from abstra_notas.assinatura import Assinador
from typing import Literal
from typing import Literal, List
from abstra_notas.validacoes.cpfcnpj import cpf_ou_cnpj, normalizar_cpf_ou_cnpj
from .remessa import Remessa
from .erro import Erro


@dataclass
class RetornoConsultaCNPJ(Retorno):
class RetornoConsultaCNPJDetalhe:
inscricao_municipal: str
emite_nfe: bool

@staticmethod
def ler_xml(xml: ElementBase) -> "RetornoConsultaCNPJDetalhe":
return RetornoConsultaCNPJDetalhe(
inscricao_municipal=xml.find(".//InscricaoMunicipal").text,
emite_nfe=xml.find(".//EmiteNFe").text == "true",
)


@dataclass
class RetornoConsultaCNPJ(Retorno):
detalhes: List[RetornoConsultaCNPJDetalhe]

@staticmethod
def ler_xml(xml: ElementBase) -> "RetornoConsultaCNPJ":
sucesso = xml.find(".//Sucesso").text == "true"
if sucesso:
return RetornoConsultaCNPJ(
inscricao_municipal=xml.find(".//InscricaoMunicipal").text,
emite_nfe=xml.find(".//EmiteNFe").text == "true",
detalhes=[
RetornoConsultaCNPJDetalhe.ler_xml(detalhe)
for detalhe in xml.findall(".//Detalhe")
]
)
else:
raise ErroConsultaCNPJ(
Expand Down
10 changes: 7 additions & 3 deletions abstra_notas/nfse/sp/sao_paulo/consulta_cnpj_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unittest import TestCase
from .consulta_cnpj import ConsultaCNPJ, RetornoConsultaCNPJ
from .consulta_cnpj import ConsultaCNPJ, RetornoConsultaCNPJ, RetornoConsultaCNPJDetalhe
from pathlib import Path
from lxml.etree import fromstring
from .cliente import ClienteMock
Expand Down Expand Up @@ -30,7 +30,11 @@ def test_exemplo(self):
self.assertEqual(
resultado,
RetornoConsultaCNPJ(
emite_nfe=True,
inscricao_municipal="39616924",
detalhes=[
RetornoConsultaCNPJDetalhe(
emite_nfe=True,
inscricao_municipal="39616924",
)
]
),
)
6 changes: 3 additions & 3 deletions abstra_notas/nfse/sp/sao_paulo/envio_rps.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ def __post_init__(self):
if self.endereco_cep is not None:
self.endereco_cep = normalizar_cep(self.endereco_cep)

assert self.endereco_bairro is None or len(
self.endereco_bairro
) <= 30, "O bairro deve ter no máximo 30 caracteres"
assert (
self.endereco_bairro is None or len(self.endereco_bairro) <= 30
), "O bairro deve ter no máximo 30 caracteres"

if self.endereco_uf is not None:
if isinstance(self.endereco_uf, str):
Expand Down
5 changes: 3 additions & 2 deletions abstra_notas/nfse/sp/sao_paulo/exemplos/consulta_cnpj.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
retorno = cliente.consultar_cnpj(pedido)

try:
print(f"Inscrição Municipal: {retorno.inscricao_municipal}")
print(f"Emite NFe: {retorno.emite_nfe}")
for detalhe in retorno.detalhes:
print(f"Inscrição Municipal: {detalhe.inscricao_municipal}")
print(f"Emite NFe: {detalhe.emite_nfe}")
except Erro as e:
print(f"Código: {e.codigo}")
print(f"Descrição: {e.descricao}")

0 comments on commit 9607950

Please sign in to comment.