Help

2

How to restrict view/access to fields to some groups?

Avatar
Damjan Cvetko

Hi there,

I am playing with the rights management and trying to restrict access of for example "purchase_price" field in sales.orders with no luck till now.

I changed the line in sale_margin_view.xml from:

<field name="purchase_price" groups="base.group_user"/>

to

<field name="purchase_price" groups="base.group_sale_manager"/>

but still all users can see this field. Any idea what I could check to make this work? Am I doing something wrong?

Cheers

Damien

Avatar
Discard
2 Answers
1
Best Answer
Try it this way:
<field name="purchase_price" groups="base.group_sale_manager,-base.group_user"/>

I only used it for the menuitems, but I think it would also work here

Avatar
Discard
0
Avatar
Carlos A García
Best Answer

For me in a similar situation works this way. First, create a new group (group_purchase_restrict) in Odoo or your module, and then declare the XML view like this:

<record id="purchase_order_form_mods" model="ir.ui.view">

    <field name="name">purchase.order.form.mods</field>

    <field name="model">purchase.order</field>

    <field name="inherit_id" ref="purchase.purchase_order_form" />

    <field name="arch" type="xml">

        <xpath expr="//button[@name='purchase_confirm'][1]" position="attributes">

            <attribute name="groups">purchase.group_purchase_user,purchase.group_purchase_manager</attribute>

        </xpath>

    </field>

</record>


<record id="purchase_order_form_mods_restrict" model="ir.ui.view">

    <field name="name">purchase.order.form.mods.restrict</field>

    <field name="model">purchase.order</field>

    <field name="inherit_id" ref="purchase.purchase_order_form" />

    <field name="groups_id" eval="[(6, 0, [ref('purchase_mods.group_purchase_restrict') ])]"/>

    <field name="arch" type="xml">

        <xpath expr="//button[@name='purchase_confirm'][1]" position="attributes">

            <attribute name="invisible">1</attribute>

        </xpath>

    </field>

</record>

This way hide the button only for the users belonging to the new group (group_purchase_restrict).

 I hope it helps

Avatar
Discard