Openerp Onchange函数

2024-05-12 21:12:18 发布

您现在位置:Python中文网/ 问答频道 /正文

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

1) form_a
2) form_b
3) form_c

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

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}

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

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

Tags: selfformidsuid标志typecontextline
1条回答
网友
1楼 · 发布于 2024-05-12 21:12:18

在on change函数中,不需要调用对象的browse函数,因为这些值尚未存储在数据库中。此外,您将“form_type”值传递给函数,而不是对象id(因为browse接受对象id)。

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

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}

相关问题 更多 >