This question has been flagged
1 Reply
10925 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"/>
        </tree>
    </field>
</record>

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?

Avatar
Discard

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

Best Answer

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"/>
        </tree>

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!
 

 

Avatar
Discard
Author

Great Bole!! Thank you very much again!