22import logging
33
44from lxml import etree
5+ from markupsafe import Markup
56from odoo import _ , api , fields , models
67from odoo .exceptions import UserError , ValidationError
78from 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