Skip to content

[FIX] l10n_uy_ux: enhance EDI sending process with pre-checks and error handling#390

Closed
jue-adhoc wants to merge 1 commit intoingadhoc:18.0from
adhoc-dev:18.0-t-63018-jue
Closed

[FIX] l10n_uy_ux: enhance EDI sending process with pre-checks and error handling#390
jue-adhoc wants to merge 1 commit intoingadhoc:18.0from
adhoc-dev:18.0-t-63018-jue

Conversation

@jue-adhoc
Copy link
Copy Markdown
Contributor

@jue-adhoc jue-adhoc commented Jan 26, 2026

Realizamos estos cambios para no levantar un raise con el error, que puede dar problemas en procesos automáticos de facturación. De esta manera, en lugar del pop-up veremos el banner tal como sucedía anteriormente con el wizard de Send & Print.
image

Copilot AI review requested due to automatic review settings January 26, 2026 14:54
@roboadhoc
Copy link
Copy Markdown
Contributor

Pull request status dashboard

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Este PR ajusta el flujo de envío EDI para Uruguay para evitar que los errores de pre-chequeos disparen raise (problemático en procesos automáticos) y, en su lugar, registrar el error en el documento EDI / chatter para que se visualice como banner.

Changes:

  • Se agrega un override de _l10n_uy_edi_send() que corre pre-checks y, si fallan, crea/setea un l10n_uy_edi.document en estado error sin continuar el envío a DGI.
  • Se elimina el ValidationError en _post() y se postea un mensaje de error en el chatter con formato HTML.

Comment thread l10n_uy_ux/models/account_move.py
Comment thread l10n_uy_ux/models/account_move.py
Comment thread l10n_uy_ux/models/account_move.py Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Si obtenemos alguno, no continuamos con el envío a DGI y en cambio creamos el XML con el error."""
moves_to_send = self
for move in self:
move.l10n_uy_edi_document_id.filtered(lambda doc: doc.state == "error").unlink()
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En este punto el .unlink() sobre documentos en estado error probablemente no elimina nada: en l10n_uy_ux/models/l10n_uy_edi_document.py el unlink() está sobreescrito para preservar documentos con message/l10n_uy_edi_error, por lo que acá quedarían documentos huérfanos. Alternativas: eliminar esta línea si se quiere preservar historial, o permitir el borrado explícito vía context (p.ej. allow_unlink_error_docs) y respetarlo en el override de unlink().

Suggested change
move.l10n_uy_edi_document_id.filtered(lambda doc: doc.state == "error").unlink()
move.l10n_uy_edi_document_id.filtered(lambda doc: doc.state == "error").with_context(
allow_unlink_error_docs=True
).unlink()

Copilot uses AI. Check for mistakes.
Comment on lines +73 to +74
edi_doc.message = self.env._("Errors occurred while evaluating the document: \n") + "\n *".join(
pre_checks_errors
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La construcción del mensaje arma el listado de errores con "\n *".join(...), lo que deja el primer error sin viñeta (queda pegado al header) y sin espacio consistente. Para que el formato sea estable, conviene prefijar el listado con \n * y luego hacer el join con el mismo separador.

Suggested change
edi_doc.message = self.env._("Errors occurred while evaluating the document: \n") + "\n *".join(
pre_checks_errors
edi_doc.message = (
self.env._("Errors occurred while evaluating the document: \n")
+ "\n * "
+ "\n * ".join(pre_checks_errors)

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +97
error_msg = Markup("<font style='color:Tomato;'><strong>ERROR:</strong></font> <i>{}</i>").format(
f"{msg}: {move.l10n_uy_edi_error}"
)
move.message_post(body=error_msg, body_is_html=True)
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El banner agrega el literal "ERROR:" hardcodeado en inglés y en HTML. Si esto es visible al usuario, debería ser traducible (p.ej. usando _()/env._()) para no mezclar idiomas en el chatter/banner.

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +79
def _l10n_uy_edi_send(self):
"""Antes de enviar a DGI, corremos los chequeos previos para atrapar algunos errores conocidos y de fácil configuración.
Si obtenemos alguno, no continuamos con el envío a DGI y en cambio creamos el XML con el error."""
moves_to_send = self
for move in self:
move.l10n_uy_edi_document_id.filtered(lambda doc: doc.state == "error").unlink()
edi_doc = self.env["l10n_uy_edi.document"].create(
{
"move_id": move.id,
"uuid": self.env["l10n_uy_edi.document"]._get_uuid(move),
}
)
move.l10n_uy_edi_document_id = edi_doc
if pre_checks_errors := move._l10n_uy_edi_check_move():
edi_doc.message = self.env._("Errors occurred while evaluating the document: \n") + "\n *".join(
pre_checks_errors
)
edi_doc.state = "error"
moves_to_send -= move

super(AccountMove, moves_to_send)._l10n_uy_edi_send()
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este cambio modifica el flujo de posteo/envío: ya no se levanta ValidationError en pre-checks y en su lugar se crea un l10n_uy_edi.document en state='error' y se revierte a borrador. Hay tests en l10n_uy_ux/tests, pero no hay cobertura para este nuevo comportamiento; estaría bueno agregar un test que fuerce un error de _l10n_uy_edi_check_move() y verifique que no se raisea excepción, que se crea el documento EDI con mensaje y que el move queda fuera de res.

Copilot generated this review using guidance from repository custom instructions.
Comment thread l10n_uy_ux/i18n/es_419.po
Comment on lines +186 to +192
#. module: l10n_uy_ux
#. odoo-python
#: code:addons/l10n_uy_ux/models/account_move.py:0
#, python-format
msgid "Errors occurred while evaluating the document: \n"
msgstr "Errores ocurridos al evaluar el documento: \n"

Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se agregó la traducción solo en es_419.po, pero el mismo msgid no está presente en l10n_uy_ux/i18n/es.po. Si están manteniendo ambos catálogos, convendría exportar/actualizar también es.po (aunque sea con msgstr vacío) para que no quede desincronizado.

Copilot uses AI. Check for mistakes.
@pablohmontenegro
Copy link
Copy Markdown
Contributor

@roboadhoc r+

roboadhoc pushed a commit that referenced this pull request Jan 27, 2026
…or handling

closes #390

Signed-off-by: Pablo Montenegro - pam (#l10n) <pam@adhoc.com.ar>
@roboadhoc roboadhoc closed this Jan 27, 2026
@roboadhoc roboadhoc deleted the 18.0-t-63018-jue branch January 27, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants