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 11, 2024
1 parent 690f7c3 commit e5b0dee
Showing 1 changed file with 4 additions and 4 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"))

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

View check run for this annotation

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L68

Added line #L68 was not covered by tests
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"))

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

View check run for this annotation

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L72

Added line #L72 was not covered by tests

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#L86-L89

Added lines #L86 - L89 were not covered by tests
_("The Record change could not be applied because: %s") % str(e)
) from e
return record

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

View check run for this annotation

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L92

Added line #L92 was not covered by tests
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)

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

View check run for this annotation

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L118-L119

Added lines #L118 - L119 were not covered by tests
if not attachments:
raise ValidationError(_("No attachment was found."))
raise UserError(_("No attachment was found."))

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

View check run for this annotation

Codecov / codecov/patch

printing_auto_base/models/printing_auto.py#L121

Added line #L121 was not covered by tests
return [base64.b64decode(a.datas) for a in attachments]

def _generate_data_from_report(self, record):
Expand Down

0 comments on commit e5b0dee

Please sign in to comment.