Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.
Module: Manufacturing
Entity: mrp.production
Compute Method: _compute_state
| Inputs | Method | Outputs |
|---|---|---|
|
""" Compute the production state. This uses a similar process to stock
picking, but has been adapted to support having no moves. This adaption
includes some state changes outside of this compute.
There exist 3 extra steps for production:
- - progress: At least one item is produced or consumed.
- - to_close: The quantity produced is greater than the quantity to
- produce and all work orders has been finished.
+ - progress: At least one item(component) is consumed, or at least one work order is either in_progress or done.
+ - to_close: All work orders are either Finished or Cancelled.
"""
for production in self:
- if not production.state or not production.product_uom_id:
+ if not production.state or not production.uom_id or not (production.id or production._origin.id):
production.state = 'draft'
elif production.state == 'cancel' or (production.move_finished_ids and all(move.state == 'cancel' for move in production.move_finished_ids)):
production.state = 'cancel'
elif (
production.state == 'done'
or (production.move_raw_ids and all(move.state in ('cancel', 'done') for move in production.move_raw_ids))
and all(move.state in ('cancel', 'done') for move in production.move_finished_ids)
):
production.state = 'done'
elif production.workorder_ids and all(wo_state in ('done', 'cancel') for wo_state in production.workorder_ids.mapped('state')):
production.state = 'to_close'
- elif not production.workorder_ids and float_compare(production.qty_producing, production.product_qty, precision_rounding=production.product_uom_id.rounding) >= 0:
- production.state = 'to_close'
- elif any(wo_state in ('progress', 'done') for wo_state in production.workorder_ids.mapped('state')):
- production.state = 'progress'
- elif production.product_uom_id and not float_is_zero(production.qty_producing, precision_rounding=production.product_uom_id.rounding):
- production.state = 'progress'
- elif any(production.move_raw_ids.mapped('picked')):
+ elif (
+ any(wo_state in ('progress', 'done') for wo_state in production.workorder_ids.mapped('state'))
+ or any(production.move_raw_ids.mapped('picked'))
+ ):
production.state = 'progress'
|
|
