[FIX] stock: don't check parent locations when finding putaway rules

Let's say we have location A, B, and C. A is the parent of B, B is the
parent of C. And we have a putaway rule to move product from A to B. Now
receive product at C, because currently when we can't find a putaway
rule at one location, we will loop to check its parent locations. So the
puteaway rule A -> B will be found, and product received at C will in
the end be stored at B.
After this commit, we don't check the parent locations when we can't
find a putaway rule.

Task 2341820
PR #63516
ENT PR odoo/enterprise#15363
UPG PR odoo/upgrade#2040
This commit is contained in:
yhu-odoo
2021-03-31 08:55:44 +00:00
parent 6e972e792d
commit f2b19e4f4d
2 changed files with 13 additions and 65 deletions
+13 -16
View File
@@ -173,23 +173,20 @@ class Location(models.Model):
def _get_putaway_strategy(self, product):
''' Returns the location where the product has to be put, if any compliant putaway strategy is found. Otherwise returns None.'''
current_location = self
putaway_location = self.env['stock.location']
while current_location and not putaway_location:
# Looking for a putaway about the product.
putaway_rules = current_location.putaway_rule_ids.filtered(lambda x: x.product_id == product)
if putaway_rules:
putaway_location = putaway_rules[0].location_out_id
# If not product putaway found, we're looking with category so.
else:
categ = product.categ_id
while categ:
putaway_rules = current_location.putaway_rule_ids.filtered(lambda x: x.category_id == categ)
if putaway_rules:
putaway_location = putaway_rules[0].location_out_id
break
categ = categ.parent_id
current_location = current_location.location_id
# Looking for a putaway about the product.
putaway_rules = self.putaway_rule_ids.filtered(lambda x: x.product_id == product)
if putaway_rules:
putaway_location = putaway_rules[0].location_out_id
# If not product putaway found, we're looking with category so.
else:
categ = product.categ_id
while categ:
putaway_rules = self.putaway_rule_ids.filtered(lambda x: x.category_id == categ)
if putaway_rules:
putaway_location = putaway_rules[0].location_out_id
break
categ = categ.parent_id
return putaway_location
def should_bypass_reservation(self):
-49
View File
@@ -937,55 +937,6 @@ class StockMove(TransactionCase):
# check if the putaway was rightly applied
self.assertEqual(move1.move_line_ids.location_dest_id.id, shelf2_location.id)
def test_putaway_7(self):
""" Checks parents locations are also browsed when looking for putaways.
WH/Stock > WH/Stock/Floor1> WH/Stock/Floor1/Rack1 > WH/Stock/Floor1/Rack1/Shelf2
The putaway is on Floor1 to send to Shelf2
A move from supplier to Rack1 should send to shelf2
"""
floor1 = self.env['stock.location'].create({
'name': 'floor1',
'usage': 'internal',
'location_id': self.stock_location.id,
})
rack1 = self.env['stock.location'].create({
'name': 'rack1',
'usage': 'internal',
'location_id': floor1.id,
})
shelf2 = self.env['stock.location'].create({
'name': 'shelf2',
'usage': 'internal',
'location_id': rack1.id,
})
# putaway floor1 -> shelf2
putaway = self.env['stock.putaway.rule'].create({
'product_id': self.product.id,
'location_in_id': floor1.id,
'location_out_id': shelf2.id,
})
floor1.write({
'putaway_rule_ids': [(4, putaway.id, 0)],
})
# stock move supplier -> rack1
move1 = self.env['stock.move'].create({
'name': 'test_putaway_6',
'location_id': self.supplier_location.id,
'location_dest_id': rack1.id,
'product_id': self.product.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 100.0,
})
move1._action_confirm()
self.assertEqual(move1.state, 'assigned')
self.assertEqual(len(move1.move_line_ids), 1)
# check if the putaway was rightly applied
self.assertEqual(move1.move_line_ids.location_dest_id.id, shelf2.id)
def test_availability_1(self):
""" Check that the `availability` field on a move is correctly computed when there is
more than enough products in stock.