3
votes

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,

2

2 Answers

3
votes

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.

1
votes

Do one thing, create one csv file named "ir.model.access.csv" and into that create one record.

This csv file must contain following columns.

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink       
access_id,access_name,model_stock_picking,group_name_external_id,1,0,0,0

And add this to the openerp.py file, so it will set this access rights for the particular model to particular group. And suppose you want to set this permissions for all then just leave blank "group_id" fields then it will set this default permission for all users.