diff --git a/spp_user_roles/README.rst b/spp_user_roles/README.rst index fc888a65..dd1b3257 100644 --- a/spp_user_roles/README.rst +++ b/spp_user_roles/README.rst @@ -129,6 +129,20 @@ Dependencies Changelog ========= +19.0.2.0.1 +~~~~~~~~~~ + +- fix(role): allow assigning groups to a brand-new role in a single + save. Clicking **Add a line** in the role form's Groups tab used to + trigger inline creation of a blank ``res.groups`` row, which raised a + required-field validation error and aborted the save. The + ``implied_ids`` field's inner list now uses ``create="0"`` so the + button opens an "Add" picker against existing groups, and + ``res.users.role.create()`` extracts ``implied_ids`` before + ``super().create()`` and writes them to the role's ``group_id`` + afterwards — mirroring the existing ``write()`` workaround in + ``base_user_role`` for the same ``_inherits`` cache-clearing bug. + 19.0.2.0.0 ~~~~~~~~~~ diff --git a/spp_user_roles/__manifest__.py b/spp_user_roles/__manifest__.py index 45f4ded4..839997cf 100644 --- a/spp_user_roles/__manifest__.py +++ b/spp_user_roles/__manifest__.py @@ -2,7 +2,7 @@ { "name": "OpenSPP User Roles", "category": "OpenSPP", - "version": "19.0.2.0.0", + "version": "19.0.2.0.1", "sequence": 1, "author": "OpenSPP.org", "website": "https://github.com/OpenSPP/OpenSPP2", diff --git a/spp_user_roles/models/role.py b/spp_user_roles/models/role.py index 069a2b09..472eee14 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, strict=True): + 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/readme/HISTORY.md b/spp_user_roles/readme/HISTORY.md index 4aaf9afe..32ad2824 100644 --- a/spp_user_roles/readme/HISTORY.md +++ b/spp_user_roles/readme/HISTORY.md @@ -1,3 +1,7 @@ +### 19.0.2.0.1 + +- fix(role): allow assigning groups to a brand-new role in a single save. Clicking **Add a line** in the role form's Groups tab used to trigger inline creation of a blank `res.groups` row, which raised a required-field validation error and aborted the save. The `implied_ids` field's inner list now uses `create="0"` so the button opens an "Add" picker against existing groups, and `res.users.role.create()` extracts `implied_ids` before `super().create()` and writes them to the role's `group_id` afterwards — mirroring the existing `write()` workaround in `base_user_role` for the same `_inherits` cache-clearing bug. + ### 19.0.2.0.0 - Initial migration to OpenSPP2 diff --git a/spp_user_roles/static/description/index.html b/spp_user_roles/static/description/index.html index 432698ea..68f7ea2e 100644 --- a/spp_user_roles/static/description/index.html +++ b/spp_user_roles/static/description/index.html @@ -503,6 +503,21 @@

Changelog

+

19.0.2.0.1

+ +
+

19.0.2.0.0