feat: Refine component availability check to use forecast_availability and prevent hiding produce buttons for zero-consumed partial productions.
This commit is contained in:
parent
0285ce9ebe
commit
2f32964266
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user