Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] sign method for NFe Paulistana #54

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/erpbrasil/edoc/provedores/paulistana.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import xml.etree.ElementTree as ET

from base64 import b64encode
from erpbrasil.edoc.nfse import NFSe
from erpbrasil.edoc.nfse import ServicoNFSe

Expand Down Expand Up @@ -73,12 +74,13 @@ def __init__(self, transmissao, ambiente, cidade_ibge, cnpj_prestador,
transmissao, ambiente, cidade_ibge, cnpj_prestador, im_prestador)

def _prepara_envia_documento(self, edoc):
assinador = Assinatura(self._transmissao.certificado)
for rps in edoc.RPS:
rps.Assinatura = Assinatura(
self._transmissao.certificado).assina_tag(
rps.Assinatura)
data = rps.Assinatura
data_bytes = data.encode('ascii')
assinatura = assinador.sign_pkcs1v15_sha1(data_bytes)
rps.Assinatura = b64encode(assinatura).decode()
xml_assinado = self.assina_raiz(edoc, '')

return xml_assinado

def _verifica_resposta_envio_sucesso(self, proc_envio):
Expand Down Expand Up @@ -168,11 +170,12 @@ def _prepara_cancelar_nfse_envio(self, doc_numero):
)],
)

assinador = Assinatura(self._transmissao.certificado)
for detalhe in raiz.Detalhe:
detalhe.AssinaturaCancelamento = Assinatura(
self._transmissao.certificado).assina_tag(
detalhe.AssinaturaCancelamento)

data = detalhe.AssinaturaCancelamento
data_bytes = data.encode('ascii')
assinatura = assinador.sign_pkcs1v15_sha1(data_bytes)
detalhe.AssinaturaCancelamento = b64encode(assinatura).decode()
xml_assinado = self.assina_raiz(raiz, '')
return xml_assinado

Expand All @@ -192,4 +195,3 @@ def assina_raiz(self, raiz, id, getchildren=False):
xml_etree
)
return xml_assinado
return xml_assinado.replace('\n', '').replace('\r', '')