This question has been flagged

Hello, 

   I have a custom module that adds an item to the "More" button dropdown from the tree view.  The item calls a function which creates a new sales order like it's supposed to do.  The problem is, I would like to open the Sales Order form after the record is created, but for some reason it isn't doing that.

Here is my return statement 

return {
            'name': 'Sale Order',
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': self.pool.get('ir.ui.view').search(cr, uid, [('name','=','sale.order.form')])[0],
            'res_model': 'sale.order',
            'res_id': new_order_id,
            'type': 'ir.actions.act_window',
        }

This block of code works for other things, but it doesn't work when opening a form from a tree view that calls a function when an item in the "More" dropdown menu is clicked.

Avatar
Discard
Best Answer

You shuoldn't need view_id at all, that's only useful when you have multiple, diverging view definitions and need to pick a non-standard one.  If you really wanted to select a specific view, use the XML ID instead:

xml_id_obj = self.pool['ir.model.data']
form_id = xml_id_obj.get_object_reference(cr, uid, 'sale', 'view_order_form')[1]
return {
    'name': 'Sale Order',
    'view_type': 'form',
    'view_mode': 'form',
    'views': [(form_id,'form')],
    'res_model': 'sale.order',
    'res_id': new_order_id,
    'type': 'ir.actions.act_window',
}

Avatar
Discard