Skip to Content
Menu
This question has been flagged
2 Replies
45584 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.

Avatar
Discard

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

@Aron my answer might help

Best Answer

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
Avatar
Discard
Related Posts Replies Views Activity
2
Sep 23
6944
2
Dec 23
56215
0
Mar 22
1659
3
Jun 20
9917
1
Oct 19
3848