From 02fb94aafb5fe2e811d9f6a4e144f2ae9655579a Mon Sep 17 00:00:00 2001 From: Florian Charlier Date: Thu, 2 Mar 2023 15:31:31 +0000 Subject: [PATCH] [FIX] gamification: set a working default user domain for challenges Fix applied to ease user experience after the user_id field removal for performance in 509b4cad. This is a simple fix to allow users to have ready filters available instead of having to enter them. This is especially helpful because, for performance reason, when no domain is selected, no user will be added, even though the widget on the webclient shows that all user records are matched and will be added. This is why [("active", "=", True)] is also added, allowing to simply remove the "internal user" rule to really have all users if desired. Task-3214005 closes odoo/odoo#116044 X-original-commit: 5a6e585e3294430126a9da3c7392942c91a9fffd Signed-off-by: Thibault Delavallee (tde) --- addons/gamification/models/gamification_challenge.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/gamification/models/gamification_challenge.py b/addons/gamification/models/gamification_challenge.py index ba71207abe0..c3905309d95 100644 --- a/addons/gamification/models/gamification_challenge.py +++ b/addons/gamification/models/gamification_challenge.py @@ -60,6 +60,14 @@ class Challenge(models.Model): _inherit = 'mail.thread' _order = 'end_date, start_date, name, id' + @api.model + def default_get(self, fields_list): + res = super().default_get(fields_list) + if 'user_domain' in fields_list and 'user_domain' not in res: + user_group_id = self.env.ref('base.group_user') + res['user_domain'] = f'["&", ("groups_id", "=", "{user_group_id.name}"), ("active", "=", True)]' + return res + # description name = fields.Char("Challenge Name", required=True, translate=True) description = fields.Text("Description", translate=True)