Skip to content

Commit a62a0fa

Browse files
committed
[FIX] l10n_uy_ux: enhance EDI sending process with pre-checks and error handling
1 parent 363a5d1 commit a62a0fa

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

l10n_uy_ux/i18n/es_419.po

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ msgstr "Tipo de Documento"
183183
msgid "Electronic Fiscal Document (CFE - UY)"
184184
msgstr "Documento Fiscal Electrónico (CFE - UY)"
185185

186+
#. module: l10n_uy_ux
187+
#. odoo-python
188+
#: code:addons/l10n_uy_ux/models/account_move.py:0
189+
#, python-format
190+
msgid "Errors occurred while evaluating the document: \n"
191+
msgstr "Errores ocurridos al evaluar el documento: \n"
192+
186193
#. module: l10n_uy_ux
187194
#. odoo-python
188195
#: code:addons/l10n_uy_ux/models/account_move.py:0

l10n_uy_ux/models/account_move.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33

44
from lxml import etree
5+
from markupsafe import Markup
56
from odoo import _, api, fields, models
67
from odoo.exceptions import UserError, ValidationError
78
from odoo.tools import safe_eval
@@ -55,6 +56,28 @@ def _l10n_uy_edi_check_move(self):
5556

5657
return errors
5758

59+
def _l10n_uy_edi_send(self):
60+
"""Antes de enviar a DGI, corremos los chequeos previos para atrapar algunos errores conocidos y de fácil configuración.
61+
Si obtenemos alguno, no continuamos con el envío a DGI y en cambio creamos el XML con el error."""
62+
moves_to_send = self
63+
for move in self:
64+
move.l10n_uy_edi_document_id.filtered(lambda doc: doc.state == "error").unlink()
65+
edi_doc = self.env["l10n_uy_edi.document"].create(
66+
{
67+
"move_id": move.id,
68+
"uuid": self.env["l10n_uy_edi.document"]._get_uuid(move),
69+
}
70+
)
71+
move.l10n_uy_edi_document_id = edi_doc
72+
if pre_checks_errors := move._l10n_uy_edi_check_move():
73+
edi_doc.message = self.env._("Errors occurred while evaluating the document: \n") + "\n *".join(
74+
pre_checks_errors
75+
)
76+
edi_doc.state = "error"
77+
moves_to_send -= move
78+
79+
super(AccountMove, moves_to_send)._l10n_uy_edi_send()
80+
5881
def _post(self, soft=True):
5982
"""Extendemos el _post nativo para evitar hacer la confirmación en dos pasos con el wizard de Send & Print.
6083
De esta manera, al clickear en confirmar las facturas automáticamente serán enviadas a DGI y posteadas.
@@ -66,13 +89,12 @@ def _post(self, soft=True):
6689
return res
6790
msg = self.env._("Error al intentar validar el documento en DGI")
6891
for move in res.filtered(lambda m: m.l10n_uy_edi_is_needed):
69-
if pre_checks_errors := move._l10n_uy_edi_check_move():
70-
raise ValidationError(
71-
self.env._("Errors occurred while evaluating the document: \n") + "\n".join(pre_checks_errors)
72-
)
7392
move._l10n_uy_edi_send()
7493
if move.l10n_uy_edi_error:
75-
move.message_post(body=msg + " %s" % (move.l10n_uy_edi_error))
94+
error_msg = Markup("<font style='color:Tomato;'><strong>ERROR:</strong></font> <i>{}</i>").format(
95+
f"{msg}: {move.l10n_uy_edi_error}"
96+
)
97+
move.message_post(body=error_msg, body_is_html=True)
7698
move.button_draft()
7799
res = res - move
78100
return res

0 commit comments

Comments
 (0)