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.

2

How to hide the create button dynamical tree view in openerp ?

By
Dhana Babu
on 1/28/14, 8:10 AM 4,267 views

I have hided the create button using following view,

<tree create="false" edit="false" >

It is working perfect, But I need to hide the create button dynamic way like this,

<tree attrs="{'create':[("uid",'=',1)]}" edit="false" >

But it is not working.

It's a question, still an answer to my question. Thanks.

Aron Lorinc
on 1/20/16, 5:11 AM

@Aron my answer might help

Camptocamp SA, Yannick Vaucher
on 3/18/16, 10:49 AM
0

Yannick Vaucher

--Yannick Vaucher--
1699
| 5 7 9
Lausanne, Switzerland
--Yannick Vaucher--
Yannick Vaucher
On 3/18/16, 10:47 AM

In your case, you might want to create a view that inherit yours using groups_id field of the ir.ui.view.

See an exemple in sale module with xml id view_order_form_editable_list


Create your base view by restricting the create button:

    <record id="view_list" model="ir.ui.view">
        <field name="name">base list view</field>
        <field name="model">my.model</field>
<field name="arch" type="xml">
<tree create="false">
...
</tree>
</field>
</record>

  

Then inherit this view to alter the view for user in a specific group:

     <record id="view_list_with_more_access" model="ir.ui.view">
        <field name="name">exemple of change of create button on list view</field>
        <field name="model">my.model</field>
        <field name="inherit_id" ref="view_list"/>
        <field name="groups_id" eval="[(4, ref('my_group_xmlid_with_more_access')))]"/>
        <field name="arch" type="xml">
             <xpath expr="//tree" position="attributes">
                 <attribute name="create">true</attribute>
            </xpath>
        </field>
    </record>


An other option would be to alter `fields_view_get` method which a check on user:


    @api.model
    def fields_view_get(self, view_id=None, view_type='form',
                        toolbar=False, submenu=False):
        res = super(MyModel, self).fields_view_get(
            view_id=view_id, view_type=view_type,
            toolbar=toolbar, submenu=submenu)
        if view_type != 'search' and self.env.uid != SUPERUSER_ID:
            # Check if user is in group that allow creation
            has_my_group = self.env.user.has_group('my_group_with_more_access')
            if not has_my_group:
                root = etree.fromstring(res['arch'])
                root.set('create', 'false')
                res['arch'] = etree.tostring(root)

        return res

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: 1/28/14, 8:10 AM
Seen: 4267 times
Last updated: 3/18/16, 10:47 AM