This question has been flagged

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

[(0,0,{value})]

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

It give me

[(6,0,[xx,xy])]

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" >
                    <group>
                        <field name="name"/>
                        <field name="childList" on_change="onchange_childList(childList)"/>
                    </group>
                </form>
            </field>
        </record>

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" >
                    <group>
                        <field name="name"/>
                    </group>
                </form>
            </field>
        </record>

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.

Avatar
Discard

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

Author

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.