2

I need to hide view that I create for users that do not have specific access rights group. I know I can use groups attribute for every field that I add in my view, so those users would not see it. But it is quite redundant as I need to hide every field in that view. So maybe there is some way that I can just hide whole view? In this example it hides for every field, because group is added for those fields.

   <record id="view_partner_additional_view" model="ir.ui.view">
        <field name="name">res.partner.patient.form.inherit</field>
        <field name="model">res.partner</field>
        <field name="priority">2</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
           <label for="is_company" string="Is a Company?" position="after">
                <field name="is_something"                          
                    attrs="{'invisible': [('is_company','=',True)]}" 
                    groups="some_grp"/>             
                <field name="is_something2" 
                    attrs="{'invisible': [('is_company','=',False)]}" 
                    groups="some_grp"/>                 
           </label>
        </field>
    </record>

Is it possible to somehow wrap whole view and define it that it will be invisible to user that does not have 'some_grp' access rights group? What I mean is that I would need to add groups attribute once, not for every field. I tried wrapping everything with div and then adding groups attribute there, but I got error, because you can't wrap it everything like that.

Andrius
  • 19,658
  • 37
  • 143
  • 243
  • there is a groups_id field on model ir.ui.view. did you try that out? edit: you can hide whole menus with groups_id field in menuitems, too. – CZoellner Feb 28 '14 at 10:37
  • @CZoellner I'm trying to hide view, not menu. Or I don't understand what you are suggesting. – Andrius Mar 03 '14 at 09:33
  • every view has the field groups_id. help of this field says: empty = every user can see this view; entries: only registered groups should see the view. but i tested it and it's not working. – CZoellner Mar 03 '14 at 12:26

1 Answers1

1

First create your form view. Then inherit the view also specify the groups. for example in sale order form view, i want to make the customer reference field readonly for group user when state is not in draft or sent.

<record id="view_order_form_cust_ref_readonly" model="ir.ui.view">
    <field name="name">sale.order.form.readonly.cust</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="groups_id" eval="[(6, 0, [ref('base.group_user') ])]"/>
    <field name="arch" type="xml">
        <field name='client_order_ref'" position="attributes">
            <attribute name="attrs">{'readonly':[('state','not in',['draft','sent'])]}</attribute>
        </field>
    </field>
</record>

In your case,first create a view which is common for all users. Then inherit the view with groups and add the fields that need to be visible for the group specified.

reference How to make field readonly based on group and status?

Community
  • 1
  • 1
OmaL
  • 5,037
  • 3
  • 31
  • 48
  • I'm wondering why there's no way to specify a separate view for each group. Why do I have to inherit? – Aron Lorincz Dec 08 '17 at 10:23
  • 1
    if you want you can create seperate views. but you have to create seperate actions also and assign each views to it for its correct working – OmaL Jan 17 '18 at 13:21