如何在Odoo 8中为计算字段设置存储触发器? [英] How to set store trigger for computed fields in Odoo 8?

查看:127
本文介绍了如何在Odoo 8中为计算字段设置存储触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用Odoo v8.0的新API,但在这样的计算字段(对于v7.0和v6.1)中找不到关于存储触发器的有用信息:

I started using the new API of Odoo v8.0 but I cannot find useful information about store trigger in computed fields like this (for v7.0 and v6.1): Store Parameter in Odoo v6

在Odoo v8.0中,我尝试使用与v7.0相同的语法,但是由于JSON响应无法返回到Web客户端,所以我无法使其工作:

In Odoo v8.0, I tried to use the same syntax of v7.0 but I couldn't get it to work because the JSON response cannot be returned back to the web client:

<function _store_trigger> is not JSON serializable.

然后我读取到该存储参数已转换为仅布尔值字段(触发器无字典): Odoo存储功能:JSON不可序列化

I read then that store parameter had been converted to Boolean only field (no dict for triggers): Odoo store function: JSON not serializable

那么,如何设置触发器以将值存储在数据库中以计算(及相关)字段呢?我想主要为它们创建过滤器和组,所以search function不会有用.

So how can I set trigger to store values in database for computed (and related) fields? I want to make filters and groups mainly for them so search function won't be useful.

推荐答案

在V8中,可以将任何字段用作计算字段.在V8中,store是一个布尔型参数,默认情况下为 false .

In V8, you can use any fields as computed fields. In V8 store is a parameter which is a boolean and by default it is false.

如果您显式设置为"store = True",则您在 @ api.depends('name')中提到的从属字段将用作触发字段.

If you set explicitly "store=True", the dependent field you mentioned in @api.depends('name'), will acts as a triggering field.

您可以将另一个对象字段指定为触发字段,该字段必须在计费模块中,例如 @ api.depends('other_object.field_name')

You can specify, the other object field as a triggering field which will be must in accounting module like @api.depends('other_object.field_name')

upper = fields.Char(compute='_compute_upper', store=True)

@api.depends('name')
def _compute_upper(self):
    for rec in self:
        self.upper = self.name.upper() if self.name else False

如果它为"false",则该值不存储在数据库中,并且每次都会计算.

If it "false", then the value is not stored in database and will be computed everytime.

upper = fields.Char(compute='_compute_upper')

这篇关于如何在Odoo 8中为计算字段设置存储触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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