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

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

By
mrpingu
on 3/2/15, 2:06 PM 904 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

[(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.

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

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

mrpingu
on 3/4/15, 4:45 AM

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: 3/2/15, 2:06 PM
Seen: 904 times
Last updated: 3/16/15, 8:10 AM