From 61a5b142774096601d8c7c0c7b0414cec6fd0ee4 Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Mon, 4 Oct 2021 15:12:54 +0200 Subject: [PATCH] [FIX] mrp_production_serial_matrix: use qty reserved for selected MO. User should be able to use the matrix when the MO is reserved and select the lots that are available plus the ones reserved specifically for the MO. --- .../wizards/mrp_production_serial_matrix.py | 7 ++----- .../wizards/mrp_production_serial_matrix_line.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py index 7d1fb2e9b..2bf4ea96c 100644 --- a/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py +++ b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix.py @@ -71,11 +71,8 @@ class MrpProductionSerialMatrix(models.TransientModel): if not ll.component_lot_id: continue lot_consumption.setdefault(ll.component_lot_id, 0) - available_quantity = self.env["stock.quant"]._get_available_quantity( - ll.component_id, - ll.production_id.location_src_id, - lot_id=ll.component_lot_id, - ) + free_qty, reserved_qty = ll._get_available_and_reserved_quantities() + available_quantity = free_qty + reserved_qty if ( available_quantity - lot_consumption[ll.component_lot_id] < ll.lot_qty diff --git a/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py index 54cc15245..590da4782 100644 --- a/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py +++ b/mrp_production_serial_matrix/wizards/mrp_production_serial_matrix_line.py @@ -36,3 +36,18 @@ class MrpProductionSerialMatrix(models.TransientModel): ] ) rec.allowed_component_lot_ids = available_quants.mapped("lot_id") + + def _get_available_and_reserved_quantities(self): + self.ensure_one() + available_quantity = self.env["stock.quant"]._get_available_quantity( + self.component_id, + self.production_id.location_src_id, + lot_id=self.component_lot_id, + ) + move_lines = self.production_id.move_raw_ids.mapped("move_line_ids").filtered( + lambda l: l.product_id == self.component_id + and l.lot_id == self.component_lot_id + and l.state not in ["done", "cancel"] + ) + specifically_reserved_quantity = sum(move_lines.mapped("product_uom_qty")) + return available_quantity, specifically_reserved_quantity