我被这个问题卡住了,有人能帮我吗?我想要一份某一picking_id的stock.pack.operation版产品清单。我通过表单视图使用上下文传递picking_id。当我尝试设置选择字段时,我什么也得不到,但当我尝试使用Char字段时,它可以工作。
代码如下:
def _default_products_list(self):
active_id = self.env.context.get('default_picking_id', []) or []
vals=[]
for record in self.env['stock.pack.operation'].search([('picking_id','=',active_id)]):
vals.extend([(record.product_id.name,record.product_id.name)])
return vals
name = fields.Char(string='test', required=True, default=_default_products_list)
product = fields.Selection(_default_products_list, string="Product")发布于 2018-02-21 21:21:19
您可以使用many2one并添加filter,以便仅显示当前picking_id中的产品
@api.onchange('picking_id')
def on_change_picking_id(self):
""" add domain to product id to show only product that are in the current picking"""
if self.picking_id:
# i'm not in my compute i forget how to get list of ids from picking_id
picking_product_ids = self.picking_id.mapped('move_lines.product_id').ids
return {'domain': {'product_id': [('id', 'in', picking_product_ids)]}}
else:
# remove domain to show all products
return {'domain': {'product_id': []}}https://stackoverflow.com/questions/48883694
复制相似问题