我在这里将product_id
添加到val字典中,但问题是,如果有多个产品,如何将每行的product_id
添加到该dict vals中。可能我需要列出product_ids
的列表,然后将其添加到字典中,但是有点麻烦
@api.multi
def button_details(self):
domain = [
('product_tmpl_id', '=', self.product_id.id)
]
vals = {}
bom_products = self.env['mrp.bom'].search(domain)
for bom_line in bom_products.bom_line_ids:
vals['product_id'] = bom_line.product_id.id
vals['product_uom_qty'] = bom_line.product_qty
context = self.env.context.copy()
context['view_buttons'] = True
view_id = self.env.ref('config.view_order_line_form_view').id
view = {
'name': _('Details'),
'view_type': 'form',
'view_mode': 'tree, form',
'res_model': 'sale.order.line',
'views' : [(view_id,'tree')],
'type': 'ir.actions.act_window',
'target': 'new',
'readonly': True,
# 'res_id': ,
'context': context
}
return view
已更新的最终目标是打开一个按钮,该按钮由按钮触发,其中包含我要从bom.line提取的产品和数量
答案 0 :(得分:2)
bom_products = self.env['mrp.bom'].search(domain)
vals['product_id'] = bom_products.bom_line_ids.mapped('product_id.id')