function类型的字段,怎么在试图做筛选条件啊???????????
-
def _get_stock_qty(self, cr, uid, ids, field_names=None, arg=False, context=None):
res = {}
print ids
if len(ids) == 0:
return res
if context and context.has_key('location'):
for id in ids:
cr.execute(
'''select stock_qty get_stock_qty from starmerx_inventory where location_id=%s and type='shelf' and product_id=%s''',
(context.get('location'), id,))
result = cr.dictfetchall()
if result:
res[id] = result[0]['get_stock_qty']
else:
print id
res[id] = 0
return res字段的定义:不保存在数据库
_columns = {
'get_newstock_qty': fields.function(_get_stock_qty, string=u"库存数量", type='integer'),
}我现在想搜索库存大于0的。在xml
《filter string="库存大于0" domain="[('get_newstock_qty', '>', '0')]"/》
不起作用。何解? -
@winbo
def _get_stock_qty:
此处是你的代码.....
#猜测你的代码应该是在product对象上,所以搜索stock_qty大于0的product_id,返回标准domain三元组: [('xxx', 'operator', 'yyy')], 其中 xxx: id, yyy: Search value.
def _search_positive_stock(self, cr, uid, ids, field_names, args, context=None):
if context and context.has_key('location'):
cr.execute(
'''select product_id from starmerx_inventory st_inv where location_id=%s and type='shelf' and product_id in %s where st_inv.stock_qty>0''', (context.get('location'), ids,))
res = cr.fetchall()
if res:
return [('id', 'in', [x[0] for x in res])]
return [('id', '=', 0)]
@以上代码尚未经过调试,写的只是思路.
#fnct_search:加上此属性来允许搜索get_newstock_qty函数字段
_columns = {
'get_newstock_qty': fields.function(_get_stock_qty, string=u"库存数量", type='integer', fnct_search=_search_positive_stock),
}xml: <filter string="库存大于0" domain="[('get_newstock_qty', '>', 0)]"/>
-
@Felix_Cheng 非常感谢 您能抽取宝贵时间来回答,有这个思路我就知道了。太感谢了!!