在odoo 8中布尔字段上的onchange函数 [英] onchange functions on boolean fields in odoo 8

查看:78
本文介绍了在odoo 8中布尔字段上的onchange函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道onchange函数如何与布尔和整数字段一起工作. 假设将一个布尔字段更改为True,则应更改各个整数的值.

i would like to know how onchange function works with boolean and integer fields. Suppose if one boolean field get changed to True, the value of respective integer should be changed.

谢谢.

推荐答案

@ api.onchange

如果装饰器中指定的任何字段以以下形式更改,则该装饰器将触发对装饰函数的调用:

This decorator will trigger the call to the decorated function if any of the fields specified in the decorator is changed in the form:

@api.onchange('fieldx')
def do_stuff(self):
   if self.fieldx == x:
       self.fieldy = 'toto'

在上一个示例中,self对应于当前在表单上编辑的记录.在on_change上下文中时,所有工作都在缓存中完成.因此,您可以在函数内更改RecordSet,而不必担心更改数据库.这就是@ api.depends

In previous sample self corresponds to the record currently edited on the form. When in on_change context all work is done in the cache. So you can alter RecordSet inside your function without being worried about altering database. That’s the main difference with @api.depends

函数返回时,缓存和RecordSet之间的差异将返回到表单.

At function return, differences between the cache and the RecordSet will be returned to the form.

视图管理

View management

新API的一项重大改进是onchange会以一种简单的方式自动为您插入到表单中.您不必再担心修改视图.

One of the great improvement of the new API is that the onchange are automatically inserted into the form for you in a simple way. You do not have to worry about modifying views anymore.

警告和域名

Warning and Domain

要更改域或发送警告,只需返回常规词典即可.在这种情况下,请不要使用@ api.one,因为它会破坏字典(将其放入列表中,Web客户端不支持该列表).

To change domain or send a warning just return the usual dictionary. Be careful not to use @api.one in that case as it will mangle the dictionary (put it in a list, which is not supported by the web client).

这篇关于在odoo 8中布尔字段上的onchange函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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