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