This question has been flagged
2 Replies
11286 Views

Shortly. I would like to add on_change function to categ_id field in product.product_normal_form_view.

I have something like that:

<record id="product_normal_form_view_smart" model="ir.ui.view">
        <field name="name">product_normal.form.attribute</field>
        <field name="model">product.product</field>
        <field name="inherit_id" ref="product.product_normal_form_view"/>
        <field name="arch" type="xml">
            <data>
                <xpath expr="/form/sheet/notebook" position="inside">
                        <field name="categ_id" on_change="on_change_categ_id()"/>
                </xpath>
            </data>
        </field>
    </record>

But it doesn't work, because now it adds new field. Problem is that I don't want add new field, only change existing one.

P.S. Of course I inherited product.product in py code.

Avatar
Discard
Author Best Answer

Ok. I solved it.

<record id="product_normal_form_view_smart" model="ir.ui.view">
    <field name="name">product_normal.form.attribute</field>
    <field name="model">product.product</field>
    <field name="inherit_id" ref="product.product_normal_form_view"/>
    <field name="arch" type="xml">
        <data>
               <field name="categ_id"  position="attributes">
                    <attribute name="on_change">on_change_categ_id()</attribute>
                </field>
        </data>
    </field>
</record>
Avatar
Discard
Best Answer

If you want to replace the field "categ_id", why not use:

<record id="product_normal_form_view_smart" model="ir.ui.view">
    <field name="name">product_normal.form.attribute</field>
    <field name="model">product.product</field>
    <field name="inherit_id" ref="product.product_normal_form_view"/>
    <field name="arch" type="xml">
        <data>
            <field name ="categ_id" position="replace">
                <field name="categ_id" on_change="on_change_categ_id()"/>
            </field>
        </data>
    </field>
</record>

Don't forget to add the method on_change_categ_id to your object product_product (if it doesn't exist).

Avatar
Discard