Odoo Help

Welcome!

This community 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.

0

Module - Hide Cost Price from some user groups

By
Budi Hartono
on 4/18/15, 11:46 AM 2,084 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?

__init__.py

import product_template 

__openerp__.py

{
	"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": [
		"product_view.xml",
    ],
	"installable": True,
	"active": False,
}

product_template.py

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

product_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
  <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"/>
      </field>
    </field>
  </record>
</data>
</openerp>



Do you have installed the module stock_account?

zbik
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
1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
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"/>

</div>


1

Hi Budi,

Check this module:

https://github.com/Vauxoo/addons-vauxoo/tree/8.0/product_price_visible


And adjust it to your needs.

Regards,

Jordi Ballester

www.eficent.com



Thanks, I'll take a look.

Budi Hartono
on 8/8/15, 4:56 AM
0
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"/> 
</xpath>

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>
</xpath>

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"...?

zbik
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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