Files
Odoo-Modules/fusion_theme_switcher/models/res_users_settings.py
gsinghpal b07f771d98 changes
2026-05-12 09:08:34 -04:00

34 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)
"""Coerce a missing color_scheme to the default on create/write.
`web_enterprise` declares `color_scheme` as required with default 'system',
and the DB column is NOT NULL. It also adds a radio widget for
`res.users.color_scheme` (a related field) to the user form. For a brand-new
user the underlying `res.users.settings` record doesn't exist yet, so the
widget loads with no value and submitting the form propagates
`color_scheme=False` into the eventual settings create/write — which trips the
NOT NULL constraint and surfaces as "Missing required value for the field
'Color Scheme'".
Treat a falsy color_scheme as 'omit' so the field's own default applies.
"""
from odoo import api, models
class ResUsersSettings(models.Model):
_inherit = "res.users.settings"
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "color_scheme" in vals and not vals["color_scheme"]:
vals["color_scheme"] = "system"
return super().create(vals_list)
def write(self, vals):
if "color_scheme" in vals and not vals["color_scheme"]:
vals = {**vals, "color_scheme": "system"}
return super().write(vals)