Odoo Help


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.


[SOLVED] How to see delete buttons on a tree view?

Juan Formoso
on 10/24/14, 5:53 AM 1,286 views

I created a new model called res.partner.link.category. Then, I created a button which opens a customized tree of that model. Here is the function called by the button and which returns the tree:

def open_history(self, cr, uid, ids, context=None):
    rplc_obj = self.browse(cr, uid, ids[0], context=context)
    data_obj = self.pool.get('ir.model.data')
    tree_data_id = data_obj._get_id(cr, uid, 'res_partner_extended', 'res_partner_link_category_tree_view')
    form_data_id = data_obj._get_id(cr, uid, 'res_partner_extended', 'res_partner_link_category_edit_form_view')
    tree_view_id = False
    form_view_id = False
    if tree_data_id:
        tree_view_id = data_obj.browse(cr, uid, tree_data_id, context=context).res_id
    if form_data_id:
        form_view_id = data_obj.browse(cr, uid, form_data_id, context=context).res_id
    return {
        'name': 'History of "%s"' % rplc_obj.link_category_id.name,
        'view_type': 'form',
        'view_mode': 'tree',
        'view_id': False,
        'views': [(tree_view_id, 'tree'), (form_view_id, 'form'),],
        'res_model': 'res.partner.link.category',
        'domain': '[("partner_id", "=", %d), ("link_category_id", "=", %d)]' % (rplc_obj.partner_id, rplc_obj.link_category_id.id),
        'type': 'ir.actions.act_window',
        'nodestroy': True,
        'target': 'new',
        'flags': {'tree': {'action_buttons': True},
                  'form': {'action_buttons': True},}

And this is the XML of the tree which is being shown:

<record id="res_partner_link_category_tree_view" model="ir.ui.view">
    <field name="name">res.partner.link.category.tree</field>
    <field name="model">res.partner.link.category</field>   
    <field name="type">tree</field>
    <field name="arch" type="xml">
        <tree string="Link categories">
            <field name="type"/>
            <field name="date"/>
            <field name="observations"/>

Everything is OK, except for the lack of delete buttons in the tree. I need them, why can't I see them? Is there any option or flag (like action_buttons) which must be specified? How can I show them?

I'd say these buttons only appear when the tree is inside a form in edit mode.

Pau Ubach
on 10/24/14, 6:03 AM


| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 10/24/14, 7:13 AM

Primary tree view that shows model, by default have no delete button.
Instead, you can select records and then select Delete records from top menu "More".


Delete buttons ("trash can" icon) are visible when shoving tree view as nested inside x2many fields.
The reason for this is: menu More on top of page is for main model, and we need a mechanism alowing to delete some (usualy) lines from related model...

Ugly hack that will show Delete button in tree view of main model is: 
define a tree view like:

<tree string="Link categories">
            <field name="type"/>
            <field name="date"/>
            <field name="observations"/>

<button type="object" icon="gtk-delete" name="unlink"/>

and then add unlink method in your class.
Now you will have delete button visible in tree view of main model... 

hope it helps...

may the source be with you!


Great Bole!! Thank you very much again!

Juan Formoso
on 10/24/14, 7:55 AM

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

2 follower(s)


Asked: 10/24/14, 5:53 AM
Seen: 1286 times
Last updated: 3/16/15, 8:10 AM