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 to use On change function?

By
Fransis L. Yoas
on 7/8/13, 2:54 AM 9,687 views

I want to put a selection for category, and when people select spesific category (for example : email issue) I want that all the fields below change to fit that category.

0
Fransis L. Yoas
On 7/9/13, 7:47 AM

Thanks for the answer.
I've found the right answer using attrs {'invisible':[('x_rwis','not in',['a'])]}

Please correct the right answer. Thank you.

Krupesh Laiya
on 2/20/14, 2:53 AM
5
Sreedath Namangalam
On 7/8/13, 3:03 AM

In XML,

Eg:-

<record id="id" model="ir.ui.view">
        <field name="name">xxxx</field>
        <field name="model">xxxx.xx</field>
        <field name="arch" type="xml">
            <form string="string" version="7.0">
                <group col="4">
                    <field name="aaa"/>
                    <field name="bbb" on_change="onchange_bbb(bbb)"/>
                    <field name="ccc"/>
                    <field name="ddd"/>
                </group>
            </form>
        </field>
    </record>

We pass the value bbb to the py file.

In Python:

Eg:-

def onchange_email(self, cr, uid, ids, bbb, context=None):
        vals = {'aaa': bbb}        
        return {'value': vals}

So the value of bbb is returned onchage to the field aaa.

Thanks

Sreedath

can I do this in developers mode?

Fransis L. Yoas
on 7/8/13, 5:53 AM

code changing have nothing to do with developer/normal modes ryt?

Sreedath Namangalam
on 7/8/13, 6:05 AM

How can i delete old values using onchange function. Eg: field A value is = 10 and i am using on change function in field B. While change the value B i need to delete A old value and update new value. Kindly help me how to achieve this..Thanks

sengottuvel
on 1/11/14, 2:04 AM
3
PARVATHY VIJAYAN P
On 7/8/13, 3:02 AM

Below example shows one onchange function for age calculation from date of birth(dob)

The xml view will be

<field name="dob" on_change="onchange_getage_id(dob,context)"/>

<field name="age_text"/>

while the date field is filled the age will be seen in the another text field.

The python onchange function is

 def onchange_getage_id(self,cr,uid,ids,dob,context=None):
        current_date=datetime.now()
        current_year=current_date.year
        birth_date = parser.parse(dob)
        current_age=current_year-birth_date.year
        val = {
            'age_text':current_age
        }
        return {'value': val}

Like this you can do your function.

Thanks

Parvathy

can I do this in developers mode?

Fransis L. Yoas
on 7/8/13, 5:53 AM

Yes you can do it

PARVATHY VIJAYAN P
on 7/8/13, 7:17 AM
0
George
On 9/1/15, 8:20 AM

Hi friends,

                  I would like to change form fields label while on_change a field. The field is many2one and I have configured few items in that object. I could not use fields_view_get. While i onchange i am able to return field string but is not reflected in form view.

please help me

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

1 follower(s)

Stats

Asked: 7/8/13, 2:54 AM
Seen: 9687 times
Last updated: 6/14/16, 5:33 AM