Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo/OpenERP: hiding create button from treeview

I have a situation here. I am using OpenERP 7. I am trying to hide Create button from tree view of my products. this can be done using

<tree create="false" .....

but situation is like. i want to keep it when user opens the tree view directly from "Asset Management" Module. But hide it when i click on Reporting for treeview.

I tried to use context like this from reporting button's function:

context['prod1']='false'
ctx = dict(context)
print ctx['prod1']

return {
   'type': 'ir.actions.act_window',
   'res_model': 'product.product',
   'view_type': 'form',
   'view_mode': 'tree,form',
   'target': 'current',
   'context':ctx,
   'create':False,   
   'domain':[('id','in',domain)]
}

and in treeview form I did:

<tree create="context.get('prod1',False)"

but I get this json related error:

ERROR : SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

this stuff is working with my button but not with my tree view. I tried adding 'create':False in return too, but unable to do what I want to. What am I missing?

like image 214
Saghir A. Khatri Avatar asked Aug 19 '14 09:08

Saghir A. Khatri


People also ask

What is Odoo Treeview?

In odoo, Tree View also known as List View shows multiple records in the form of a list (rows and columns). Each row represents a record of the database table. You can do various operations on Tree view that is sorting, filtering, and groupby. All views are stored in the database, in the ir.


2 Answers

Are the views your accessing the same or are they different ?

If they are different, I believe the proper way to implement your requirement is to override the relevant view with the

create="false"

property you mentioned.

From the technical memento:

View Inheritance

Existing views should be modifying through inherited views, never directly. An inherited view references its parent view using the inherit_id field, and may add or modify existing elements in the view by referencing them through XPath expressions, and specifying the appropriate position.

Hope this helps.

like image 102
zee Avatar answered Oct 19 '22 19:10

zee


I successfully solved the very same issue by using field_view_get:

def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
    default_type = context.get('default_type', False)
    can_create = default_type != 'out_customer_production'
    update = not can_create and view_type in ['form', 'tree']
    if update:
        doc = etree.XML(res['arch'])
        if not can_create:
            for t in doc.xpath("//"+view_type):
                t.attrib['create'] = 'false'
        res['arch'] = etree.tostring(doc)

    return res

(I left tree and form view without the create attribute)

like image 30
Alessandro Ruffolo Avatar answered Oct 19 '22 17:10

Alessandro Ruffolo