From 7e15fa59e4979f0765a8e10e776b3da1472a31c7 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Tue, 8 Nov 2016 15:58:57 +0100 Subject: [PATCH] [FIX] mrp: correctly update lot_product_id to final lot for stock.move.lots When there are 3 different lots reserved for 3 different serial numbers for the final product, if you do the first finished product, the finished lot is put on all stock.move.lots even if nothing has been consumed for it. This results in traceability report for the first finished lot being linked to all of lots instead of just the one that was consumed. Now we update lot_produced_id only on stock.move.lots where quantity_done > 0. That way it will only links with the correct one. --- addons/mrp/models/mrp_workorder.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 7aef5fcbd1f..987991bcad3 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -300,9 +300,12 @@ class MrpWorkorder(models.Model): if self.next_work_order_id and self.final_lot_id and not self.next_work_order_id.final_lot_id: self.next_work_order_id.final_lot_id = self.final_lot_id.id - # TODO: add filter for those that have not been done yet --> need to check as it can have different filters - self.move_lot_ids.filtered(lambda x: not x.done_move and not x.lot_produced_id).write({'lot_produced_id': self.final_lot_id.id, - 'lot_produced_qty': self.qty_producing,}) + self.move_lot_ids.filtered( + lambda move_lot: not move_lot.done_move and not move_lot.lot_produced_id and move_lot.quantity_done > 0 + ).write({ + 'lot_produced_id': self.final_lot_id.id, + 'lot_produced_qty': self.qty_producing + }) # If last work order, then post lots used # TODO: should be same as checking if for every workorder something has been done?