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): _inherit = 'res.config.settings' theme_primary_color = fields.Char( string='Primary Colour', config_parameter='community_theme_base.primary_color', default=DEFAULT_PRIMARY_COLOR, ) theme_secondary_color = fields.Char( string='Secondary Colour', config_parameter='community_theme_base.secondary_color', default=DEFAULT_SECONDARY_COLOR, ) theme_accent_color = fields.Char( 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', help="Shown in the website navbar and on generated PDF reports/cards. " "Falls back to the company logo if not set.", ) theme_heading_font = fields.Char( string='Heading Font', config_parameter='community_theme_base.heading_font', default=DEFAULT_FONT, ) theme_body_font = fields.Char( 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 '')