[FIX] mrp: state of flexible MO

- Create flexible BOM for product P
- Create a MO for 5 units
- Produce 3 units
- Post the inventory
- Cancel the MO

The MO remains 'In Progress'.

In case of a flexible BOM, the quantity produced is compared to the
quantity to produce to know whether the MO should be done. In this
specific case, however, the MO should be closed.

It's not possible to rely on the move states in this case, so we
force the MO state.

opw-2270279

closes odoo/odoo#53010

X-original-commit: c99fe9dc5b5054d8d92b7283ad9f27f150de410b
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Nicolas Martinelli
2020-06-16 06:20:26 +00:00
parent 3aaa0088cf
commit 2399b59e28
+12
View File
@@ -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):