【问题标题】:Onchange function in OpenerpOpenerp 中的 Onchange 函数
【发布时间】:2012-04-21 04:32:33
【问题描述】:

我在 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}

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

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

【问题讨论】:

    标签: python xml onchange openerp


    【解决方案1】:

    在您的 on-change 函数中,您不需要调用对象的浏览函数,因为值尚未存储在数据库中。此外,您将“form_type”值传递给函数而不是对象 id(因为浏览接受对象 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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多