From 8a1d7dfe7bd82473f33400c0e933142261bc30b6 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 17 Jun 2016 17:41:03 +0200 Subject: [PATCH] [FIX] sale_stock: do not count discount twice When a product is a kit and a discount is applied thanks to a pricelist, the discount is counted twice if the invoice is created from the stock picking. This is because the pricelist will modify the price unit, but moreover the discount will be applied a second time by the method `_compute_price` of the account move line. opw-676838 --- addons/sale_stock/sale_stock.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index bb38c0e5890..f869d157432 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -20,7 +20,7 @@ # ############################################################################## from datetime import datetime, timedelta -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare +from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare, float_is_zero from openerp.osv import fields, osv from openerp.tools.safe_eval import safe_eval as eval from openerp.tools.translate import _ @@ -410,10 +410,14 @@ class stock_move(osv.osv): res['account_analytic_id'] = sale_line.order_id.project_id and sale_line.order_id.project_id.id or False res['discount'] = sale_line.discount if move.product_id.id != sale_line.product_id.id: - res['price_unit'] = self.pool['product.pricelist'].price_get( - cr, uid, [sale_line.order_id.pricelist_id.id], - move.product_id.id, move.product_uom_qty or 1.0, - sale_line.order_id.partner_id, context=context)[sale_line.order_id.pricelist_id.id] + precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Discount') + if float_is_zero(sale_line.discount, precision_digits=precision): + res['price_unit'] = self.pool['product.pricelist'].price_get( + cr, uid, [sale_line.order_id.pricelist_id.id], + move.product_id.id, move.product_uom_qty or 1.0, + sale_line.order_id.partner_id, context=context)[sale_line.order_id.pricelist_id.id] + else: + res['price_unit'] = move.product_id.lst_price else: res['price_unit'] = sale_line.price_unit uos_coeff = move.product_uom_qty and move.product_uos_qty / move.product_uom_qty or 1.0