Openerp 在树状视图中打开产品记录的按钮

Openerp 在树状视图中打开产品记录的按钮,openerp,odoo,Openerp,Odoo,在“制造bom表(mrp.bom模型)”表单视图中,有组成产品的零部件列表。我想在列表视图中添加一个按钮,在弹出窗口中打开产品组件 我已尝试此代码,但按钮打开的产品项目错误。请帮我解决我做错了什么 class mrp_bom_line(osv.osv): _inherit = ['mrp.bom.line'] def open_full_record(self, cr, uid, ids, context=None): return { '

在“制造bom表(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

此处id[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,
            }