Odoo(openerp)中@ api.onchange和@ api.depends之间的主要区别是什么? [英] What is Main difference between @api.onchange and @api.depends in Odoo(openerp)?

查看:600
本文介绍了Odoo(openerp)中@ api.onchange和@ api.depends之间的主要区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Odoo v8中,使用了许多API装饰器. 但我不了解 @ api.depends @ api.onchange 之间的主要区别.

In Odoo v8 there are many API decorators used. But i don't understand the main difference between @api.depends and @api.onchange.

有人可以帮助我吗?

谢谢.

推荐答案

@ api.depends

此装饰器专门用于odoo中的"fields.function".对于"field.function",您可以计算该值并将其存储在一个字段中,在该字段中,计算可能取决于同一表或某些其他表的某些其他字段,在这种情况下,您可以使用"@ api.depends"可在某些表的字段上保持监视"状态.

This decorator is specifically used for "fields.function" in odoo. For a "field.function", you can calculate the value and store it in a field, where it may possible that the calculation depends on some other field(s) of same table or some other table, in that case you can use '@api.depends' to keep a 'watch' on a field of some table.

因此,如果装饰器中的任何字段被由ORM更改或以表单更改" ,则这将触发对装饰函数的调用.

So, this will trigger the call to the decorated function if any of the fields in the decorator is 'altered by ORM or changed in the form'.

比方说,存在一个具有字段"x,y& z"的表"A"和具有字段"p"的表"B",其中"p"是一个field.function,取决于字段表'A'中的x',因此,如果在字段'x'中进行了任何更改,它将触发修饰后的函数,用于计算表'B'中的字段'p'.

确保表"A"和"B"以某种方式关联.

Make sure table "A" and "B" are related in some way.

@ 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. Here scope is limited to the same screen / model.

让我们在表单上说我们有字段"DOB"和"Age",因此我们可以使用@ api.onchange装饰器作为"DOB",在其中,您只要更改"DOB"的值,就可以计算出年龄"字段.

Let's say on form we have fields "DOB" and "Age", so we can have @api.onchange decorator for "DOB", where as soon as you change the value of "DOB", you can calculate the "age" field.

您可能会在@ api.depends和@ api.onchange中找到相似之处,但是一些区别是onchange的范围仅限于同一屏幕/模型,而@ api.depends也可以使用其他相关的屏幕/模型.

You may field similarities in @api.depends and @api.onchange, but the some differences are that scope of onchange is limited to the same screen / model while @api.depends works other related screen / model also.

有关更多信息,此处是描述所有内容的链接Odoo v8的API.

For more info, Here is the link that describe all API of Odoo v8.

这篇关于Odoo(openerp)中@ api.onchange和@ api.depends之间的主要区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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