fix(spp_user_roles): exclude role-backing groups from Groups dropdown#159
fix(spp_user_roles): exclude role-backing groups from Groups dropdown#159
Conversation
UI-created roles auto-generate backing res.groups records that then appear in the Groups tab dropdown of other roles. Add domain filter on implied_ids to exclude groups linked to roles.
There was a problem hiding this comment.
Code Review
This pull request modifies the role view in Odoo to apply a domain filter on the implied_ids field. A critical issue was identified regarding the use of the role_id field in the domain, as it is not a standard Odoo field and is missing from the provided model definitions. This would likely cause a traceback, so it is recommended to define the inverse field on the res.groups model as suggested.
| <xpath expr="//field[@name='implied_ids']" position="attributes"> | ||
| <attribute | ||
| name="domain" | ||
| >[('role_id', '=', False)]</attribute> | ||
| </xpath> |
There was a problem hiding this comment.
The domain [('role_id', '=', False)] refers to a field role_id on the res.groups model. This field is not a standard Odoo field, nor is it defined in the base_user_role module or the provided spp_user_roles/models/role.py file.
Unless this field is defined in a dependency not shown in this PR, this will cause a traceback when loading the form view. To fix this, you should define the inverse field in your Python models (e.g., in spp_user_roles/models/role.py):
class ResGroups(models.Model):
_inherit = "res.groups"
role_id = fields.One2many(
comodel_name="res.users.role",
inverse_name="group_id",
string="Associated Role",
) <xpath expr="//field[@name='implied_ids']" position="attributes">
<attribute name="domain">[('role_id', '=', False)]</attribute>
</xpath>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 19.0 #159 +/- ##
=======================================
Coverage 71.33% 71.33%
=======================================
Files 932 932
Lines 54975 54975
=======================================
Hits 39217 39217
Misses 15758 15758
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Why is this change needed?
When creating a role via the UI (Settings → Users & Companies → User Roles → New), Odoo 19 auto-creates a backing
res.groupsrecord. These role-backing groups then appear in the Groups tab dropdown of other roles alongside legitimate permission groups, causing confusion.How was the change implemented?
Added a domain filter
[('role_id', '=', False)]on theimplied_idsfield in the role form view. This excludes anyres.groupsrecord that has a linkedres.users.role— i.e., role-backing groups are hidden from the dropdown while standard permission groups remain visible.New unit tests
N/A — view-only change.
Unit tests executed by the author
Existing spp_user_roles tests pass.
How to test manually
Related links
https://projects.acn.fr/projects/acn-eng/work_packages/888