Odoo Help

Welcome!

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.

0

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

By
user0780987
on 7/8/14, 11:44 AM 2,190 views

Hi,

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" />
      </tree>
      <form version="7.0">
        <group col="4">
          ...
        </group>
      </form>
    </field>

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?

user0780987
on 7/11/14, 3:46 AM
0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

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

Bole
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

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

1 follower(s)

Stats

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