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?

Support
Support
5000
| 2 1 2
Asked on 8/14/15, 2:19 PM
0
vote
3795 Views

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.

 

http://stackoverflow.com/questions/23359684/dont-allow-to-quote-below-the-sales-price-of-a-product-in-openerp

 

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>

</xpath>

 

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:
     pass
  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}}
     pass
  return {'value': res.get('value'), 'warning':warning}

Support
Support
5000
| 2 1 2
Answered on 8/14/15, 2:21 PM
0
vote

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)

Stats

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