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 = [] diff --git a/addons/web/tests/logo_ci.png b/addons/web/tests/logo_ci.png new file mode 100644 index 00000000000..1a1ae58e90a Binary files /dev/null and b/addons/web/tests/logo_ci.png differ 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]