Skip to content

Commit

Permalink
[IMP][l10n_br_paulistana] Document Status
Browse files Browse the repository at this point in the history
Signed-off-by: Luis Felipe Miléo <[email protected]>
  • Loading branch information
mileo committed Dec 5, 2024
1 parent 85e3e82 commit 138ad37
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions l10n_br_nfse_paulistana/constants/paulistana.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

CONSULTA_LOTE = [
"ConsultaLote",
"ConsultaNFe",
]
43 changes: 25 additions & 18 deletions l10n_br_nfse_paulistana/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ def _eletronic_document_send(self):
def _document_status(self):
status = super()._document_status()
for record in self.filtered(filter_oca_nfse).filtered(filter_paulistana):
vals = dict()

Check warning on line 387 in l10n_br_nfse_paulistana/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfse_paulistana/models/document.py#L387

Added line #L387 was not covered by tests
processador = record._processador_erpbrasil_nfse()
processo = processador.consulta_nfse_rps(
numero_rps=record.rps_number,
Expand All @@ -394,25 +395,31 @@ def _document_status(self):
or None,
cnpj_prest=misc.punctuation_rm(record.company_id.partner_id.cnpj_cpf),
)

consulta = processador.analisa_retorno_consulta(processo)
data_emissao = datetime.strptime(
consulta["data_emissao"], "%Y-%m-%dT%H:%M:%S"
)
if isinstance(consulta, dict):
record.write(
{
"verify_code": consulta["codigo_verificacao"],
"document_number": consulta["numero"],
"authorization_date": data_emissao,
}
)
record.authorization_event_id.set_done(
status_code=4,
response=_("Procesado com Sucesso"),
protocol_date=data_emissao,
protocol_number=record.authorization_protocol,
file_response_xml=processo.retorno,
)
retorno = ET.fromstring(processo.retorno)

Check warning on line 400 in l10n_br_nfse_paulistana/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfse_paulistana/models/document.py#L400

Added line #L400 was not covered by tests

if processo.webservice in CONSULTA_LOTE:
if processo.resposta.Cabecalho.Sucesso:
nfse = retorno.find(".//NFe")

Check warning on line 404 in l10n_br_nfse_paulistana/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfse_paulistana/models/document.py#L404

Added line #L404 was not covered by tests

vals["document_number"] = nfse.find(".//NumeroNFe").text
vals["authorization_date"] = nfse.find(".//DataEmissaoRPS").text
vals["verify_code"] = nfse.find(".//CodigoVerificacao").text
vals["status_name"] = _("Procesado com Sucesso")
vals["status_code"] = 4
vals["edoc_error_message"] = ""

Check warning on line 411 in l10n_br_nfse_paulistana/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfse_paulistana/models/document.py#L406-L411

Added lines #L406 - L411 were not covered by tests

record.authorization_event_id.set_done(

Check warning on line 413 in l10n_br_nfse_paulistana/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfse_paulistana/models/document.py#L413

Added line #L413 was not covered by tests
status_code=4,
response=vals["status_name"],
protocol_date=vals["authorization_date"],
protocol_number=nfse.find(".//CodigoVerificacao").text,
file_response_xml=processo.retorno,
)

record._change_state(SITUACAO_EDOC_AUTORIZADA)
record.write(vals)

Check warning on line 422 in l10n_br_nfse_paulistana/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfse_paulistana/models/document.py#L421-L422

Added lines #L421 - L422 were not covered by tests
status = _(consulta)
return status

Expand Down

0 comments on commit 138ad37

Please sign in to comment.