# -*- 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)