From dbbc90e9ea7b2ca5523911e4ce4d466fa19534a0 Mon Sep 17 00:00:00 2001 From: "Simon Goffaux (sigo)" Date: Thu, 22 Feb 2024 11:28:07 +0100 Subject: [PATCH] [FIX] website_sale: add !important to ribbon color Before this commit, the bg-primary class was overwriting the bg_color set by the user after saving changes as it has the !important tag. Steps to reproduce the issue: 1. Go to Shop page on website 2. Enable edit mode 3. Pick a product and create a new Badge (ribbon) 4. Change the background color and save changes -> color reverts to bg-primary This commit fixes this behavior by adding the !important tag to the bg_color so that it properly overwrites the bg-primary color. opw-3734598 closes odoo/odoo#155274 X-original-commit: 9ee115b58342b3e0dbc11081e7ff752c10f8bfa9 Signed-off-by: Antoine Vandevenne (anv) Signed-off-by: Simon Goffaux (sigo) --- addons/website_sale/models/product_ribbon.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/website_sale/models/product_ribbon.py b/addons/website_sale/models/product_ribbon.py index 54424354fdd..b8578ac6bf8 100644 --- a/addons/website_sale/models/product_ribbon.py +++ b/addons/website_sale/models/product_ribbon.py @@ -17,3 +17,15 @@ class ProductRibbon(models.Model): bg_color = fields.Char(string='Ribbon background color', required=False) text_color = fields.Char(string='Ribbon text color', required=False) html_class = fields.Char(string='Ribbon class', required=True, default='') + + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if 'bg_color' in vals and not '!important' in vals['bg_color']: + vals['bg_color'] += ' !important' + return super().create(vals_list) + + def write(self, data): + if 'bg_color' in data and not '!important' in data['bg_color']: + data['bg_color'] += ' !important' + return super().write(data)