From ca40236ddc75424be0e361f33adc55e8663ca399 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 17 Dec 2015 14:26:06 +0100 Subject: [PATCH] [FIX] sale: onchange_product_uom The function "product_uom_change" was built to reset the price unit of a SO line when the uom was changed. Before this fix 503820a, the price unit of the SO line only depended on the price list then it was not needed to pass the fiscal position to this function. After this fix 503820a, the price unit of a SO line also depends on the taxes set on the SO line(e.g.:if an included tax is deleted, the price unit must be recomputed without this tax). Then to recompute the unit price, the function "product_id_change" must take into account the fiscal position set on the SO to consider the right taxes to recompute the unit price. The fiscal position set on a SO must be passed to onchange_product_uom each time it will be called because the price unit will be recomputed. --- addons/sale/sale.py | 12 ++++++++++++ addons/sale/sale_view.xml | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index d172c7bdb2c..119bee779aa 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1232,6 +1232,18 @@ class sale_order_line(osv.osv): partner_id=partner_id, lang=lang, update_tax=update_tax, date_order=date_order, context=context) + def onchange_product_uom(self, cursor, user, ids, pricelist, product, qty=0, + uom=False, qty_uos=0, uos=False, name='', partner_id=False, + lang=False, update_tax=True, date_order=False, fiscal_position=False, context=None): + context = context or {} + lang = lang or ('lang' in context and context['lang']) + if not uom: + return {'value': {'price_unit': 0.0, 'product_uom' : uom or False}} + return self.product_id_change(cursor, user, ids, pricelist, product, + qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name, + partner_id=partner_id, lang=lang, update_tax=update_tax, + date_order=date_order, fiscal_position=fiscal_position, context=context) + def unlink(self, cr, uid, ids, context=None): if context is None: context = {} diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index be3ad08b6ee..675a621071f 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -134,7 +134,7 @@ on_change="product_id_change(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, False, parent.fiscal_position, True, context)"/> + on_change="onchange_product_uom(parent.pricelist_id,product_id,product_uom_qty,product_uom,product_uos_qty,product_uos,name,parent.partner_id, False, False, parent.date_order, parent.fiscal_position, context)"/>