Search code examples
python-3.xodoo-12

Change application access user right in odoo 12



i want to change application access user right.
in Mark Demo, Administration is selection field and it has rights for Access Rights.
i want to change it to Settings.
in python file self.env.user.has_group('base.group_system') returns False.
it means in selection field it fielded with Blank or Access right.
how can i change it to Settings.
i found this group in base.

<record model="res.groups" id="group_system">
    <field name="name">Settings</field>
    <field name="implied_ids" eval="[(4, ref('group_erp_manager'))]"/>
    <field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
</record>

Solution

  • When we change the value of Administration field and click on save button Odoo as usual calls write method, the first thing Odoo does, in this case, is calling _remove_reified_groups method to remove reified group fields (sel_groups_2_3 in your example) from values and compute the value of groups_id then add it to values to be written in the next step (when calling super).

    _remove_reified_groups compute groups to add or remove from groups_id. if a reified group field is present in values and has a value it will be added to groups_id, each time a reified group field is present in values the method calls get_selection_groups(key) to compute the groups to remove, the method returns the groups ids present in the field name. for the administration field sel_groups_2_3 the method will return [2, 3].

    To reproduce the same result when updating Administration group we need to remove the groups used in field name then add the selected group to groups_id (values['groups_id'] = [(3, 2), (3, 3), (4, 3)])

    The XML code used to set Mark demo administration group to Settings group should be:

    <record id="base.user_demo" model="res.users">
        <field name="groups_id" eval="[(3,ref('base.group_erp_manager')),(3,ref('base.group_system')),(4,ref('base.group_system'))]"/>
    </record>