From 94db11826ecde22c9c72c80d2bd2467ae6dbc8a7 Mon Sep 17 00:00:00 2001 From: "Louis Wicket (wil)" Date: Thu, 12 May 2022 14:55:03 +0000 Subject: [PATCH] [IMP] mail: add res_users_settings_id field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the `res_users_settings_id` field on `res.users` so that it can be used as a target for relateds that is not a x2many field. closes odoo/odoo#90015 Related: odoo/upgrade#3479 Related: odoo/enterprise#26287 Signed-off-by: Sébastien Theys (seb) --- addons/mail/models/res_users.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/addons/mail/models/res_users.py b/addons/mail/models/res_users.py index 5eaa0148018..9a237b2ddfe 100644 --- a/addons/mail/models/res_users.py +++ b/addons/mail/models/res_users.py @@ -27,6 +27,8 @@ class Users(models.Model): "- Handle by Emails: notifications are sent to your email address\n" "- Handle in Odoo: notifications appear in your Odoo Inbox") res_users_settings_ids = fields.One2many('res.users.settings', 'user_id') + # Provide a target for relateds that is not a x2Many field. + res_users_settings_id = fields.Many2one('res.users.settings', string="Settings", compute='_compute_res_users_settings_id', search='_search_res_users_settings_id') _sql_constraints = [( "notification_type", @@ -41,6 +43,15 @@ class Users(models.Model): if user.share or not user.notification_type: user.notification_type = 'email' + @api.depends('res_users_settings_ids') + def _compute_res_users_settings_id(self): + for user in self: + user.res_users_settings_id = user.res_users_settings_ids and user.res_users_settings_ids[0] + + @api.model + def _search_res_users_settings_id(self, operator, operand): + return [('res_users_settings_ids', operator, operand)] + # ------------------------------------------------------------ # CRUD # ------------------------------------------------------------