Clean up MO production stock availability checks by removing debug logs, simplifying quantity comparison, and streamlining conditional logic.

This commit is contained in:
Suherdy Yacob 2026-02-12 17:05:30 +07:00
parent b7e21cc2bf
commit d31ce99419

View File

@ -37,40 +37,22 @@ class MrpProduction(models.Model):
potential_negative = False potential_negative = False
# We need to check stock availability in the source location # We need to check stock availability in the source location
location = production.location_src_id
for move in production.move_raw_ids: for move in production.move_raw_ids:
if move.state in ('done', 'cancel'): if move.state in ('done', 'cancel'):
continue continue
# User request:
# "if the components qty consumed is 0 then still show produce and produce all button"
# "only hide the visibility if components qty consumed will make the stock negative"
# If nothing is currently set to be consumed (0), we assume it's safe to proceed
# (or the user intends to consume 0/different amount later).
# We only block if the *Explicitly Consumed* amount exceeds available stock.
if move.quantity == 0:
continue
# Check availability based on the ACTUAL 'Consumed' quantity
qty_to_consume = move.quantity
_logger.info("DEBUG MO_LOCK: Move %s product=%s state=%s consumed=%s forecast=%s", move.id, move.product_id.display_name, move.state, qty_to_consume, move.forecast_availability)
# Skip check if product is not storable (Service, etc.) # Skip check if product is not storable (Service, etc.)
if not move.product_id.is_storable: if not move.product_id.is_storable:
continue continue
# If the move is already assigned (Ready), we consider it safe to produce. # If the move is already assigned (Ready), we consider it safe to produce.
if move.state == 'assigned': if move.state == 'assigned':
_logger.info("DEBUG MO_LOCK: Move is 'assigned', skipping negative check.")
continue continue
# Check availability # Check availability based on the ACTUAL 'Consumed' quantity
# We use forecast_availability as it includes reservations # We use forecast_availability as it includes reservations
# Use float_compare to avoid precision issues # Use float_compare to avoid precision issues
if float_compare(move.forecast_availability, qty_to_consume, precision_rounding=move.product_uom.rounding) < 0: if float_compare(move.forecast_availability, move.quantity, precision_rounding=move.product_uom.rounding) < 0:
_logger.info("DEBUG MO_LOCK: CRITICAL - potential negative stock detected for %s", move.product_id.display_name)
potential_negative = True potential_negative = True
break break
@ -78,8 +60,6 @@ class MrpProduction(models.Model):
production.show_produce = False production.show_produce = False
production.show_produce_all = False production.show_produce_all = False
_logger.info("DEBUG MO_LOCK: End - show_produce=%s show_produce_all=%s", production.show_produce, production.show_produce_all)
# Relaxed guard: Do not hide if qty_producing > 0 even if consumption is 0. # 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. # 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, # If they really want to block 0-consumption production, it should be a validation error on click,