Skip to Content
Menu
This question has been flagged

Hello all,

i am trying to override base record rule in my custom module because i want to display only current company partner to specific user. but when i use base feature frim settings 》 multi comoany and uncheck share partner then it apply on all company and user 


so i am trying to do this for only some user or only for some compnay so i am overriding base record rule but it's not working


 <record model="ir.rule" id="res_partner_rule">
            <field name="name">res.partner company</field>
            <field name="model_id" ref="base.model_res_partner"/>
            <!--
Show partners from ancestors and descendants companies
(or company-less), this is usually a better default for
multicompany setups.
-->
            <field name="domain_force">['|','|',('company_id.child_ids','child_of',[user.company_id.id]),('company_id','child_of',[user.company_id.id]),('company_id','=',False)]</field>
            <field name="active" eval="False"/>
        </record>
i am trying to override above rule

please any one help me
Avatar
Discard
Best Answer

Hi, your changes on res_partner_rule from your custom_module is not affected because that record rule is set in the base module xml file with noupdate="1"

And also if you notice, that rule is inactive by default.

<record model="ir.rule" id="res_partner_rule">
<field name="name">res.partner company</field>
<field name="model_id" ref="base.model_res_partner"/>
<!--
Show partners from ancestors and descendants companies
(or company-less), this is usually a better default for
multicompany setups.
-->
<field name="domain_force">['|','|',('company_id.child_ids','child_of',[user.company_id.id]),('company_id','child_of',[user.company_id.id]),('company_id','=',False)]</field>
<field name="active" eval="False"/>
</record>

So before modifying the rule, just enable that default rule n try if it solves your issue. 

if not, you may check this link to understand how to override the record values set with noupdate="1", from your custom module. For eg:

<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value eval="[('module', '=', 'base'), ('name', '=', 'res_partner_rule')]"/>
</function>
<value eval="{'noupdate': False}"/>
</function>

<record model="ir.rule" id="base.res_partner_rule">
<field name="name">res.partner company</field>
<field name="model_id" ref="base.model_res_partner"/>
<!--
Show partners from ancestors and descendants companies
(or company-less), this is usually a better default for
multicompany setups.
-->
<field name="domain_force"> ['|',('company_id','=',user.company_id.id),('company_id','=',False)]</field>
<field name="active" eval="True"/>
</record>


<function name="write" model="ir.model.data">
<function name="search" model="ir.model.data">
<value eval="[('module', '=', 'base'), ('name', '=', 'res_partner_rule')]"/>
</function>
<value eval="{'noupdate': True}"/>
</function>

Hope this helps!!

Avatar
Discard
Best Answer

Hi,

You can rewrite/overide exiting rule in your custom module and do necessary changes. What you have to do is that, just copy and paste the original rule in your module and change its ID like with original_module_name.ID


Suppose if the rule  is coming from the module purchase and if it's ID is test_rule , in your custom module change the ID of record to purchase.test_rule


Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
Mar 24
953
1
Mar 24
1168
2
Dec 18
6612
1
Mar 15
4139
0
Mar 15
2830