Setup in Odoo
- Go to Developer Mode (activate it if not already).
- Navigate to Technical > Automation > Automated Actions.
-
Create a new Automated Action:
- Model: Manufacturing Order (mrp.production)
- Trigger: On Update or On Creation & Update (depending on use case)
- Filter Domain (optional): You may filter on state = 'confirmed' or similar.
- Action To Do: Execute Python Code
Python Code Example
Here’s the Python code that can be used in the automated action to prevent production if components are missing:
if record.state == 'confirmed': for move in record.move_raw_ids: if move.product_id.type == 'product' and move.product_uom_qty > move.reserved_availability: raise UserError(f"Not enough stock for component '{move.product_id.display_name}'.\n" f"Required: {move.product_uom_qty}, Reserved: {move.reserved_availability}")