Skip to content

Commit

Permalink
[FIX] printing_auto_base: use proper Error
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaudoux committed Dec 16, 2024
1 parent 98218b0 commit 1fbc0ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions printing_auto_base/models/printing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(

Check warning on line 89 in printing_auto_base/models/printing_auto.py

View check run for this annotation

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L88-L89

Added lines #L88 - L89 were not covered by tests
_("The Record change could not be applied because: %s") % str(e)
) from e
return record
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions printing_auto_base/tests/test_printing_auto_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1fbc0ca

Please sign in to comment.