From 52aee9a8e79010fd1d527415d24d46a5c1595016 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 28 May 2015 12:00:56 +0200 Subject: [PATCH] [FIX] stock_landed_costs: splitting and decimals When splitting landed costs against the picking line, the decimal precision was not taken into account. For example: with a landed cost of 5.01 split equally over two lines, the cost for each line is 2.505 which is rounded to 2.51 with a decimal precision of the fractional part of 2. Hence the total was wrongly of 5.02 (which is an issue when wanted to validate the landed costs). With this commit, the split landed costs are restrained to stay under the whole landed cost price. closes #6882 fixes #5568 opw-639503 --- addons/stock_landed_costs/stock_landed_costs.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/stock_landed_costs/stock_landed_costs.py b/addons/stock_landed_costs/stock_landed_costs.py index a05a548fe87..36d44dcb66e 100644 --- a/addons/stock_landed_costs/stock_landed_costs.py +++ b/addons/stock_landed_costs/stock_landed_costs.py @@ -22,7 +22,7 @@ from openerp.osv import fields, osv import openerp.addons.decimal_precision as dp from openerp.exceptions import Warning -from openerp.tools import float_compare +from openerp.tools import float_compare, float_round from openerp.tools.translate import _ import product @@ -239,6 +239,7 @@ class stock_landed_cost(osv.osv): line_obj = self.pool.get('stock.valuation.adjustment.lines') unlink_ids = line_obj.search(cr, uid, [('cost_id', 'in', ids)], context=context) line_obj.unlink(cr, uid, unlink_ids, context=context) + digits = dp.get_precision('Product Price')(cr) towrite_dict = {} for cost in self.browse(cr, uid, ids, context=None): if not cost.picking_ids: @@ -261,6 +262,7 @@ class stock_landed_cost(osv.osv): total_line += 1 for line in cost.cost_lines: + value_split = 0.0 for valuation in cost.valuation_adjustment_lines: value = 0.0 if valuation.cost_line_id and valuation.cost_line_id.id == line.id: @@ -281,6 +283,11 @@ class stock_landed_cost(osv.osv): else: value = (line.price_unit / total_line) + if digits: + value = float_round(value, precision_digits=digits[1], rounding_method='UP') + value = min(value, line.price_unit - value_split) + value_split += value + if valuation.id not in towrite_dict: towrite_dict[valuation.id] = value else: