我想按计算字段(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')
答案 0 :(得分:2)
好的,让我们做一个小解决方法:
您必须添加@api.depends
(您在工作中依赖的字段),并且此方法将在您每次更改depends字段的值时运行。