Odoo Help


Module - Hide Cost Price from some user groups

Budi Hartono
on 4/18/15, 11:46 AM 3,750 views

I'm trying to create a module to restrict access to Cost Price in the Procurement tab of the Product view. I want to let only Administrator and Purchase Manager see the Cost Price and make the other groups cannot see the Cost Price. I have created a module below. But It doesn't work. Nothing changes and everyone still can see the Cost Price. Can anybody tell me what my mistake is?


import product_template 


	"name": "Hide Cost Price from Some Groups",
	"version": "1.0.0",
	"author": "Budi Hartono",
	"depends": ["product"],
	"category": "",
	"description": """
	Hide Cost Price from Some Groups.
	"website": "http://www.recoremedia.com",
	"data": [
	"installable": True,
	"active": False,


from openerp.osv import fields, osv
from openerp.tools.translate import _
class product_template(osv.osv):
    _inherit = "product.template"


<?xml version="1.0" encoding="utf-8"?>
  <record id="product_template_form_view_restricted" model="ir.ui.view">
    <field name="name">product.template.common.form</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="arch" type="xml">
      <field name="standard_price" position="replace">          
        <field name="standard_price" groups="base.group_erp_manager,purchase.group_purchase_manager"/>

Do you have installed the module stock_account?

on 4/18/15, 1:05 PM

Yes I have installed it. It is the "WMS Accounting" isn't it?

Budi Hartono
on 4/19/15, 12:59 AM


| 6 5 7
Lodz, Poland

On 4/19/15, 3:13 AM

Module stock_account inherit model product.template and replace standard_price view,  see ir.ui.viiew with id=view_template_property_form

Probably your module replace product and in next step module stock_account replace your definition

You must define:

"depends": ["stock_account"],

and redefine groups in this xml (code from view_template_property_form):

<div groups="base.group_user">

<field name="standard_price" attrs="{'readonly':['&', ('valuation','=','real_time'), ('cost_method', 'in', ['standard', 'average'])]}" nolabel="1"/>
<button name="%(action_view_change_standard_price)d" string="- update" type="action" attrs="{'invisible':['|', ('valuation','!=', 'real_time'), ('cost_method', 'not in', ['standard', 'average'])]}" class="oe_link" groups="stock_account.group_inventory_valuation"/>



Hi Budi,

Check this module:


And adjust it to your needs.


Jordi Ballester


Thanks, I'll take a look.

Budi Hartono
on 8/8/15, 4:56 AM
Budi Hartono
On 4/19/15, 4:17 AM

Thanks zbik, you pointed out the problem, now I'm able to change something with this:

<xpath expr="//label[@string='Cost Price']" position="replace">
  <label string="Cost Price New" for="standard_price" align="1.0" groups="base.group_user"/> 

I just wanted to see if my code works, so I just changed the string into "Cost Price New" like above. I see that it's working. But I still don't know why my code below won't work:

<xpath expr="//div[@groups='base.group_user']" position="replace">
<div>Nothing Here!</div>

I guess it's the Xpath code because I got this error message when trying to install my module:

Element '<div name="options">' cannot be located in parent view 
I try to change the Xpath expression but still cannot find a way to make it work. 

Where, in your module xpath, you change ... div name="options"...?

on 4/19/15, 1:56 PM

Nowhere, I didn't even put that '

' in the code. But this error occurs when I put in the stock_account module.
Budi Hartono
on 4/21/15, 12:29 AM

Well, I found alternative solution. I changed my xpath target, I don't try to change the div anymore, but instead I replace the field standard_price (which is the child node of that div). And it works.

Budi Hartono
on 4/21/15, 1:15 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 4/18/15, 11:46 AM
Seen: 3750 times
Last updated: 12/8/16, 9:13 AM