Odoo - OpenERP - How to Restrict user from editing the unit price for product in sale order line?

We do not want anyone to change unit price from sales order line. Rather they want to control changing price from masterdata only.

I checked the filed 'price_unit' from sale order line and the field is readonly

I checked the view 'sale.order.line.form2' and the 'price_unit' has no readonly attributes.

Can anyone help me to make this field readonly so that no one can change the value?

| 2 1 2
Asked on 8/14/15, 2:19 PM

I solved using this function, very usefull, is not read only  , is a :  don't allow users to quote below the sales price of products, and you can make your particular changes.




Call the function for the field price_unit in the view xml

<xpath expr="//field[@name='price_unit']" position="attributes">

<attribute name="on_change">check_margin(product_id,price_unit)</attribute>



and in the class, define the function to process it.


def check_margin(self, cr, uid, ids, product_id, unit_price, context=None):
  res = {}
  warning = {}
  sale_price = None
  if product_id:
     sale_price = self.pool.get('product.product').browse(cr, uid,product_id).list_price
  if unit_price is None:
  elif unit_price < sale_price:
     warning = {  
       'title': _("Warning"),  
       'message': _('Unit price given, is less than the sales price of the selected product. Please change (or contact your sales manager to change) the sales price of the selected product.'),  
     res = {'value': {'price_unit':sale_price}}
  elif unit_price >= sale_price:
     res = {'value': {'price_unit':unit_price}}
  return {'value': res.get('value'), 'warning':warning}

| 2 1 2
Answered on 8/14/15, 2:21 PM

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!

Ask a Question

Keep Informed

About This Forum

This forum is for HiTechnologia Employees & just Odoo general knowledge purpose only.

Read Guidelines

Question tools

3 follower(s)


Asked: 8/14/15, 2:19 PM
Seen: 5768 times
Last updated: 8/14/15, 2:21 PM