diff --git a/addons/mrp/models/stock_warehouse.py b/addons/mrp/models/stock_warehouse.py index 40d6b6bb4b9..98e8cada056 100644 --- a/addons/mrp/models/stock_warehouse.py +++ b/addons/mrp/models/stock_warehouse.py @@ -13,6 +13,8 @@ class StockWarehouse(models.Model): help="When products are manufactured, they can be manufactured in this warehouse.") manufacture_pull_id = fields.Many2one( 'stock.rule', 'Manufacture Rule') + manufacture_mto_pull_id = fields.Many2one( + 'stock.rule', 'Manufacture MTO Rule') pbm_mto_pull_id = fields.Many2one( 'stock.rule', 'Picking Before Manufacturing MTO Rule') sam_rule_id = fields.Many2one( @@ -101,6 +103,8 @@ class StockWarehouse(models.Model): def _get_global_route_rules_values(self): rules = super(StockWarehouse, self)._get_global_route_rules_values() + location_src = self.manufacture_steps == 'mrp_one_step' and self.lot_stock_id or self.pbm_loc_id + production_location = self._get_production_location() location_id = self.manufacture_steps == 'pbm_sam' and self.sam_loc_id or self.lot_stock_id rules.update({ 'manufacture_pull_id': { @@ -119,6 +123,23 @@ class StockWarehouse(models.Model): 'propagate_cancel': self.manufacture_steps == 'pbm_sam' }, }, + 'manufacture_mto_pull_id': { + 'depends': ['manufacture_steps', 'manufacture_to_resupply'], + 'create_values': { + 'procure_method': 'make_to_order', + 'company_id': self.company_id.id, + 'action': 'pull', + 'auto': 'manual', + 'route_id': self._find_global_route('stock.route_warehouse0_mto', _('Make To Order')).id, + 'location_id': production_location.id, + 'location_src_id': location_src.id, + 'picking_type_id': self.manu_type_id.id + }, + 'update_values': { + 'name': self._format_rulename(location_src, production_location, 'MTO'), + 'active': self.manufacture_to_resupply, + }, + }, 'pbm_mto_pull_id': { 'depends': ['manufacture_steps', 'manufacture_to_resupply'], 'create_values': { diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index f3a9752446f..77bb41b8c7d 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1453,11 +1453,6 @@ class StockMove(models.Model): """ This method will try to apply the procure method MTO on some moves if a compatible MTO route is found. Else the procure method will be set to MTS """ - try: - mto_route = self.env['stock.warehouse']._find_global_route('stock.route_warehouse0_mto', - 'Make To Order') - except ValueError: - mto_route = False for move in self: product_id = move.product_id domain = [ @@ -1466,10 +1461,7 @@ class StockMove(models.Model): ('action', '!=', 'push') ] rules = self.env['procurement.group']._search_rule(False, product_id, move.warehouse_id, domain) - routes = product_id.route_ids + product_id.route_from_categ_ids + move.warehouse_id.route_ids if rules and (rules.procure_method == 'make_to_order'): move.procure_method = rules.procure_method - elif mto_route and mto_route.id in [x.id for x in routes]: - move.procure_method = 'make_to_order' else: move.procure_method = 'make_to_stock'