22
33import logging
44
5- from odoo import fields , models
5+ from odoo import api , fields , models
66
77_logger = logging .getLogger (__name__ )
88
@@ -12,6 +12,29 @@ class ResUsersRoleCustomSPP(models.Model):
1212
1313 role_type = fields .Selection ([("local" , "Local" ), ("global" , "Global" )], default = "global" )
1414
15+ @api .model_create_multi
16+ def create (self , vals_list ):
17+ # Workaround: same Odoo cache-clearing bug as in base_user_role's write()
18+ # override. When res.groups fields are set via _inherits on create(),
19+ # implied_ids gets dropped. Extract group fields and write them to
20+ # group_id directly after creation, mirroring the write() fix.
21+ groups_vals_list = []
22+ group_fields = set (self .env ["res.groups" ]._fields ) - {"name" }
23+ for vals in vals_list :
24+ group_vals = {}
25+ for field in group_fields :
26+ if field in vals :
27+ group_vals [field ] = vals .pop (field )
28+ groups_vals_list .append (group_vals )
29+
30+ new_records = super ().create (vals_list )
31+
32+ for record , group_vals in zip (new_records , groups_vals_list ):
33+ if group_vals :
34+ record .group_id .write (group_vals )
35+
36+ return new_records
37+
1538 def action_update_users (self ):
1639 """
1740 Call the update_users function to force the update of associated users in the role.
0 commit comments