Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How add on_change to field in inherited view?

By
Tadeusz Karpiński
on 7/2/13, 11:34 AM 5,055 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.

2

patrick

--patrick--
1958
| 5 4 7
Baarn, Netherlands
--patrick--
patrick
On 7/2/13, 12:00 PM

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).

5
Tadeusz Karpiński
On 7/2/13, 12:00 PM

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>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 7/2/13, 11:34 AM
Seen: 5055 times
Last updated: 3/16/15, 8:10 AM