在树视图中打开产品记录的按钮
Button to Open Product Record in Tree view
在制造物料清单(mrp.bom模型)表单视图中,有一个构成产品的组件列表。我想在列表视图中添加一个按钮,用于在弹出窗口中打开产品组件。
我试过此代码,但按钮打开了错误的产品项目。请帮我解决我做错了什么。
class mrp_bom_line(osv.osv):
_inherit = ['mrp.bom.line']
def open_full_record(self, cr, uid, ids, context=None):
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'product.template',#self._name,
'res_id': ids[0],
'target': 'new',
'context': context, # May want to modify depending on the source/destination
}
这里你传递的res_id是错误的。它应该是 product.template 记录的 ID
这里的 ids[0] 会给你 bom 行的 id,在 bom 行中有参考 product.product 而不是 product.template.
所以如果你想打开一个产品,你需要写一个方法,
def open_product(self, cr, uid, ids, context=None):
rec = self.browse(cr, uid, ids[0], context)
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'product.product',
'res_id': rec.product_id.id,
'target': 'new',
'context': context,
}
在制造物料清单(mrp.bom模型)表单视图中,有一个构成产品的组件列表。我想在列表视图中添加一个按钮,用于在弹出窗口中打开产品组件。
我试过此代码,但按钮打开了错误的产品项目。请帮我解决我做错了什么。
class mrp_bom_line(osv.osv):
_inherit = ['mrp.bom.line']
def open_full_record(self, cr, uid, ids, context=None):
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'product.template',#self._name,
'res_id': ids[0],
'target': 'new',
'context': context, # May want to modify depending on the source/destination
}
这里你传递的res_id是错误的。它应该是 product.template 记录的 ID
这里的 ids[0] 会给你 bom 行的 id,在 bom 行中有参考 product.product 而不是 product.template.
所以如果你想打开一个产品,你需要写一个方法,
def open_product(self, cr, uid, ids, context=None):
rec = self.browse(cr, uid, ids[0], context)
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'product.product',
'res_id': rec.product_id.id,
'target': 'new',
'context': context,
}