diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index 6270723660b..4c8e1a5a7f5 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -374,7 +374,7 @@ class StockWarehouseOrderpoint(models.Model): quants[item[0]].append((item[1], item[2])) rounding = {product.id: product.uom_id.rounding for product in all_product_ids} - path = {loc: loc.parent_path for loc in self.env['stock.location'].search([('id', 'child_of', all_replenish_location_ids.ids)])} + path = {loc: loc.parent_path for loc in self.env['stock.location'].with_context(active_test=False).search([('id', 'child_of', all_replenish_location_ids.ids)])} for loc in all_replenish_location_ids: for product in all_product_ids: qty_available = sum(q[1] for q in quants.get(product, [(0, 0)]) if q[0] and path[q[0]] in loc.parent_path) diff --git a/addons/stock/tests/test_proc_rule.py b/addons/stock/tests/test_proc_rule.py index 371eec3c327..cca1f782175 100644 --- a/addons/stock/tests/test_proc_rule.py +++ b/addons/stock/tests/test_proc_rule.py @@ -528,6 +528,31 @@ class TestProcRule(TransactionCase): orderpoint.action_replenish(force_to_max=True) self.assertEqual(orderpoint.qty_forecast, 200.0) + def test_orderpoint_location_archive(self): + warehouse = self.env['stock.warehouse'].create({ + 'name': 'Test Warehouse', + 'code': 'TWH' + }) + stock_loc = warehouse.lot_stock_id + shelf1 = self.env['stock.location'].create({ + 'location_id': stock_loc.id, + 'usage': 'internal', + 'name': 'shelf1' + }) + product = self.env['product.product'].create({'name': 'Test Product', 'type': 'product'}) + stock_move = self.env['stock.move'].create({ + 'name': 'Test Move', + 'product_id': product.id, + 'product_uom': product.uom_id.id, + 'product_uom_qty': 1, + 'location_id': shelf1.id, + 'location_dest_id': self.env.ref('stock.stock_location_customers').id, + }) + stock_move._action_confirm() + shelf1.active = False + # opening the replenishment should not raise a KeyError even if the location is archived + self.env['stock.warehouse.orderpoint'].action_open_orderpoints() + class TestProcRuleLoad(TransactionCase): def setUp(cls):