Search code examples
xmlsecurityodooodoo-12record-rules

Modify existing record rule odoo


I want to put <field name="perm_create" eval="False" /> to existing record rule . so i added inherited it and added my addition .. but no effect:

<record id="hr_attendance.hr_attendance_rule_attendance_manager" model="ir.rule">
    <field name="perm_create" eval="False"/>
</record>

Solution

  • It is because of <data noupdate="1">. hr_attendance_rule_attendance_manager is defined in hr_attendance with noupdate=1. So, you cannot change it normally.

    As far as I know, there are 2 ways to solve this.

    1. Remove noupdate via UI. Settings > Technical > External Identifiers > find your record (hr_attendance.hr_attendance_rule_attendance_manager). Then, uncheck "Non Updatable" field.

    2. Remove noupdate with xml. I am referring to this question/answer. https://www.odoo.com/forum/help-1/question/how-can-i-update-a-record-stored-with-the-attribute-noupdate-1-78133

    • Find record and remove noupdate.
    <function name="write" model="ir.model.data">
        <!-- First we need to find the record...-->
        <function name="search" model="ir.model.data">
            <value eval="[('module', '=', 'purchase'), ('name', '=', 'purchase_order_comp_rule')]"/>
        </function>
        <!-- ...and temporarily set the noupdate field to False-->
        <value eval="{'noupdate': False}" />
    </function>
    
    • Apply the changes you want.
    <!-- Get our main job done, i.e. modify the domain_force field of a record -->
    <record id="purchase.purchase_order_comp_rule" model="ir.rule">
        <field name="domain_force">[('company_id','=',user.company_id.id)]</field>
    </record>
    
    • (Optional) revert back to noupdate True.
    <!-- (Optional) Time to clean our dirty hand, set the previously noupdate False to True again -->
    <function name="write" model="ir.model.data">
        <function name="search" model="ir.model.data">
            <value eval="[('module', '=', 'purchase'), ('name', '=', 'purchase_order_comp_rule')]"/>
        </function>
        <value eval="{'noupdate': True}" />
    </function>