Thayif kabir
Thayif kabir

Reputation: 726

Update res users form based on default company in odoo14

Based on user's default company need to hide some groups and group category in user form in odoo 14

Some groups must be visible to particular company, If one user changes their company_id only groups allowed to that particular company should be there in users form

Upvotes: 0

Views: 231

Answers (1)

Atul
Atul

Reputation: 36

you can try overriding update_user_groups_view() function in res_groups.py in base. Below portion of code in that function used to hide the groups.

else:
                # application separator with boolean fields
                app_name = app.name or 'Other'
                xml3.append(E.separator(string=app_name, colspan="4", **attrs))
                attrs['attrs'] = user_type_readonly
                for g in gs:
                    field_name = name_boolean_group(g.id)
                    if g == group_no_one:
                        # make the group_no_one invisible in the form view
                        xml3.append(E.field(name=field_name, invisible="1", **attrs))
                    else:
                        xml3.append(E.field(name=field_name, **attrs))

You override this function and insert your condition here, then override fields_view_get in res_users like this

@api.model
def fields_view_get(self, view_id=None, view_type="form", **kwargs):
    if view_type == "form":
        self.env["res.groups"].sudo()._update_user_groups_view()
    return super(ResUsers, self).fields_view_get(view_id=view_id, view_type=view_type, **kwargs)

Upvotes: 2

Related Questions