diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index ba8d0d98e22..9af4de81d68 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1258,6 +1258,18 @@ class MrpProduction(models.Model): continue filtered_documents[(parent, responsible)] = rendering_context production._log_manufacture_exception(filtered_documents, cancel=True) + + # In case of a flexible BOM, we don't know from the state of the moves if the MO should + # remain in progress or done. Indeed, if all moves are done/cancel but the quantity produced + # is lower than expected, it might mean: + # - we have used all components but we still want to produce the quantity expected + # - we have used all components and we won't be able to produce the last units + # + # However, if the user clicks on 'Cancel', it is expected that the MO is either done or + # canceled. If the MO is still in progress at this point, it means that the move raws + # are either all done or a mix of done / canceled => the MO should be done. + self.filtered(lambda p: p.state not in ['done', 'cancel'] and p.bom_id.consumption == 'flexible').write({'state': 'done'}) + return True def _get_document_iterate_key(self, move_raw_id):