This forum is now just an archive. Use the new Q&A website
It is currently Mon Jul 28, 2014 10:15 am

All times are UTC + 2 hours




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: onchange function in openerp
PostPosted: Sat Apr 21, 2012 6:42 am 
Offline

Joined: Wed Jan 18, 2012 12:57 pm
Posts: 322
Location: cochin
i have a selection field in account.invoice.line named form_type.it has three selection options:
1)form_a
2)form_b
3)form_c

there is also a integer field named flag in account.invoice.line. when form_c is selected the flag value should be set to 1 else if either form_a or form_b is selected the flag value should be set to 0.i wrote an onchange function for the above case but its not working. can someone help me out what is wrong in my code?
Code:
def onchange_form_type(self,cr,uid,ids,invoice,context=None):
    val={}
    flag=0
    invoice = self.pool.get('account.invoice.line').browse(cr, uid, invoice)
    for invoice in self.browse(cr, uid, ids,context=context):
        if invoice.form_type=="form_c":
            flag="1"
        else:
            flag="0"

    print flag
    val = {
            'flag':flag,

             }
    return {'value': val}


my xml code in account.invoice.line for onchange is:

Code:
<field name="form_type" on_change="onchange_form_type(form_type)"/>

_________________
Regards,
Nightfury


Top
 Profile  
 
 Post subject: Re: onchange function in openerp
PostPosted: Mon Apr 23, 2012 11:28 am 
Offline

Joined: Wed Jan 18, 2012 12:57 pm
Posts: 322
Location: cochin
In the on-change function there is no need to call the browse function of the object, because the values are not stored in the database yet. Also, we are passing the "form_type" value to the function and not the object id(as browse accepts object id).

So, below will be the on_change function
Code:
def onchange_form_type(self, cr, uid, ids, form_type, context=None):

    val={}
    flag=0
    if form_type == 'form_c':
        flag="1"
    val = { 'flag': flag }
return {'value': val}

_________________
Regards,
Nightfury


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP