Search code examples
odooodoo-8rules

odoo override group permission on object


I have a task in odoo 8, i have to create a user group named ( picker ) which will be in inheritance to warehouse user group. as Warehouse Manager -> User --> test. so i created the user as follows :

<record id="warehouse_picker" model="res.groups">
    <field name="name">picker </field>
    <field name="category_id" ref="base.module_category_warehouse_management"/>
    <field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
 </record>

also i have added this code to give access of menu warehouse to this user :

<record id="stock.group_stock_user" model="res.groups">
     <field name="implied_ids" eval="[(4, ref('warehouse_picker')),(4, ref('stock.group_locations'))]"/>
</record>  

Now, The Group Warehouse / User has access rule to an object (stock.picking) as 1,1,1,1. I need to restrict / Override this rule (stock.picking) to 1,0,0,0

I tried following code, but doesn't work :

<record id="warehouse_picker_rule" model="ir.rule">
    <field name="name">Warehouse Picker Rule</field>
    <field name="model_id" ref="stock.model_stock_picking"/>
    <field name="domain_force">[(1, '=', 1)]</field>
    <field name="groups" eval="[(4, ref('warehouse_picker'))]"/>
    <field name="perm_read" eval="False"/>
    <field name="perm_write" eval="False"/>
    <field name="perm_create" eval="False"/>
    <field name="perm_unlink" eval="True"/>
</record>

Can someone help me to solve / override the existing rule. i don't want to touch the core module rules.

Thanks,


Solution

  • Check out from which module this rule is coming from and then you can override like:

    <record id="module.rule_id" model="ir.model.access">
        <field name="perm_read" eval="True"/>
        <field name="perm_write" eval="False"/>
        <field name="perm_create" eval="False"/>
        <field name="perm_unlink" eval="False"/>
    </record>
    

    For example, module is stock and rule_id (you can find this with debug mode in the GUI or look into the modules ir.model.access.csv first column) is move_read_all:

    <record id="stock.move_read_all" model="ir.model.access">
        <field name="perm_read" eval="True"/>
        <field name="perm_write" eval="False"/>
        <field name="perm_create" eval="False"/>
        <field name="perm_unlink" eval="False"/>
    </record>
    

    If i understand your wish correct, then you have to override it the following way:

    <record id="stock.access_stock_picking_user" model="ir.model.access">
        <field name="perm_read" eval="True"/>
        <field name="perm_write" eval="False"/>
        <field name="perm_create" eval="False"/>
        <field name="perm_unlink" eval="False"/>
    </record>
    

    You will need to put the dependency to stock into your manifest file of your custom module.