In Odoo Studio, I want to create an automatic action that prevents a Manufacturing Order (MO) from being produced if the components are not available in stock. Can you help me with the Python code for this?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
2
Respuestas
399
Vistas
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}")
There is no need for custom Python code to achieve this.
You set this up on the Bill of Material. In the 'Miscellaneous' tab, under 'Manufacturing Readiness', set this to 'When all components are available'. This should also be the default setting on a BoM.
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
Inscribirse