Skip to content
Snippets Groups Projects
Commit d73a6261 authored by Abdelouahab (abla)'s avatar Abdelouahab (abla)
Browse files

[FIX] account: do not add banner on corrupted PDF

To reproduce
============
- create a vendor Bill
- add the PDF (from ticket attached files) in chatter
- go back to list view and select the bill -> print Original Bills
a traceback is raised

Problem
=======
for some excptional PDF files (like the one attached in the ticket),
the library PyPDF2 that  we use to manage PDF files crashes.

Solution
========
a [fix](https://github.com/odoo/odoo/commit/e55196375aa124558b87ebd50012d5664295ca07

) was backported from 16 and updated
so that we don't block the flow, we let a message on chatter that there was an error and we ignore adding the banner.

opw-3141143

closes odoo/odoo#112454

X-original-commit: 1ce5ba7d627a4082e3b6f4736fcb45fab63d1388
Signed-off-by: default avatarJohn Laterre (jol) <jol@odoo.com>
Signed-off-by: default avatarabla001 <abla@odoo.com>
parent 7b9dd53a
Branches
Tags
No related merge requests found
......@@ -13992,6 +13992,14 @@ msgstr ""
msgid "There was an error processing this page."
msgstr ""
 
#. module: account
#: code:addons/account/models/ir_actions_report.py:0
#, python-format
msgid ""
"There was an error when trying to add the banner to the original PDF.\n"
"Please make sure the source file is valid."
msgstr ""
#. module: account
#: model_terms:ir.ui.view,arch_db:account.res_config_settings_view_form
msgid "These taxes are set in any new product created."
......
......@@ -2,6 +2,7 @@
import io
import textwrap
from collections import OrderedDict
from PyPDF2.utils import PdfStreamError
from odoo import models, _
from odoo.exceptions import UserError
......@@ -33,10 +34,10 @@ class IrActionsReport(models.Model):
record = self.env[attachment.res_model].browse(attachment.res_id)
try:
stream = pdf.add_banner(stream, record.name, logo=True)
except ValueError:
raise UserError(_(
"Error when reading the original PDF for: %r.\nPlease make sure the file is valid.",
textwrap.shorten(record.name, width=100)
except (ValueError, PdfStreamError):
record._message_log(body=_(
"There was an error when trying to add the banner to the original PDF.\n"
"Please make sure the source file is valid."
))
collected_streams[invoice.id] = {
'stream': stream,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment