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

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

By
Alloice Lagat
on 8/19/13, 7:45 AM 2,383 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?

1

AJ Schrafel Paper Corp

--AJ Schrafel Paper Corp--
2050
| 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.

Xsias
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
0
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

sale_order_line()

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)

Xsias
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
0
Xsias
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)
        else:
            return super(sale_order_line, self).write(cr, uid, ids, vals, context)

# Some code #
sale_order_line()

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

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

Xsias
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(...

Xsias
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 ?

Xsias
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?

OCTAVIO DIAZ ARRIAGA
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.

Xsias
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.

Xsias
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
0
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.

 

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

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

1 follower(s)

Stats

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