Skip to Content
Menu
This question has been flagged
2 Replies
10351 Views

Letting everyone in the company know cost price of product is unacceptable? (basic theory)

I have to hide cost price for some* of my employee but i still have to let them able to see On hand quantity.


using odoo 13 community. anyway to one click disable?

Avatar
Discard

Great solution Paresh! Thank you.

Thanks Paresh, works perfectly

Best Answer

You will need to put them in separate security groups. You can then customize the screens to make the fields conditionally visible by adding the groups="visible_group1" attribute (where visible_group1 is the external id of the security group to which the field should be visible). For example,

<field name="standard_price" groups="visible_group1"/>

The groups attribute should contain a comma-separated list of groups which should be able to see the field. Once you add the groups attribute, any group not listed in the list will not be able to see the field.


EDIT:

Here's an example of how to make the Cost field visible only to a user having the Administration/Settings privilege (i.e. base.group_system)

1. Go to the bug icon and select Edit View: Form

2. The underlying view is an extension view. Click on the icon next to the Inherited View field to open the product.template.common.form view in edit mode.

3. Click on the Inherited Views tab, scroll to the bottom and click on Add a line.

4. Enter a custom View Name, for example x_product.template.common.form

5. Put the following code in the field in the Architecture tab. You will need to substitute the group id base.group_system with the external id of your custom security group. 


<?xml version="1.0"?>
<data>
    <xpath expr="//label[@for='standard_price']" position="attributes">
        <attribute name="groups">base.group_system</attribute>
    </xpath>
    <xpath expr="//div[@name='standard_price_uom']" position="attributes">
        <attribute name="groups">base.group_system</attribute>
    </xpath>
</data>


Save all the views and reload the form. The Cost field (standard_price) will now be visible only to users who have been added to the Administration/Settings security group.


If you are interested in understanding the details of the technicalities of the customization steps, you may want to read up on the following documentation on Views.

https://www.odoo.com/documentation/13.0/reference/views.html


Avatar
Discard
Author

where can i add this line i want to hide cost price here ,

screenshot https://imgur.com/a/RADLZ1r

i know how to enter edit form view

Are you familiar with how to customize the view using inheritance ? If yes, are you doing the customization through the UI or through a customization module ?

Author

I only know 2 ways . ( i use windows 10)

1. through bug icon https://imgur.com/a/NRV7QbA

2. find the file and use notepad

I have edited my earlier answer and added an example with the detailed steps.

Author

WOW!!! Thanks man, it worked !!! your are the best

Hi Paresh Wagh, i cant seem to follow your example. I am using Odoo 16.

Hi Paresh Wagh, i cant seem to follow your example. I am using Odoo 16. Could you do a video or something? Thanks,