Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Form view doesn't open from function

By
Eric
on 9/2/14, 3:39 PM 1,038 views

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.

0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 9/9/14, 3:32 AM

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',
}

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/2/14, 3:39 PM
Seen: 1038 times
Last updated: 3/16/15, 8:10 AM