0
votes

In the manufacturing bill of materials (mrp.bom model) form view, There is a list of components that make up a product. I want to add a button to the list view that opens the product component in a pop up.

I have tried this code but the button is opening the wrong product item. Please help me resolve what I am doing wrong.

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
            }
2

2 Answers

2
votes

Here ids[0] will give you id of bom line, and in bom line there is reference of product.product not product.template.

so if you wanted to open a product you need to write a method like,

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,
            }
0
votes

Here the res_id you are passing is wrong. it should be the id of the product.template record