You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The base_user_role module creates user role groups without automatically assigning external IDs (XML IDs). This causes issues in two critical areas:
When trying to assign these groups to views using Odoo Studio, as it requires groups to have external IDs.
When manually editing XML views, as the XML IDs are needed to include these user groups in view definitions.
These limitations significantly hinder the module's functionality and integration with Odoo's view management system.
To Reproduce
Affected versions: Odoo 16.0
Steps to reproduce the behavior:
Install and configure the base_user_role module
Create a new user role (e.g., "Finance Manager")
Attempt to assign the newly created user role group to a view using Odoo Studio
Observe the error message: "Only groups with an external ID can be used here. Please choose another group or assign manually an external ID to this group."
Alternatively, try to manually edit an XML view to include the new user role group
Observe that there's no valid XML ID to reference the group
Expected behavior
User role groups should be automatically created with unique, properly formatted external IDs, allowing them to be:
Directly assignable in view definitions through Odoo Studio without errors.
Easily referenceable when manually editing XML views.
Additional context
Current workaround: Manually assigning external IDs to the groups (records in res.groups) associated with user roles resolves the issue for both Odoo Studio and manual XML editing.
Once external IDs are manually assigned, the functionality works correctly.
This manual process is time-consuming, prone to oversight, and needs to be repeated for each role, significantly impacting development and maintenance efficiency.
The module would be much more user-friendly if it automatically assigned properly formatted external IDs to the groups upon creation.
The desired format for external IDs is "user_roles.{role_name_in_lowercase_with_spaces_replaced_by_underscores}" (e.g., "user_roles.finance_manager").
The solution should handle Unicode characters in role names, converting them to ASCII for the external ID.
All characters (including special characters) should be kept intact in the external ID, with only spaces being replaced by underscores and the string converted to lowercase.
The lack of automatic external ID assignment affects not just the ease of use with Odoo Studio, but also the ability to efficiently manage view access control through manual XML editing.
This issue fundamentally limits the integration of the base_user_role module with Odoo's view management system, both through the UI and in code.
Proposed solution
Modify the create method in the ResUsersRole model to automatically generate appropriate external IDs for the associated groups. Here's the proposed implementation:
importunicodedatafromodooimportapi, modelsdefslugify(value):
""" Convert to ASCII. Convert spaces to underscores. Convert to lowercase. Also strip leading and trailing whitespace. """value=str(value)
value=unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value=value.strip().lower()
returnvalue.replace(' ', '_')
classResUsersRole(models.Model):
_name="res.users.role"_inherits= {"res.groups": "group_id"}
_description="User role"@api.model_create_multidefcreate(self, vals_list):
roles=super().create(vals_list)
forroleinroles:
# Generate the external IDext_id=f"user_roles.{slugify(role.name)}"# Check if this external ID already existsexisting=self.env['ir.model.data'].search([
('module', '=', 'user_roles'),
('name', '=', slugify(role.name))
])
# If it exists, append a number to make it uniqueifexisting:
count=1whileself.env['ir.model.data'].search([
('module', '=', 'user_roles'),
('name', '=', f"{slugify(role.name)}_{count}")
]):
count+=1ext_id=f"user_roles.{slugify(role.name)}_{count}"# Create the external IDself.env['ir.model.data'].create({
'name': ext_id.split('.')[1],
'module': 'user_roles',
'model': 'res.groups',
'res_id': role.group_id.id,
})
returnroles
This solution ensures that:
Each group associated with a user role has a unique external ID automatically assigned.
The external IDs follow the format "user_roles.{role_name_in_lowercase_with_spaces_replaced_by_underscores}".
Unicode characters in role names are properly handled and converted to ASCII for the external ID.
Only spaces are replaced with underscores; all other characters (including special characters) are kept intact.
The entire string is converted to lowercase.
Leading and trailing whitespace is removed.
Potential duplicates are handled by appending a number if necessary.
Implementing this solution will:
Eliminate the need for manual intervention in assigning external IDs.
Improve overall usability of the module for both Odoo Studio users and developers working with XML views.
Ensure seamless compatibility with Odoo's view management system, both through the UI and in code.
Streamline the process of assigning user role groups to views, enhancing the module's integration with Odoo's core functionality.
The text was updated successfully, but these errors were encountered:
Module
base_user_role
Describe the bug
The base_user_role module creates user role groups without automatically assigning external IDs (XML IDs). This causes issues in two critical areas:
These limitations significantly hinder the module's functionality and integration with Odoo's view management system.
To Reproduce
Affected versions: Odoo 16.0
Steps to reproduce the behavior:
Install and configure the base_user_role module
Create a new user role (e.g., "Finance Manager")
Attempt to assign the newly created user role group to a view using Odoo Studio
Alternatively, try to manually edit an XML view to include the new user role group
Expected behavior
User role groups should be automatically created with unique, properly formatted external IDs, allowing them to be:
Additional context
Proposed solution
Modify the
create
method in theResUsersRole
model to automatically generate appropriate external IDs for the associated groups. Here's the proposed implementation:This solution ensures that:
Implementing this solution will:
The text was updated successfully, but these errors were encountered: