[FIX] base: Allow to create an user
Now that an onchange set its result into the cache, we cannot create a user because the onchange tries to put the reified fields (eg: sel_4_7) into the cache. As those field don't exist and are pseudo-fields used to manage groups into the res user form view, we should replace the values by ORM commands on the groups_id field, as this is already the case in the create and the write methods. Note: Initially merged in saas-12.4, but was not forward ported, I don't know why. closes odoo/odoo#34487 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -1192,6 +1192,18 @@ class UsersView(models.Model):
|
||||
user.write({'groups_id': [(4, group_multi_company.id)]})
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def new(self, values={}, origin=None, ref=None):
|
||||
values = self._remove_reified_groups(values)
|
||||
user = super().new(values=values, origin=origin, ref=ref)
|
||||
group_multi_company = self.env.ref('base.group_multi_company', False)
|
||||
if group_multi_company and 'company_ids' in values:
|
||||
if len(user.company_ids) <= 1 and user.id in group_multi_company.users.ids:
|
||||
user.update({'groups_id': [(3, group_multi_company.id)]})
|
||||
elif len(user.company_ids) > 1 and user.id not in group_multi_company.users.ids:
|
||||
user.update({'groups_id': [(4, group_multi_company.id)]})
|
||||
return user
|
||||
|
||||
def _remove_reified_groups(self, values):
|
||||
""" return `values` without reified group fields """
|
||||
add, rem = [], []
|
||||
|
||||
Reference in New Issue
Block a user