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

Purchase module, unit price reset on change of qty or uom. What needs to be changed in on_change function ?

By
Christian Parent
on 5/8/14, 1:09 PM 2,010 views

When creating a purchase order, if you happen to change the price first then quantity or unit of measure after, the price will reset back to what it was before you changeg it (default price or 0.0). It have something to do with the onchange_product_id function but, cannot figure out what exactly creates this.

here is the code of the function (with non relevent code removed) :

def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
        partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
        name=False, price_unit=False, context=None):

    if context is None:
        context = {}

    res = {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'product_uom' : uom_id or False}}
    if not product_id:
        return res

    product_product = self.pool.get('product.product')
    product_uom = self.pool.get('product.uom')
    product_pricelist = self.pool.get('product.pricelist')

 ....

    if pricelist_id:
        price = product_pricelist.price_get(cr, uid, [pricelist_id],
                product.id, qty or 1.0, partner_id or False, {'uom': uom_id, 'date': date_order})[pricelist_id]
    else:
        price = product.standard_price

....

    res['value'].update({'price_unit': price, 'taxes_id': taxes_ids})

    return res

product_id_change = onchange_product_id
product_uom_change = onchange_product_uom

What cause that behavior and how to modify it to keep the price entered by the user at any time ? (This has been like that since at least V.6)

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 5/8/14, 3:22 PM

Hello,

the price changed by this code:

# - determine price_unit and taxes_id
    if pricelist_id:
        price = product_pricelist.price_get(cr, uid, [pricelist_id],
                product.id, qty or 1.0, partner_id or False, {'uom': uom_id, 'date': date_order})[pricelist_id]
    else:
        price = product.standard_price

it'll check the price list for the product or set it to the standard one. So if you need the price entered by the user never changed you have to overwrite this function to don't use the price variable in the line "before the return res":

res['value'].update({'price_unit': price, 'taxes_id': taxes_ids})

Update

you can add

if price_unit:
         price = price_unit

after the if - else condition ...

note: this is simple solution, in case the user doesn't change the price and then he changed the uom, there will be no automatic converting to the price ! so you'll need more work here.

I hope this could helps..

Regards...

I did had tried that change, it did not worked.

It had something to do with the declaration price_unit=False in the signature. I have moved price_unit before the date_order=False, in the signature so it did not need to be initiated, did the changes in form view too. It works. Not for the the onchange_product_uom function which calls the onchange_product_id function in its return. Did the same changes in same order (in signature) but, getting a string instead of int error.... Looking at it now !

Christian Parent
on 5/8/14, 3:41 PM

there is no something to to with price_unit=False it just a default value, you've to don't interrupt the order of the signature. I have tried my change before I post this answer and it worked! I hope if you can return the function as it is original one with that change and try it...

Ahmed M.Elmubarak
on 5/8/14, 4:11 PM

When using:

res['value'].update({'price_unit': price_unit, 'taxes_id': taxes_ids})

If I change the quantity afterwards or the unit of measure, the price returns to 0.00$.

I have changed everything back to original, I had already tried your solution before and it was behaving that way. I will also retry the price = price_unit and see but as I remember, it was also setting it back to 0.00$

Christian Parent
on 5/12/14, 1:45 PM

I've updated the answer, if you still get the 0.00 , please check the order of the params in the xml view you can check the price_unit value by printing it to server and then try to change the qty.

Ahmed M.Elmubarak
on 5/12/14, 3:42 PM

hey man, I didn't notice that you're tagging V8, this may not work with you cause I checked it with V7 I'm so sorry for that...

Ahmed M.Elmubarak
on 5/13/14, 9:34 AM

No prob, I have a production server which runs 6.0.x, will try your solution on it. For 8, I have set everything back to normal, re-moved price_unit in the signature of only onchange_product_id fonction so it does not need to be initiated to false, and made the appropriated changes in the xml also and it works as intended for both, onchange_product_id and onchange_product_uom. Looks like the signature sets it to 0 (false) no mather what the call pass as argument.

Christian Parent
on 5/13/14, 11:41 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

1 follower(s)

Stats

Asked: 5/8/14, 1:09 PM
Seen: 2010 times
Last updated: 3/16/15, 8:10 AM