diff options
| author | Nicolas Galler <ngl@odoo.com> | 2020-10-06 12:43:11 +0000 |
|---|---|---|
| committer | Nicolas Galler <ngl@odoo.com> | 2020-10-08 09:26:53 +0000 |
| commit | 6d6e48f34f850fa533ce00532ada0e3464c8144b (patch) | |
| tree | f2be51af3ee1d39051c8b5347a63310c033be41c /addons/web/tests/test_base_document_layout.py | |
| parent | 0474f9b6bb3c959a2fe4ad1b231fa5e8ffbcf9d8 (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/tests/test_base_document_layout.py')
| -rw-r--r-- | addons/web/tests/test_base_document_layout.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/addons/web/tests/test_base_document_layout.py b/addons/web/tests/test_base_document_layout.py index 55b324117f4..dd8f4e2ad24 100644 --- a/addons/web/tests/test_base_document_layout.py +++ b/addons/web/tests/test_base_document_layout.py @@ -194,6 +194,20 @@ class TestBaseDocumentLayout(TestBaseDocumentLayoutHelpers): doc_layout.secondary_color = doc_layout.logo_secondary_color self.assertColors(doc_layout, self.company_imgs['sweden']['colors']) + def test_parse_company_colors_grayscale(self): + """Grayscale images with transparency""" + self.company.write({ + 'primary_color': '#ff0080', + 'secondary_color': '#00ff00', + 'paperformat_id': self.env.ref('base.paperformat_us').id, + }) + with Form(self.env['base.document.layout']) as doc_layout: + with Image.open(os.path.join(dir_path, 'logo_ci.png'), 'r') as img: + base64_img = image_to_base64(img, 'PNG') + doc_layout.logo = base64_img + self.assertEqual('#8d8d8d', doc_layout.primary_color) + + # /!\ This case is NOT supported, and probably not supportable # res.partner resizes manu-militari the image it is given # so res.company._get_logo differs from res.partner.[default image] |
