跳至内容
菜单
此问题已终结
5 回复
49008 查看

This question seems to have been asked before, but I couldn't get the answers to work.

I have a field - amount_words. It should be invisible only to one group and visible to all others. This is what I have done so far:

 <record id="view_order_line_tree2" model="ir.ui.view">
    <field name="name">sale.order.line.tree.inherit</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="sale.view_order_form"/>
    <field name="arch" type="xml">
        <xpath expr="//page/group" position="after"> <group class="oe_subtotal_amount_footer oe_left"> <field name="amount_words" /> </group> </xpath> </field> </record>

This is to introduce the amount_words field.

Now, to hide it for the service_order group:

 <record id="view_order_line_tree3" model="ir.ui.view">
    <field name="name">sale.order.line.tree.inherit2</field>
    <field name="model">sale.order</field>
    <field name="inherit_id" ref="view_order_line_tree2"/>
    <field name="groups_id" eval="[(6, 0, [ref('custom_sale.group_service_order') ])]"/>
    <field name="arch" type="xml">
	<field name="amount_words" position="attributes">
	    <attribute name="attrs">{'invisible':1}</attribute>
	</field>
    </field>
</record>

But the effect is that it is now invisible for all groups. Does anyone know how to achieve this?



形象
丢弃
最佳答案

Hi,

Add a boolean field to the xml file and make it invisible.

Add the invisible attribute to the amount_words field.

Write a compute function to compute the value of the boolean field according to the user has the group to which the field visibility is to be blocked or not.

XML file:

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


    <field name="name">sale.order.line.tree.inherit</field>


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


    <field name="inherit_id" ref="sale.view_order_form"/>


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


        <xpath expr="//page/group" position="after">


            <group class="oe_subtotal_amount_footer oe_left">


                <field name="flag" invisible="1"/>


                <field name="amount_words"  attrs="{ 'invisible': [('flag', '=', True)] }"/>


            </group>


        </xpath>


    </field>


</record>


Python file:

class SaleOrder(models.Model):
_inherit = 'sale.order'

amount_words = fields.Char()
flag = fields.Boolean(compute='check_group')

def check_group(self):
if self.user_has_groups('custom_sale.group_service_order'):
self.flag = True
else:
self.flag = False

Regards

形象
丢弃
最佳答案


Hello Shawn,

You can use 'groups' for number of groups you want to show this field just like below:

<field name="amount_words" position="attributes">

    <attribute name="groups">other_than_service_order_group_name</attribute>

</field>

After doing this, field will only be seen to groups you have mentioned in group attribute.

Hope this helps!

Thanks,

Kalpana Hemnani

 

形象
丢弃
编写者

Thanks Kalpana, but here I would have to assign the majority of my users to a separate group which seems unnecessary. I have commented in the other post. Please let me know in case you have any other suggestions.

最佳答案

Hello,

Please check the this url.

http://pinakinnayi.blogspot.in/2013/06/field-level-security-in-openerp.html

Hope this will help you.

Thanks.

Shamji


形象
丢弃
编写者

Thanks Solanki, but I think the link describes how to display it for a certain group. In my case, there are only very few users who should not see the field, so I created a group for that purpose. The workaround would be to create a separate group, assign everyone else to that group and apply groups to that. But that would be a tedious task and not the ideal way to do it. I think the code snippet that I posted with some tweaks should accomplish the task. Please let me know if you have any other ideas.

最佳答案

For me in the same 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

形象
丢弃
最佳答案

Dear Shawn,

You can create a new wizard, And in this wizard you can choose a User/Customer (Specific User) and on this User/Customer give a access to this new field is visible or invisible. 

Thanks.

Farid Ghanchi

形象
丢弃
相关帖文 回复 查看 活动
1
5月 23
3923
2
3月 24
5679
1
12月 21
9685
2
1月 16
4359
2
9月 15
4214