summaryrefslogtreecommitdiff
path: root/addons/web/models/base_document_layout.py
diff options
context:
space:
mode:
authorNicolas Galler <ngl@odoo.com>2020-10-06 12:43:11 +0000
committerNicolas Galler <ngl@odoo.com>2020-10-08 09:26:53 +0000
commit6d6e48f34f850fa533ce00532ada0e3464c8144b (patch)
treef2be51af3ee1d39051c8b5347a63310c033be41c /addons/web/models/base_document_layout.py
parent0474f9b6bb3c959a2fe4ad1b231fa5e8ffbcf9d8 (diff)
[FIX] base: do not crash if uploading a grayscale image
Behavior before the fix: Uploading a grayscale image with transparency in the company logo field of the document layout causes a crash: ``` File "/data/build/odoo/addons/web/models/base_document_layout.py", line 89, in _compute_logo_colors wizard.logo_primary_color, wizard.logo_secondary_color = wizard_for_image._parse_logo_colors() File "/data/build/odoo/addons/web/models/base_document_layout.py", line 191, in _parse_logo_colors color[1][2] > white_threshold) and color[1][3] > 0: Exception ... IndexError: tuple index out of range ``` To reproduce, use the `logo_ci.png` image included in the unit test data and load it in the document layout (under General Settings). The system does not detect that the image does not have color information and attempts to read the R,G,B values (but the image only has 2 values per pixel: the grayscale value and the alpha) Versions affected: 13, 14 Behavior after the fix: The image is loaded correctly (arguably, there is not a lot of interest in detecting the primary color of a grayscale image, but the script still returns a (gray) value which is preferrable to a traceback) opw-2352394 closes odoo/odoo#59381 X-original-commit: 9efe5608aa4fb4f66475d3cb3e15ea332a3ded38 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons/web/models/base_document_layout.py')
-rw-r--r--addons/web/models/base_document_layout.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/addons/web/models/base_document_layout.py b/addons/web/models/base_document_layout.py
index 8d26f61e2f7..6dd2883f3b9 100644
--- a/addons/web/models/base_document_layout.py
+++ b/addons/web/models/base_document_layout.py
@@ -179,9 +179,8 @@ class BaseDocumentLayout(models.TransientModel):
w = int(50 * base_w / base_h)
h = 50
- # Converts to RGBA if no alpha detected
- image_converted = image.convert(
- 'RGBA') if 'A' not in image.getbands() else image
+ # Converts to RGBA (if already RGBA, this is a noop)
+ image_converted = image.convert('RGBA')
image_resized = image_converted.resize((w, h))
colors = []