From 473d2ab98a86aaa1d80472964054167d4445c762 Mon Sep 17 00:00:00 2001 From: Denis Ledoux <dle@odoo.com> Date: Thu, 2 Jun 2016 12:47:17 +0200 Subject: [PATCH] [FIX] mrp: inventory value of produced items Since the revision bc23c92c3ed07283bbd40f88ce73024572922a72, the inventory value of the produced items could be doubled, because the list `total_consume_moves` could contain several time the same move ids, e.g. when it was added by `total_consume_moves.append(raw_material_line.id)` and `total_consume_moves += already_consumed_lines.ids` The list is replaced by a set to ensure a same move cannot be counted twice. opw-678727 --- addons/mrp/mrp.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 871fe2a6a107..1efa441be02f 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -983,7 +983,7 @@ class mrp_production(osv.osv): if produce_product.product_id.id == production.product_id.id: main_production_move = produce_product.id - total_consume_moves = [] + total_consume_moves = set() if production_mode in ['consume', 'consume_produce']: if wiz: consume_lines = [] @@ -1003,7 +1003,7 @@ class mrp_production(osv.osv): consumed_qty = min(remaining_qty, raw_material_line.product_qty) stock_mov_obj.action_consume(cr, uid, [raw_material_line.id], consumed_qty, raw_material_line.location_id.id, restrict_lot_id=consume['lot_id'], consumed_for=main_production_move, context=context) - total_consume_moves.append(raw_material_line.id) + total_consume_moves.add(raw_material_line.id) remaining_qty -= consumed_qty if not float_is_zero(remaining_qty, precision_digits=precision): #consumed more in wizard than previously planned @@ -1012,19 +1012,19 @@ class mrp_production(osv.osv): stock_mov_obj.write(cr, uid, [extra_move_id], {'restrict_lot_id': consume['lot_id'], 'consumed_for': main_production_move}, context=context) stock_mov_obj.action_done(cr, uid, [extra_move_id], context=context) - total_consume_moves.append(extra_move_id) + total_consume_moves.add(extra_move_id) if production_mode == 'consume_produce': # add production lines that have already been consumed since the last 'consume & produce' last_production_date = production.move_created_ids2 and max(production.move_created_ids2.mapped('date')) or False already_consumed_lines = production.move_lines2.filtered(lambda l: l.date > last_production_date) - total_consume_moves += already_consumed_lines.ids + total_consume_moves = total_consume_moves.union(already_consumed_lines.ids) price_unit = 0 for produce_product in production.move_created_ids: is_main_product = (produce_product.product_id.id == production.product_id.id) and production.product_id.cost_method=='real' if is_main_product: - total_cost = self._calculate_total_cost(cr, uid, total_consume_moves, context=context) + total_cost = self._calculate_total_cost(cr, uid, list(total_consume_moves), context=context) production_cost = self._calculate_workcenter_cost(cr, uid, production_id, context=context) price_unit = (total_cost + production_cost) / production_qty_uom -- GitLab