Odoo Help

2

0
2 Answers
3
Avatar

Yannick Vaucher Switzerland

--Yannick Vaucher--

1789
| 5 7 11
Lausanne, Switzerland
--Yannick Vaucher--


Yannick Vaucher Switzerland
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
Ask a Question
Writer
Tag
Keep Informed
1 follower(s)
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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now