From 1fbc0ca3eeac5f0068274054257c9ecfc70428b7 Mon Sep 17 00:00:00 2001 From: Jacques-Etienne Baudoux Date: Fri, 6 Dec 2024 15:43:55 +0100 Subject: [PATCH] [FIX] printing_auto_base: use proper Error --- printing_auto_base/models/printing_auto.py | 8 ++++---- printing_auto_base/tests/test_printing_auto_base.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/printing_auto_base/models/printing_auto.py b/printing_auto_base/models/printing_auto.py index 5f3ed8bf6dc..88a8aaa41e7 100644 --- a/printing_auto_base/models/printing_auto.py +++ b/printing_auto_base/models/printing_auto.py @@ -65,11 +65,11 @@ class PrintingAuto(models.Model): def _check_data_source(self): for rec in self: 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 ( 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): if self.printer_id: @@ -86,7 +86,7 @@ def _get_record(self, record): try: return safe_eval(f"obj.{self.record_change}", {"obj": record}) except Exception as e: - raise ValidationError( + raise UserError( _("The Record change could not be applied because: %s") % str(e) ) from e return record @@ -118,7 +118,7 @@ def _generate_data_from_attachment(self, record): domain = self._prepare_attachment_domain(record) attachments = self.env["ir.attachment"].search(domain) if not attachments: - raise ValidationError(_("No attachment was found.")) + raise UserError(_("No attachment was found.")) return [base64.b64decode(a.datas) for a in attachments] def _generate_data_from_report(self, record): diff --git a/printing_auto_base/tests/test_printing_auto_base.py b/printing_auto_base/tests/test_printing_auto_base.py index fce32e202ed..1c1701bb165 100644 --- a/printing_auto_base/tests/test_printing_auto_base.py +++ b/printing_auto_base/tests/test_printing_auto_base.py @@ -6,7 +6,7 @@ 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 @@ -83,7 +83,7 @@ def test_get_content(self): ) attachment.unlink() - with self.assertRaises(ValidationError): + with self.assertRaises(UserError): printing_auto_attachment._get_content(self.record) def test_do_print(self):