onchange function

Asked by Pravitha V

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

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Pravitha V
Solved:
Last query:
Last reply:
Revision history for this message
Damián Soriano (damiansoriano) said :
#1

The invoice parameter of the onchange_form_type function is not the invoice but the field form_type, since you are passing that in the xml code.

So, when you are browsing the records with

invoice = self.pool.get('account.invoice.line').browse(cr, uid, invoice)

the invoice variable contains the field that was setted and not the id of the invoices. Try doing the following:

def onchange_form_type(self, cr, uid, ids, form_type, context=None):
    if form_type=="form_c":
        flag="1"
    else:
        flag="0"

    val = { 'flag':flag,}
    return {'value': val}

And the XML code:

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

Revision history for this message
Pravitha V (pravithavarghese1) said :
#2

thankyou that really helped