[IMP] stock, mrp: remove MTO route magical behavior
When a move is created from a location A to a location B and not via a rule but it wants to apply the rule logic in order to know if a move is MTS or MTO then _adjust_procure_method is called. It will check if a rule between A and B for the selected product/ category/warehouse and if it exists it will apply the rule procure method to the move. If not it will check if the route MTO is ticked, and will set the move as MTO even if no rule exist. It could be miss understanding by the user that have moves MTO without matching rule. It would be easier to have a single proccess with rule.
This commit is contained in:
@@ -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': {
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user