[FIX] printing_auto_base: use proper Error

This commit is contained in:
Jacques-Etienne Baudoux
2024-12-06 15:43:55 +01:00
parent 98218b0462
commit 1fbc0ca3ee
2 changed files with 6 additions and 6 deletions

View File

@@ -65,11 +65,11 @@ class PrintingAuto(models.Model):
def _check_data_source(self): def _check_data_source(self):
for rec in self: for rec in self:
if rec.data_source == "report" and not rec.report_id: if rec.data_source == "report" and not rec.report_id:
raise UserError(_("Report is not set")) raise ValidationError(_("Report is not set"))
if rec.data_source == "attachment" and ( if rec.data_source == "attachment" and (
not rec.attachment_domain or rec.attachment_domain == "[]" not rec.attachment_domain or rec.attachment_domain == "[]"
): ):
raise UserError(_("Attachment domain is not set")) raise ValidationError(_("Attachment domain is not set"))
def _get_behaviour(self): def _get_behaviour(self):
if self.printer_id: if self.printer_id:
@@ -86,7 +86,7 @@ class PrintingAuto(models.Model):
try: try:
return safe_eval(f"obj.{self.record_change}", {"obj": record}) return safe_eval(f"obj.{self.record_change}", {"obj": record})
except Exception as e: except Exception as e:
raise ValidationError( raise UserError(
_("The Record change could not be applied because: %s") % str(e) _("The Record change could not be applied because: %s") % str(e)
) from e ) from e
return record return record
@@ -118,7 +118,7 @@ class PrintingAuto(models.Model):
domain = self._prepare_attachment_domain(record) domain = self._prepare_attachment_domain(record)
attachments = self.env["ir.attachment"].search(domain) attachments = self.env["ir.attachment"].search(domain)
if not attachments: if not attachments:
raise ValidationError(_("No attachment was found.")) raise UserError(_("No attachment was found."))
return [base64.b64decode(a.datas) for a in attachments] return [base64.b64decode(a.datas) for a in attachments]
def _generate_data_from_report(self, record): def _generate_data_from_report(self, record):

View File

@@ -6,7 +6,7 @@ from unittest import mock
from odoo_test_helper import FakeModelLoader from odoo_test_helper import FakeModelLoader
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError
from odoo.addons.base_report_to_printer.models.printing_printer import PrintingPrinter from odoo.addons.base_report_to_printer.models.printing_printer import PrintingPrinter
@@ -83,7 +83,7 @@ class TestPrintingAutoBase(TestPrintingAutoCommon):
) )
attachment.unlink() attachment.unlink()
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
printing_auto_attachment._get_content(self.record) printing_auto_attachment._get_content(self.record)
def test_do_print(self): def test_do_print(self):