Odoo Help

0

[SOLVED] How to return a tree in a function with several fields?

By
Juan Formoso
on 10/20/14, 6:20 AM 1,329 views

I have made a button which calls a function. This function shows a popup with all the records of a model (in mode tree view). When I click on the button, I am seeing the tree view with all the records of the model I want, but only one of their fields (the name). I would like to show more properties. Anyone knows what I have to do?

Here my code (the return of the function):

return {
            'view_type': 'tree',
            'view_mode': 'tree',
            'res_model': 'my.model',
            'type': 'ir.actions.act_window',
            'target': 'new',
            'flags': {'tree': {'action_buttons': False}} 
}

Thank you in advance.

1

Hello,

Hint : By default, If no view specified at action return time (which you have did in your example), then OpenERP creates itself tree view and return only "Name" column.

In Order to achieve your purpose, you need to find the tree view and form view and add those into return dictionary.

For example see below code, ( See Bold Lines & you will understand what I am trying to say )

   def button_click_method(self, cr, uid, ids, context=None):
        self_obj = self.browse(cr, uid, ids, context=context)[0]
        product_ids = []
        if self_obj.product_ids:
            product_ids = [ int(x) for x in self_obj.product_ids.split(', ')]
        data_obj = self.pool.get('ir.model.data')
        data_id = data_obj._get_id(cr, uid, 'product', 'stone_tree_view_ept')
        view_id = False
        if data_id:
            view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
        form_data_id = data_obj._get_id(cr, uid, 'product', 'stone_form_view_ept')
        if form_data_id:
            form_view_id = data_obj.browse(cr, uid, form_data_id, context=context).res_id
        
        context.update({'active_ids': [],'no_complete_name':1})
        return {
                   'name': _('Stones'),
                   'view_type': 'form',
                   'res_model': 'product.product',
                   'view_id': False,
                   'domain':"[('id', 'in',%s)]" %(product_ids),
                   'context': context,
                   'views': [(view_id, 'tree'), (form_view_id, 'form')],
                   'type': 'ir.actions.act_window',
                   'target': 'current',
                   'nodestroy': True
               }

If you have not created Tree and Form view then please create them first.

Hope this answer will help you,

 

Thank you Hiren Vora. I created the view (id="my_model_view", name="my.model.tree"). I copied your code and changed the necessary lines, but I got an error. What do I have to put in data_id = data_obj._get_id(cr, uid, 'product', 'stone_tree_view_ept')? I mean instead of 'product' (my model?) and 'stone_tree_view_ept' (the id of the view?)

Juan Formoso
on 10/20/14, 9:41 AM

Oooohhh!!! I gotta!! It was the name of the module! Thank you so much! You helped me a lot!

Juan Formoso
on 10/20/14, 10:01 AM

I am happy that your problem is solved. After all you learned something new that matters for me !

Viraj Joshi
on 10/20/14, 10:15 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 10/20/14, 6:20 AM
Seen: 1329 times
Last updated: 3/16/15, 8:10 AM