5

The following record rule is defined in product module

<data noupdate="1">
    <record id="product_comp_rule" model="ir.rule">
        <field name="name" >Product multi-company</field>
        <field name="model_id" ref="model_product_template"/>
        <field name="global" eval="True"/>
        <field name="domain_force"> ['|',('company_id','=',user.company_id.id),('company_id','=',False)]</field>
    </record>
</data>

I want to edit it in my custom module to be

<record id="product.product_comp_rule" model="ir.rule">
    <field name="name" >All Products (Parent Company)</field>
    <field name="model_id" ref="product.model_product_template"/>
    <field name="global" eval="True"/>
    <field name="domain_force">['|','|',('company_id','=',user.company_id.id),('company_id','=','False'),('company_id','child_of',[user.company_id.id])] </field>
</record>
1
  • why does this question get minus flag? i have the some problem, does anyone get the answer yet? May 22, 2019 at 3:54

3 Answers 3

10

You can use :

<function name="fix_er_role" model="ir.rule"/>

After that add the method to ir.rule and fix your data

class IRRule(models.Model):
    _inherit = 'ir.rule'
    
    def fix_er_role(self):
         rol_id = self.env.ref('product.product_comp_rule')
         rol_id = self.env['ir.rule'].search([('id','=',rol_id)])
         rol_id.write({'domain_force':['|','|',('company_id','=',user.company_id.id),('company_id','=','False'),('company_id','child_of',[user.company_id.id])]})

Edit : an other good solution for this requirement.

    <function name="write" model="ir.model.data">
         <!-- get the record if from data base -->
        <function name="search" model="ir.model.data">
            <value
              eval="[('module', '=', 'product'), ('name', '=', 'product_comp_rule')]"
              />
        </function>
       <!-- remove noupdate -->
        <value eval="{'noupdate': False}" />
    </function>


    <record id="product.product_comp_rule" model="ir.rule">
        <field name="name" >All Products (Parent Company)</field>
        <field name="model_id" ref="product.model_product_template"/>
        <field name="global" eval="True"/>
        <field name="domain_force">['|','|',('company_id','=',user.company_id.id),('company_id','=','False'),('company_id','child_of',[user.company_id.id])] </field>
    </record>

    <!-- reset noupdate -->
    <function name="write" model="ir.model.data">
        <function name="search" model="ir.model.data">
            <value
              eval="[('module', '=', 'product'), ('name', '=', 'product_comp_rule')]"
              />
        </function>
        <value eval="{'noupdate': True}" />
    </function>
3

In Odoo 13 the XML solution worked just without the comments

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

    <record id="product.product_comp_rule" model="ir.rule">
        <field name="name" >All Products (Parent Company)</field>
        <field name="model_id" ref="product.model_product_template"/>
        <field name="global" eval="True"/>
        <field name="domain_force">['|','|',('company_id','=',user.company_id.id),('company_id','=','False'),('company_id','child_of',[user.company_id.id])] </field>
    </record>

    <!-- reset noupdate -->
    <function name="write" model="ir.model.data">
        <function name="search" model="ir.model.data">
            <value eval="[('module', '=', 'product'), ('name', '=', 'product_comp_rule')]"/>
        </function>
        <value eval="{'noupdate': True}" />
    </function>

The issue was already reported by someone else https://github.com/odoo/odoo/issues/45592

0

We can do it in another sample way using noupdate="0"

<data noupdate="0">
    <record id="product.product_comp_rule" model="ir.rule">
        <field name="name" >All Products (Parent Company)</field>
        <field name="model_id" ref="product.model_product_template"/>
        <field name="global" eval="True"/>
        <field name="domain_force">['|','|',('company_id','=',user.company_id.id),('company_id','=','False'),('company_id','child_of',[user.company_id.id])] </field>
    </record>
</data>
1
  • 1
    The solution isn't working from odoo 8 onwards, hence you need first to disable the update for that specific record and write your changes, then preferably put back the noupdate = True Mar 4, 2021 at 22:27

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.