Understanding client event and overriding tree_but_open

Asked by Jonathan Liuti

Hello folks,

I'm trying to understand how the client event binding works.
To sum it up briefly, I would like to override this in product_view.xml of product base module:
(line 277)
        <record id="product_normal_action_tree" model="ir.actions.act_window">
            <field name="name">Products</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">product.product</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[('categ_id','child_of',[active_id])]</field>
            <field name="context">{'categ_id':active_id}</field>
        </record>
        <record id="ir_product_category_open" model="ir.values">
            <field eval="'tree_but_open'" name="key2"/>
            <field eval="'product.category'" name="model"/>
            <field name="name">Products by Categories</field>
            <field eval="'ir.actions.act_window,%d'%product_normal_action_tree" name="value"/>
            <field eval="True" name="object"/>
        </record>

What I would like to achieve especially is to be able to override those 2 fields in one of my module:
            <field name="domain">[('categ_id','child_of',[active_id])]</field>
            <field name="context">{'categ_id':active_id}</field>

I've tried to apply my modification directly in the core files and it works as expected, but now I would like to do it the clean way.

If someone can help me understand how to either override or redeclare this and how to bind it to the right action, I'd me more than pleased ;-)

Thx,
John

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Jonathan Liuti
Solved:
Last query:
Last reply:
Revision history for this message
fooflare (fooflare) said :
#1

Hello,

the only thing I can think of is to replace one of the fields by your custom field and replace the other field with no one.

I mean, in your inherit record:

         <field name="arch" type="xml">
             <field name="domain" position="replace">
                   <field name="your_custom_field"/>
             </field>
             <field name="context" position="replace"/>
         </field>

Regards.

Revision history for this message
Jonathan Liuti (liuti-john) said :
#2

The right way to do this is:

        <record id="product.product_normal_action_tree" model="ir.actions.act_window">
            <field name="name">Products</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">product.product</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">['|',('categ_id','child_of',[active_id]),('categ_ids','in',active_ids)]</field>
            <field name="context">{}</field>
        </record>

the id part of the record is important, you have to prefix the original id name with the model concerned. And its working as expected.

Amòs,
I didn't try your way but I think it only works for views and not record but I may be wrong.

Thanks anyway,
John.