odoo中compute字段

admin 2019-11-4 6886

刷新的问题:

有兄弟想用一个字段来实现距离截止时间还有多久的计算字段,但不会实时刷新。具体的原因解释如下:

A computed field is (re)evaluated whenever some of its dependencies are modified.
计算字段是根据其依赖的字段改变而重新计算的。

If you don't specify dependencies with @depends, nothing triggers its evaluation.
如果未指定@depends,则不会触发重新计算。

This is not a bug, what you get is the expected behavior.
这不是BUG,是正常的逻辑行为。

If the field really has no dependency, simply add a @depends on a required field.
如果字段确实不依赖其他字段,可以使之依赖一个必录字段。

If the field should not be reevaluated, do not define it as a computed field and override the method create instead.
如果字段不需要重新计算,则不要定义成compute字段,而在覆盖create方法来填值。

----------

附一个变通的办法:

1、定义另一个计算字段,以当前时间为值

2、原计算字段依赖刚定义的新字段,就可以实现实时计算


最新回复 (0)
返回