From 486d2ad1d907680c46d31549ea4b853cf9e3b2fe Mon Sep 17 00:00:00 2001 From: Flavyo Henrique Date: Tue, 5 Jan 2021 11:03:02 -0300 Subject: [PATCH] =?UTF-8?q?-=20Adicionado=20consulta=20do=20RPS=20para=20a?= =?UTF-8?q?=20prefeitura=20de=20Goi=C3=A2nia/GO.=20-=20Colocado=20como=20o?= =?UTF-8?q?pcional=20a=20tag=20endere=C3=A7o=20na=20gera=C3=A7=C3=A3o=20do?= =?UTF-8?q?=20rps=20conforme=20manual=20da=20prefeitura.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytrustnfe/nfse/goiania/__init__.py | 26 ++++++++++++++-------- .../nfse/goiania/templates/ConsultarNfseRps.xml | 19 ++++++++++++++++ pytrustnfe/nfse/goiania/templates/Rps.xml | 2 ++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 pytrustnfe/nfse/goiania/templates/ConsultarNfseRps.xml diff --git a/pytrustnfe/nfse/goiania/__init__.py b/pytrustnfe/nfse/goiania/__init__.py index 832f1d9..ed790fa 100644 --- a/pytrustnfe/nfse/goiania/__init__.py +++ b/pytrustnfe/nfse/goiania/__init__.py @@ -10,6 +10,9 @@ from pytrustnfe.xml import render_xml, sanitize_response from .assinatura import Assinatura +NAMESPACE = './/{http://nfse.goiania.go.gov.br/xsd/nfse_gyn_v02.xsd}' + + def _render(certificado, method, **kwargs): path = os.path.join(os.path.dirname(__file__), "templates") xml_send = render_xml(path, f"{method}.xml", False, **kwargs) @@ -39,16 +42,22 @@ def _send(certificado, method, **kwargs): return {"send_xml": str(xml_send), "received_xml": str(response), "object": obj} -def xml_gerar_nfse(certificado, **kwargs): - return _render(certificado, "GerarNfse", **kwargs) - - def gerar_nfse(certificado, **kwargs): + """" Gera uma NFSe de saída """ + if "xml" not in kwargs: - kwargs["xml"] = xml_gerar_nfse(certificado, **kwargs) + kwargs["xml"] = _render(certificado, "GerarNfse", **kwargs) return _send(certificado, "GerarNfse", **kwargs) +def consulta_nfse_por_rps(certificado, **kwargs): + """ Consulta os dados de um NFSe já emitida """ + + if "xml" not in kwargs: + kwargs["xml"] = _render(certificado, "ConsultarNfseRps", **kwargs) + return _send(certificado, "ConsultarNfseRps", **kwargs) + + def split_result(xml_received: str): """ Retorna o código e a mensagem de retorno vindo do webservice """ @@ -57,10 +66,9 @@ def split_result(xml_received: str): if xml is None: return None, None - ns = './/{http://nfse.goiania.go.gov.br/xsd/nfse_gyn_v02.xsd}' - msg_return = xml.find(f'{ns}MensagemRetorno') - code = msg_return.find(f"{ns}Codigo").text - msg = msg_return.find(f"{ns}Mensagem").text + msg_return = xml.find(f'{NAMESPACE}MensagemRetorno') + code = msg_return.find(f"{NAMESPACE}Codigo").text + msg = msg_return.find(f"{NAMESPACE}Mensagem").text return code, msg diff --git a/pytrustnfe/nfse/goiania/templates/ConsultarNfseRps.xml b/pytrustnfe/nfse/goiania/templates/ConsultarNfseRps.xml new file mode 100644 index 0000000..32085c3 --- /dev/null +++ b/pytrustnfe/nfse/goiania/templates/ConsultarNfseRps.xml @@ -0,0 +1,19 @@ + + + + {{ numero }} + {{ serie }} + {{ tipo }} + + + + {% if cnpj_cpf|length == 14 %} + {{ cnpj_cpf }} + {% endif %} + {% if cnpj_cpf|length == 11 %} + {{ cnpj_cpf }} + {% endif %} + + {{ inscricao_municipal }} + + diff --git a/pytrustnfe/nfse/goiania/templates/Rps.xml b/pytrustnfe/nfse/goiania/templates/Rps.xml index e4785f9..8160243 100644 --- a/pytrustnfe/nfse/goiania/templates/Rps.xml +++ b/pytrustnfe/nfse/goiania/templates/Rps.xml @@ -47,6 +47,7 @@ {% endif %} {{ tomador.razao_social }} + {% if tomador.endereco %} {{ tomador.endereco.rua }} {{ tomador.endereco.numero }} @@ -55,6 +56,7 @@ {{ tomador.endereco.codigo_municipio }} {{ tomador.endereco.uf }} + {% endif %}