Domanda

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.

È stato utile?

Soluzione

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?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top