One2many字段domain实现, 并使用filter视图中的变量
-
[size=14pt]新类
class my_model(osv.osv):
_name = "my.model"
_description = 'abc'
_columns = {
'product_id': fields.many2one('product.product', u'产品'),
'move_in': fields.many2one('stock.move', u'入库记录'),
'location_id': fields.many2one('stock.location', u'在库库位'),
.........................
}
my_model()
产品类
class product_product(osv.Model):
_inherit = 'product.product'
_columns = {
'my_model': fields.one2many('my.model', 'product_id', u'my_model', domain=['&',('move_in','!=',False),('move_in.state','=','done')]),
}
product_product()
[b]本站有贴子说有one2many的domain只能在py文件中实现, 不能在xml文件中实现.[/b]
[b]视图文件不变, 现在再修改py文件如下:[/b]
class product_product(osv.Model):
_inherit = 'product.product'
_columns = {
'my_field': fields.function(_get_juan, method=True, string = u'分卷', type='one2many',relation='my_model'),
}
product_product()
def _get_juan(self, cr, uid, ids, name, arg, context=None):
res = {}
jids = []
obj = self.pool.get('my_model')
for product in self.browse(cr,uid,ids):
if context.get('location', False):
location_ids = [context['location']]
else:
location_ids = ........
args = [('product_id','=',product.id)]
args += [('location_id','in',location_ids)]
res[product.id] = obj.search(cr,uid,args)
return res[/size]