diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index b3651ec1292..1a608d5af48 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -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