From 9775d4cce886ea7d16b85f45dc2060f5596e80d3 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Tue, 30 Oct 2018 19:54:25 +0000 Subject: [PATCH] [FIX] stock: Don't allow to archive main locations of warehouse When a location is archived, we are checking that it is not used a warehouse stock or view location to avoid bad configration leading to inconsistencies on stock available quantities. TASK-ID: 38469 --- addons/stock/models/stock_location.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index 6e48f4283e5..4c9f32c3266 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -94,6 +94,13 @@ class Location(models.Model): " Please unreserve the products first." )) if 'active' in values: + if values['active'] == False: + for location in self: + warehouses = self.env['stock.warehouse'].search([('active', '=', True), '|', ('lot_stock_id', '=', location.id), ('view_location_id', '=', location.id)]) + if warehouses: + raise UserError(_("You cannot archive the location %s as it is" + " used by your warehouse %s") % (location.display_name, warehouses[0].display_name)) + if not self.env.context.get('do_not_check_quant'): children_location = self.env['stock.location'].with_context(active_test=False).search([('id', 'child_of', self.ids)]) internal_children_locations = children_location.filtered(lambda l: l.usage == 'internal')