How to update the domain of an existing act_window

Hi folks. I need to update the domain of an existing act_window of the products module, which is the following.

<record model="ir.action.act_window" id="act_template_by_category">
            <field name="name">Product by Category</field>
            <field name="res_model">product.template</field>
            <field name="context"
                eval="{'categories': [Eval('active_id')]}" pyson="1"/>
            <field name="domain"
                eval="[('categories_all','child_of', [Eval('active_id')], 'parent')]"
                pyson="1"/>
        </record>

From a new module I want to edit the domain, so that it looks like this.

<field name="domain"   
eval="['AND',('categories_all','child_of', [Eval('active_id')], 'parent'), 'type','=','goods')]"
    pyson="1"/>

Thanks in advance.

I am not very sure what exactly you want to do, but my guess is that you want to limit or filter the products displayed in a existing list/form. Then the approach I will take is to create a ir.rule and set the domain that you need.

Something like this:

        <record model="ir.rule.group" id="rule_group_product_by_cat">
            <field name="name">Products by Active Cat</field>
            <field name="model" search="[('model', '=', 'product.template')]"/>
            <field name="global_p" eval="False"/>
            <field name="perm_read" eval="True"/>
            <field name="perm_write" eval="True"/>
            <field name="perm_create" eval="True"/>
            <field name="perm_delete" eval="False"/>
        </record>
        <record model="ir.rule" id="rule_product_cat_1">
            <field name="domain" eval="[('categories_all','child_of', [Eval('active_id')], 'parent')]" pyson="1"/>
            <field name="rule_group" ref="rule_group_product_by_cat"/>
        </record>

I hope it helps.

It is not good to update existing action (but doable if you use the same id but prefixed by the original module). You should consider create a new one with his own domain.

Access right should not be used for convenient display but only to apply global restrictions.

Thanks for the reply, I want to change an action in the product category tree view, that when double clicked opens a new tab with the products that have that category. But I want that action to filter me also the products that are of type goods.

Thanks for the reply, it happens that if I create a new action, when I double click on the product category tree it does not take this new action, so I think that I should update or delete the existing action. By adding the prefix of the original module I got what I needed. I am left like this:

<record model="ir.action.act_window" id="product.act_template_by_category">
            <field name="name">Product by Category</field>
            <field name="res_model">product.template</field>
            <field name="context"
                eval="{'categories': [Eval('active_id')]}" pyson="1"/>
            <field name="domain"
                eval="['AND',('categories_all','child_of', [Eval('active_id')], 'parent'),('type','=','goods')]"
                pyson="1"/>
        </record>

Why is it not good to update existing actions?

This is because you did not register your action with a keyword tree_open.

Indeed you could deactivate the original action with just:

<record model="ir.action.act_window" id="product.act_template_by_category">
    <field name="active" eval="False"/>
</record>

Because some code may depend on it but also because on each update trytond-admin will update first with the initial value (or log a warning because the record has changed) when processing the original module and then update it with processing your module.

Thank you very much for clarifying all my doubts, I am going to do it the right way, deactivating the original one and generating a new action.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.