Files

50 lines
1.8 KiB
Python
Raw Permalink Normal View History

2026-07-01 14:41:49 +07:00
from odoo import models, fields, api
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
# ✅ CRITICAL FIX: Use Many2one to link to the singleton
# This is the ONLY field the settings wizard needs to save explicitly
khmer_theme_config_id = fields.Many2one(
'custom.theme.config',
string='Theme Configuration',
required=True,
default=lambda self: self._get_default_theme_config()
)
# ✅ Related Fields (Read/Write via the Many2one)
# These will automatically update the linked record when the Many2one is saved
khmer_font_file = fields.Binary(
string="Custom Font File (.ttf)",
related='khmer_theme_config_id.font_file',
readonly=False
)
khmer_font_name = fields.Char(
string="Font Family Name",
related='khmer_theme_config_id.font_name',
readonly=False
)
khmer_menu_bg_color = fields.Char(
string="Menu Background Color",
related='khmer_theme_config_id.menu_bg_color',
readonly=False
)
khmer_menu_bg_image = fields.Binary(
string="Menu Background Image",
related='khmer_theme_config_id.menu_bg_image',
readonly=False
)
khmer_is_responsive = fields.Boolean(
string="Enable Mobile Responsiveness",
related='khmer_theme_config_id.is_responsive',
readonly=False
)
khmer_font_file_name = fields.Char(string="Font Filename", related='khmer_theme_config_id.font_file_name',
readonly=False)
@api.model
def _get_default_theme_config(self):
config = self.env['custom.theme.config'].search([], limit=1)
if not config:
config = self.env['custom.theme.config'].create({'name': 'Main Configuration'})
return config.id