python – 在OpenERP 7.0的列表视图中按选择排序
作者:互联网
在OpenERP 7列表视图中,我想显示订单草稿中的状态值排序,当前在Asc或Desc中显示已分配和取消.但在我的情况下,我们需要在订单草稿,分配和取消状态中进行排序.基于在python文件中的顺序应用
例如在SQL代码中 –
select state, date from object_name
ORDER BY CASE WHEN state = 'draft' THEN 0
WHEN state = 'assigned' THEN 1
WHEN state = 'cancel' THEN 2
ELSE 3
END, date desc
上面的sql代码在python中应用
_order = ("CASE WHEN state='draft' THEN 0",
"WHEN state = 'assigned' THEN 1",
"ELSE 2 END, date desc")
在上面的查询排序选择值工作在pg_admin但在python代码中它显示错误
Invalid "order" specified. A valid "order" specification is a comma-separated
list of valid field names (optionally followed by asc/desc for the direction)
基于此排序顺序的选择值如何在OpenERP中应用?覆盖搜索方法也应用了相同的sql查询但显示相同的问题.
解决方法:
尝试使用store属性创建一个功能字段,该属性在状态更改时加载函数.
例如
def _get_state(cr, uid, ids,field_name, context=None):
res={}
for obj in self.browse(cr, uid, ids, context):
res[obj.id] = (obj.state=='draft' and 0) or (obj.state=='assigned' and 1) or (obj.state=='cancel' and 2) or 3
return res
_columns = {
current_state_num: fields.function(_get_state,string='Current state',type='integer',store={'your.current.model.name':(lambda cr, uid, ids, context:ids,['state'],20)})
}
_order = "current_state_num,date desc"
标签:python,openerp,postgresql-8-4 来源: https://codeday.me/bug/20190703/1368510.html