[FIX] stock: consider archived locations for orderpoint creation
orderpoint creation should also consider archived location while computing qty_available or else users will be faced with a `KeyError` closes odoo/odoo#156965 X-original-commit: 1467cc1a2d773b8c7cbb4410c5c2f756764ca7c8 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
committed by
William Henrotin
parent
f052c8a858
commit
95acbfcf9d
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user