Odoo Help


Is it possible to hide delete button for some rows in a tree view ?

on 7/8/14, 11:44 AM 2,623 views


I have a view like this :

    <field name="product_line_ids" nolabel="1">
      <tree version="7.0">
        <field name="product_id" context="{'product_name_display': 'short'}" />
        <field name="name" />
        <field name="price_unit" />
        <field name="product_qty" />
        <field name="uom_id" />
        <field name="total" />
        <field name="is_included" />
        <field name="avg_price" />
        <field name="is_bought" />
        <field name="origin" />
        <field name="budget_line_id" />
        <field name="purchase_order_id" />
        <field name="type" invisible="1" />
      <form version="7.0">
        <group col="4">

Depending if purchase_order_id is False or not, I would like to enable / disable the delete button on my view.

How can I achieve this ?

Thank you very much

Thank you Bole, This is an acceptable workaround, indeed. Too bad it's not possible to have this behaviour because with your solution, an error will appear on screen. I prefer to restrict user's actions instead of having error messages. Do you know if it's possible to create some function in javascript or jquery to realize client-side validation?

on 7/11/14, 3:46 AM


| 5 4 6
Zagreb | Karlovac, Croatia

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

On 7/10/14, 1:40 PM

Normaly if you need to restrict deletion on objects you would define a view like:
<field name="product_line_ids" nolabel="1">
      <tree version="7.0" delete="false">.....

This will disable delete option completly on view 

There is no way of putting condition on delete function, it is enabled or disabled....

Workaround is...

If you need to check for some value and accordingly allow or not deletion....
You need to define an unlink method in your .py file for that class like:

def unlink(self, cr, uid, ids, context=None):
    for line in self.browse(cr, uid, ids):
        if line.purchase_order_id:
            raise osv.except_osv('error!', 'not allowed to delete record with purchase_line_id')
    return super(name_of_class, self).unlink(cr, uid, ids)

This way delete function is enabled, but before actual deletion some data check is made, and if certain condition is met 
(in this case existing purchase_order_id) system will raise error and will not allow deletion of selected records
Instead of raising error you may also remove id wich contains purchase_order_id from ids list and continue with unlinking (deleting) other records that are ok to be deleted... 

hope this helps...
p.s. the syntax of unlink method if for v7, but should work in v8 also 

look for other examles of unlink methods in some classes and expand to your needs

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.


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)


Asked: 7/8/14, 11:44 AM
Seen: 2623 times
Last updated: 3/16/15, 8:10 AM