Odoo Help


Why on_change method with one2many parameter return ids instead of value?

Randy Raharjo
on 3/2/15, 2:06 PM 1,495 views

I have two module, one parent and one child modules. Parent module have one2many field to child module. I put on_change method in the one2many field with parameter is the field itself.

In on_change method(.py file) when creating new line in one2many field, the parameter looks like


Then, I save the module, and try to edit the one2many field.

It give me


with xx and xy are id's of child.

My question is, when I change some value in child's field, how can parent know the changed value in child's field.

I already tried to browse the record of xx, and xy. It gives me the old value stored in db.

Someone pls enlighten me!

--------------------------------------------------------- EDIT ( Adding the code and some more explanation about the condition)

This is the parent XML, Field childList has on_change method that have itself as parameter

<record id="parent_form" model="ir.ui.view">
            <field name="name">belajar.parent.form</field>
            <field name="model">belajar.parent</field>
            <field name="arch" type="xml">
                <form string="Parent" version="7.0" >
                        <field name="name"/>
                        <field name="childList" on_change="onchange_childList(childList)"/>

This is parent class

class parentA(osv.osv):
    _name = 'belajar.parent'
    _description = "Belajar one2many"
    _columns = {
            'name': fields.char("Parent"),
            'childList': fields.one2many("belajar.child","parent","ChildList"),
    def onchange_childList(self,cr,uid,ids,cl,context=None):
        res = {}
        print cl
        return {'value': res}

This is Child XML

<record id="child_form" model="ir.ui.view">
            <field name="name">belajar.child.form</field>
            <field name="model">belajar.child</field>
            <field name="arch" type="xml">
                <form string="child" version="7.0" >
                        <field name="name"/>

This is child Class

class childA(osv.osv):
    _name = 'belajar.child'
    _description = "Belajar one2many"
    _columns = {
            'name': fields.char("Child"),
            'parent': fields.many2one("belajar.parent" , "Parent"),

When user editing child record in one2many field at parent form, it goes to onchange_childList and print some value. That value is different depending on the situation:

  • When creating new row /  editing that new row it returns [(0,0,{value})]
  • When editing existing row ( row from record that has been saved / created ) it return [(0,0,[xx,xy])

How can I get user value form existing row? It only gives me the ID.

Hi,, Are you editing the values from view part or by using code??

Baiju KS
on 3/3/15, 8:56 AM

Hi, thanks for the reply. I am editing from view part. Like normal user would do. Then I want the user's value to be passed to parent, in on_change method.

Randy Raharjo
on 3/4/15, 4:45 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/2/15, 2:06 PM
Seen: 1495 times
Last updated: 3/16/15, 8:10 AM