Skip to Content
Menu
This question has been flagged
1 Reply
8901 Views

Hi Odooers !
I'd like to know how I can either modify an existing security group or add a new one to an existing module ? In my case I need to have a security group to only allow read access to purchase orders and purchase orders lines (Purchase module). I'd like to do that through a new module that will extend the existing purchase module. I tried to add the following xml to my module's security xml:

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

With the following rules:

access_purchase_order_readonly,access_purchase_order_readonly,purchase.model_purchase_order,group_purchase_user,1,0,0,0
access_purchase_order_line_readonly,access_purchase_order_line_readonly,purchase.model_purchase_order_line,group_purchase_user,1,0,0,0

Thinking I could override the existing "User" security group of Purchase.

I also tried to add a new security group with new security rules in the same fashion:

<record id="group_consult_internal_purchase" model="res.groups">
<field name="name">Consulter</field>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="category_id" ref="base.module_category_purchase_management"/>
</record>
access_purchase_order_readonly,access_purchase_order_readonly,purchase.model_purchase_order, group_consult_internal_purchase,1,0,0,0
access_purchase_order_line_readonly,access_purchase_order_line_readonly,purchase.model_purchase_order_line, group_consult_internal_purchase,1,0,0,0

I tried to find examples in the documentation or the internet but I couldn't find any so I'm even sure that's possible.

Help please ?



Avatar
Discard
Best Answer

Hi,

There are some existing record rules and access rights for this models in the odoo source code, you might need to inherit and change those rules for achieving what you are trying to do.


For Changing an existing record rule, you can do it like this,

<record model="ir.rule" id="purchase_order_line_comp_rule">
<field name="name">Purchase Order Line multi-company</field>
<field name="model_id" ref="model_purchase_order_line"/>
<field name="global" eval="True"/>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
</record>


The above rule is defined in the purchase module, suppose if i need to change the domain to empty for this rule from my custom module what i have to do is ,

<record model="ir.rule" id="purchase.purchase_order_line_comp_rule">
<field name="domain_force"></field>
</record>


Copy existing rule to your module, remove those lines you don't want to make changes and change the id to original_module_name.orginal_id . In the above code, you can see i have changed the id purchase_order_line_comp_rule to purchase.purchase_order_line_comp_rule . This is how you can change existing record rules.


For Changing existing access rights,you have to follow same procedures, replace the id with original_module_name.id .


Thanks

Avatar
Discard
Author

Thanks for the answer ! do you think it is also possible to add a new security group to an existing module from my custom module ?

Yes, it can be done

how can i add a new group to the list of module groups

Related Posts Replies Views Activity
3
Sep 15
3310
2
May 15
4291
0
Dec 24
28
1
Dec 24
40
0
Nov 24
29