按函数/计算字段分组 "store = True"

Group by function / computed field with out "store = True"

我想按计算域分组 (type_client)。

我知道我应该做到store = True,但我做不到,因为值是动态的。还有其他选择吗?

这是我的功能:

    def act_show_supect(self):
    for objctf in self:
        for client in self.env['res.partner'].search([('user_id.id', '=', self.user_id.id),
                                                      ('company_type', '=', 'company'),
                                                      ('type_client', '=', 'suspect')]):
            if client.type_client == 'suspect':
                objctf.ensure_one()
                res = objctf.env['ir.actions.act_window'].for_xml_id(
                    'base', 'action_partner_form')
                res.update(
                    context=dict(
                        objctf.env.context,
                        search_default_user_id_id=objctf.user_id.id,
                        search_default_type_client='suspect',
                    ),
                    domain=[('user_id.id', '=', objctf.user_id.id),
                            ('company_type', '=', 'company'),
                            ('type_client', '=', 'suspect')]
                )

                return res

这是执行后的错误:

  File "E:\odoo11.0\odoo\models.py", line 1908, in read_group
    result = self._read_group_raw(domain, fields, groupby, offset=offset, 
    limit=limit, orderby=orderby, lazy=lazy)

  File "E:\odoo11.0\odoo\models.py", line 1946, in _read_group_raw
    assert gb_field.store and gb_field.column_type, "Fields in 'groupby' 
    must be regular database-persisted fields (no function or related 
    fields), or function fields with store=True"

  AssertionError: Fields in 'groupby' must be regular database-persisted 
    fields (no function or related fields), or function fields with 
    store=True

我想分组:

('type_client', '=', 'suspect')

好的,让我们做一个小的解决方法:

您必须添加 @api.depends(您的工作所依赖的字段),每次您更改依赖字段的值时,此方法都会 运行。