From 6217a00b166e30a15d9f53b1167cf17f8f38f578 Mon Sep 17 00:00:00 2001 From: Mark Penalosa Date: Thu, 30 Apr 2026 09:45:22 +0800 Subject: [PATCH 1/3] fix(spp_user_roles): prevent validation error when assigning groups to a new role --- spp_user_roles/models/role.py | 25 ++++++++++++++++++++++++- spp_user_roles/views/role.xml | 13 ++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/spp_user_roles/models/role.py b/spp_user_roles/models/role.py index 069a2b09..c6e83d7b 100644 --- a/spp_user_roles/models/role.py +++ b/spp_user_roles/models/role.py @@ -2,7 +2,7 @@ import logging -from odoo import fields, models +from odoo import api, fields, models _logger = logging.getLogger(__name__) @@ -12,6 +12,29 @@ class ResUsersRoleCustomSPP(models.Model): role_type = fields.Selection([("local", "Local"), ("global", "Global")], default="global") + @api.model_create_multi + def create(self, vals_list): + # Workaround: same Odoo cache-clearing bug as in base_user_role's write() + # override. When res.groups fields are set via _inherits on create(), + # implied_ids gets dropped. Extract group fields and write them to + # group_id directly after creation, mirroring the write() fix. + groups_vals_list = [] + group_fields = set(self.env["res.groups"]._fields) - {"name"} + for vals in vals_list: + group_vals = {} + for field in group_fields: + if field in vals: + group_vals[field] = vals.pop(field) + groups_vals_list.append(group_vals) + + new_records = super().create(vals_list) + + for record, group_vals in zip(new_records, groups_vals_list): + if group_vals: + record.group_id.write(group_vals) + + return new_records + def action_update_users(self): """ Call the update_users function to force the update of associated users in the role. diff --git a/spp_user_roles/views/role.xml b/spp_user_roles/views/role.xml index 0637e402..c15f029f 100644 --- a/spp_user_roles/views/role.xml +++ b/spp_user_roles/views/role.xml @@ -20,9 +20,16 @@ - - [('role_id', '=', False)] - many2many + + + + + + Date: Mon, 4 May 2026 11:16:29 +0800 Subject: [PATCH 2/3] fix(spp_user_roles): pass strict=True to zip() in create override MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI's ruff (B905) flagged `zip(new_records, groups_vals_list)` for omitting the explicit `strict=` parameter. The two iterables are built side-by-side in the same loop above the call, so they're guaranteed equal length — make it explicit with `strict=True` to satisfy the linter and turn an undetectable mismatch into a clear runtime error if the invariant ever breaks. --- spp_user_roles/models/role.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spp_user_roles/models/role.py b/spp_user_roles/models/role.py index c6e83d7b..472eee14 100644 --- a/spp_user_roles/models/role.py +++ b/spp_user_roles/models/role.py @@ -29,7 +29,7 @@ def create(self, vals_list): new_records = super().create(vals_list) - for record, group_vals in zip(new_records, groups_vals_list): + for record, group_vals in zip(new_records, groups_vals_list, strict=True): if group_vals: record.group_id.write(group_vals) From 980b34f04f948187fbd201f946e4e0896ea26119 Mon Sep 17 00:00:00 2001 From: emjay0921 Date: Mon, 4 May 2026 11:28:16 +0800 Subject: [PATCH 3/3] fix(spp_user_roles): drop position=replace on implied_ids MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OCA xml-view-dangerous-replace-low-priority hook flagged the position="replace" used to add a domain and an embedded list to the `implied_ids` field on the role form. Replace is reserved as a last resort; the same effect can be achieved with position="attributes" (for the new domain) plus position="inside" (to embed the list). Functionally identical for OP#979 — the field still restricts the group dropdown to free groups and the inline list still has create disabled, but the inheritance is now safer for downstream views. --- spp_user_roles/views/role.xml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/spp_user_roles/views/role.xml b/spp_user_roles/views/role.xml index c15f029f..1817878b 100644 --- a/spp_user_roles/views/role.xml +++ b/spp_user_roles/views/role.xml @@ -20,16 +20,19 @@ - - - - - - + + + [('role_id', '=', False)] + + + + +