How to set store trigger for computed fields in Odoo 8?

房东的猫 提交于 2020-01-16 12:09:05

问题


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

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.

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

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.


回答1:


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.

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

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

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

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


来源:https://stackoverflow.com/questions/29537608/how-to-set-store-trigger-for-computed-fields-in-odoo-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!