[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
This commit is contained in:
Nicolas Lempereur 2015-05-28 12:00:56 +02:00
parent 916525fbf3
commit 52aee9a8e7
1 changed files with 8 additions and 1 deletions

View File

@ -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: