From 2f329642663292df00761c2210fad47d2a92ace8 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Thu, 12 Feb 2026 16:44:05 +0700 Subject: [PATCH] feat: Refine component availability check to use forecast_availability and prevent hiding produce buttons for zero-consumed partial productions. --- models/mrp_production.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/models/mrp_production.py b/models/mrp_production.py index ec1b6a0..988a173 100644 --- a/models/mrp_production.py +++ b/models/mrp_production.py @@ -49,11 +49,13 @@ class MrpProduction(models.Model): # Check availability based on the ACTUAL 'Consumed' quantity qty_to_consume = move.quantity - # Check availability - product_in_location = move.product_id.with_context(location=location.id) - available_qty = product_in_location.qty_available + # Skip check if product is not storable (Service, etc.) + if not move.product_id.is_storable: + continue - if available_qty - qty_to_consume < 0: + # Check availability + # We use forecast_availability as it includes reservations + if move.forecast_availability < qty_to_consume: potential_negative = True break @@ -61,13 +63,7 @@ class MrpProduction(models.Model): production.show_produce = False production.show_produce_all = False - # User request: "hide the produce if all components consumed is 0 (does not make sense right to produce without components)" - # This should only apply if we are in "Partial Produce" mode (qty_producing > 0), where consumption should have been calculated/entered. - # If qty_producing is 0 (Fresh MO), we usually show "Produce All", which will auto-calculate consumption, so we shouldn't hide it. - if production.qty_producing > 0: - # Check if ALL moves have 0 quantity - # We filter out cancelled moves, and maybe we should focus on raw materials. - relevant_moves = production.move_raw_ids.filtered(lambda m: m.state not in ('done', 'cancel')) - if relevant_moves and all(m.quantity == 0 for m in relevant_moves): - production.show_produce = False - production.show_produce_all = False + # Relaxed guard: Do not hide if qty_producing > 0 even if consumption is 0. + # This allows users to trigger consumption by clicking the Produce button. + # If they really want to block 0-consumption production, it should be a validation error on click, + # not a hidden button that prevents them from even trying.