Odoo Help


Add a function to make users not to input thier values in unit price

Alloice Lagat
on 8/19/13, 7:45 AM 2,993 views

I want to add a function in sale.py so that if a user edits the unit price,, it will still return the initial pricelist when he tries to save the form, in sale.order.line. The values passed to the form should be the one from the database.

i.e if price_unit != pricelist _warn mssg: ("you are not allowed to change unit price")

what the function should do is check, if the value that is in field is same as the one in the pricelist, then allow to save and close or new, if less or more.. return error,

How can i add it?


AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
| 4 5 8
Bronx, United States
--AJ Schrafel Paper Corp--

Exploring OpenERP for business

AJ Schrafel Paper Corp
On 8/24/13, 2:18 AM

If want to make the price not editable, and all items will be priced making it so no user will ever need to type in a price, just modify the XML to make the field read only.

You could make it so a group does have edit rights and just make managers of the company members of the group.

1or2 lines of XML versus several 10s of lines of python code

I did that..but its not making the field readonly.. <field name= 'price_unit' readonly="1"/> It does not make the field readonly..what makes it readonly is in python code. 'price_unit' =fields.float("Unit Price"......,states=('draft:[reaonly, True]) but it will not save the price in the server.so u will return 0.. post your xml code here that functions..

Alloice Lagat
on 8/24/13, 2:59 AM

You must reinstall the module after you make a modification to the XML, not just start stop the server. If you made the field readonly correctly, it is readonly.

AJ Schrafel Paper Corp
on 8/25/13, 12:12 AM

Yes, patently's answer is much easier than mine. You should do this. But you do not need to reinstall the entire module, just update normally.

on 8/26/13, 5:33 AM

That seems much better,,coz i was worried how comes i make fields readonly in the xml and yet they dont show any difference,, I will definately try it and if it works i will let u both know.. Thanks Pals for your continous assistance.

Alloice Lagat
on 8/26/13, 8:13 AM
Alloice Lagat
On 8/21/13, 9:28 AM

Here is where i have added your code

    def unlink(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        """Allows to delete sales order lines in draft,cancel states"""
        for rec in self.browse(cr, uid, ids, context=context):
            if rec.state not in ['draft', 'cancel']:
                raise osv.except_osv(_('Invalid action !'), _('Cannot delete a sales order line which is in state \'%s\'!') %(rec.state,))
        return super(sale_order_line, self).unlink(cr, uid, ids, context=context)

    def write(self, cr, uid, ids, vals, context=None):
        for this in self.browse(cr, uid, ids, context):
            if vals['price_unit'] != this.price_unit:
                vals['price_unit'] = this.price_unit
                result = super(sale_order_line, self).write(cr, uid, ids, vals, context)
        return result


class sale_config_picking_policy(osv.osv_memory):

result = super(sale_order_line, self).write(cr, uid, ids, vals, context) is too much indented here.

Can you print vals please and said to me the value please ? (I edit my answer with an exemple)

on 8/21/13, 12:11 PM

The error dissapears when oi remove result = super(sale_order_line, self).write(cr, uid, ids, vals, context) return result

Alloice Lagat
on 8/22/13, 10:53 AM

and replace with return super(sale_order_line, self).write(cr, uid, ids, vals, context) but still no changes

Alloice Lagat
on 8/22/13, 10:54 AM
On 8/20/13, 7:19 AM

You need to add the write function in sale.py like that :

class sale_order_line(osv.osv):
    # Somme code #
    def write(self, cr, uid, ids, vals, context=None):
        # Do some code like this :
        # Browse the actual price_unit, compare this price with the new price value in vals
        # If the price is different : ignore him, else do nothing
        order_line_price_unit = self.read(cr,uid,ids,['price_unit'])['price_unit'][0]
        if 'price_unit' in vals and vals['price_unit'] != order_line_price_unit:
            vals['price_unit'] = this.price_unit
            return super(sale_order_line, self).write(cr, uid, ids, vals, context)
            return super(sale_order_line, self).write(cr, uid, ids, vals, context)

# Some code #

Add "sale" in the dependencies of your module. (File __openerp__.py)

"depends": [ ...., "sale", .... ],

on 8/20/13, 10:34 AM

You edit the sale.py of the base's code directly ? If you do so, you don't need _inherit and add 'sale' on the dependencies anymore. Just add the def write(...

on 8/20/13, 11:27 AM

I've edited my answer. So you have something like that ? Just adding the write in the sale.py ?

We don't have edited the xml, the error is strange. Have you done some others changes ?

on 8/20/13, 1:41 PM

In this case the unit price from the sale order line is updated? or make the change in the database?

on 8/20/13, 8:40 PM

Ok, starting from the beginning... You go in sale module, on the base code of openerp. Open the sale.py file. Add my write() on the sale.order class. That's all. No others edits.

on 8/21/13, 6:16 AM

Can you edit your question and add in her your previous comment ? Like that we can have the entire code.

on 8/21/13, 7:19 AM

Your code has errors

Alloice Lagat
on 8/21/13, 10:49 AM

Sven..The code still is returning the error.No handler found

Alloice Lagat
on 8/24/13, 3:00 AM
Boris Ghelman
On 10/1/14, 11:17 PM

After many days investigating and googleling,  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.



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

1 follower(s)


Asked: 8/19/13, 7:45 AM
Seen: 2993 times
Last updated: 3/16/15, 8:10 AM