Openerp中的Onchange功能 [英] Onchange function in Openerp

查看:84
本文介绍了Openerp中的Onchange功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在account.invoice.line中有一个名为form_type的选择字段.它具有三个选择选项:

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

account.invoice.line中还有一个名为 flag 的整数字段.选择form_c时,标志值应设置为1;否则,标志值应设置为1.否则,如果选择了form_a或form_b,则标志值应设置为0.对于上述情况,我编写了一个 onchange 函数,但它不起作用.有人可以帮我吗?我的代码有什么问题?

There is also an integer field named flag in account.invoice.line. When form_c is selected, the flag value should be set to 1; otherwise, 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 it's not working. Can someone help me out? What is wrong in my 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}

account.invoice.line中用于onchange的XML代码是:

My XML code in account.invoice.line for onchange is:

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

推荐答案

在变更函数中,您无需调用对象的浏览功能,因为这些值尚未存储在数据库中.另外,您正在将"form_type"值传递给函数,而不是对象ID(因为浏览器接受对象ID).

In your on-change function you don't need to call the browse function of the object, because the values are not stored in the database yet. Also, you are passing the "form_type" value to the function and not the object id(as browse accepts object id).

因此,下面将是满足预期要求的on_change函数:

So, below will be the on_change function, for the expected requirement:

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}

这篇关于Openerp中的Onchange功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆