diff options
| author | Benjamin Frantzen (bfr) <bfr@odoo.com> | 2020-06-10 17:03:10 +0000 |
|---|---|---|
| committer | Benjamin Frantzen (bfr) <bfr@odoo.com> | 2020-06-18 16:49:32 +0000 |
| commit | ae15f89f73cffaebd20ba74b9c20ad641a1ea5e4 (patch) | |
| tree | c2cab938806908dfbf7f0477976c3d7d289e91d7 /odoo/tools | |
| parent | 80379606dbc7d4afdb22476eea97a28ed88fe497 (diff) | |
[FIX] tools.pdf: do not crash when PDF has no attachments
In the PDF, `DictionaryObject` can be wrapped in `IndirectObject`. For nested
dictionaries, using `get` on a `DictionaryObject` will unwrap the result if it's
an `IndirectObject`, but not `__getitem__` so when trying to futher call `get`
on the result will cause an error: we need to unwrap the object first.
Instead, we patch `DictionaryObject.get()` for it to unwrap the object in case
it's an `IndirectObject`.
This is a follow-up commit of fece5ab1bf2fef043b131f1bd0886f0841116103
closes odoo/odoo#53269
X-original-commit: 189a0b28ec7fdb7472f936450cfd7b4bfd6912ed
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Signed-off-by: bfr-o <bfr-o@users.noreply.github.com>
Diffstat (limited to 'odoo/tools')
| -rw-r--r-- | odoo/tools/pdf.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/odoo/tools/pdf.py b/odoo/tools/pdf.py index 8e317fa2bde..dadae1df522 100644 --- a/odoo/tools/pdf.py +++ b/odoo/tools/pdf.py @@ -12,6 +12,17 @@ import hashlib DEFAULT_PDF_DATETIME_FORMAT = "D:%Y%m%d%H%M%S+00'00'" +# make sure values are unwrapped by calling the specialized __getitem__ +def _unwrapping_get(self, key, default=None): + try: + return self[key] + except KeyError: + return default + + +DictionaryObject.get = _unwrapping_get + + class BrandedFileWriter(PdfFileWriter): def __init__(self): super().__init__() @@ -25,7 +36,8 @@ PdfFileWriter = BrandedFileWriter def merge_pdf(pdf_data): - ''' Merge a collection of PDF documents in one + ''' Merge a collection of PDF documents in one. + Note that the attachments are not merged. :param list pdf_data: a list of PDF datastrings :return: a unique merged PDF datastring ''' @@ -40,7 +52,8 @@ def merge_pdf(pdf_data): def rotate_pdf(pdf): - ''' Rotate clockwise PDF (90°) + ''' Rotate clockwise PDF (90°) into a new PDF. + Note that the attachments are not copied. :param pdf: a PDF to rotate :return: a PDF rotated ''' |
