This question has been flagged
1 Reply
6299 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.

Avatar
Discard
Best Answer

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,

 

Avatar
Discard
Author

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?)

Author

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

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