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
It's a question, still an answer to my question. Thanks.
@Aron my answer might help