diff --git a/addons/community_theme_base/models/res_config_settings.py b/addons/community_theme_base/models/res_config_settings.py index 02f77b5..fe2a484 100644 --- a/addons/community_theme_base/models/res_config_settings.py +++ b/addons/community_theme_base/models/res_config_settings.py @@ -1,9 +1,10 @@ -from odoo import fields, models +from odoo import api, fields, models DEFAULT_PRIMARY_COLOR = '#2C3E50' DEFAULT_SECONDARY_COLOR = '#7F8C8D' DEFAULT_ACCENT_COLOR = '#3498DB' DEFAULT_FONT = 'Inter, sans-serif' +LOGO_PARAM = 'community_theme_base.logo' class ResConfigSettings(models.TransientModel): @@ -21,8 +22,12 @@ class ResConfigSettings(models.TransientModel): string='Accent Colour', config_parameter='community_theme_base.accent_color', default=DEFAULT_ACCENT_COLOR, ) + # Binary fields cannot use config_parameter= directly (Odoo's settings + # framework only supports boolean/integer/float/char/selection/many2one/ + # datetime that way), so this one is persisted manually via get_values/ + # set_values, base64-encoded into an ir.config_parameter like the others. theme_logo = fields.Binary( - string='Logo', config_parameter='community_theme_base.logo', + string='Logo', help="Shown in the website navbar and on generated PDF reports/cards. " "Falls back to the company logo if not set.", ) @@ -34,3 +39,16 @@ class ResConfigSettings(models.TransientModel): string='Body Font', config_parameter='community_theme_base.body_font', default=DEFAULT_FONT, ) + + @api.model + def get_values(self): + res = super().get_values() + res['theme_logo'] = self.env['ir.config_parameter'].sudo().get_param(LOGO_PARAM) or False + return res + + def set_values(self): + super().set_values() + value = self.theme_logo + if isinstance(value, bytes): + value = value.decode() + self.env['ir.config_parameter'].sudo().set_param(LOGO_PARAM, value or '')