[IMP] mrp: hook method to control auto confirmation of MOs

There is a bit of a dance on the lambda function to filter the MOs
that should be autoconfirmed out of a procurement. To the point
that the logic is different in v14 and v15/16.

Refs:

- v14: https://github.com/odoo/odoo/commit/5fd6c7251331de2600eaee76114b76f535652fec
- v16: https://github.com/odoo/odoo/commit/2ab878aecb67930a9a7cd35901cb6c4b98c7e442
- v16 previous: https://github.com/odoo/odoo/commit/2b003b8d3917b45772b5f16edf21292446e96601

It would be great for partners to be able to extend it and be able
to control the logic used even if the default behavior gets changed
again.

closes odoo/odoo#118761

X-original-commit: 3c5c00c6bf63a90d747ddc74b31cdced0116d74d
Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
Lois Rilo
2023-04-18 09:24:36 +02:00
committed by Arnold Moyaux
parent fd9a4c2101
commit 3296aee6cf
+4 -2
View File
@@ -38,6 +38,9 @@ class StockRule(models.Model):
remaining |= rule
super(StockRule, remaining)._compute_picking_type_code_domain()
def _should_auto_confirm_procurement_mo(self, p):
return (not p.orderpoint_id and p.move_raw_ids) or (p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)
@api.model
def _run_manufacture(self, procurements):
new_productions_values_by_company = defaultdict(list)
@@ -79,8 +82,7 @@ class StockRule(models.Model):
for company_id, productions_values in new_productions_values_by_company.items():
# create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example)
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(productions_values)
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or\
(p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm()
productions.filtered(self._should_auto_confirm_procurement_mo).action_confirm()
for production in productions:
origin_production = production.move_dest_ids and production.move_dest_ids[0].raw_material_production_id or False