From c7bfdecd1c5a88439beee1850da3c6518f8d975e Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 18 Apr 2019 15:15:01 +0200 Subject: [PATCH] [FIX] stock: Error when re-installing manufacturing application Steps to reproduce the bug: - Install MRP - Uninstall MRP - Install MRP Bug: An error was raised by sql constraint 'barcode_company_uniq' which ensures that a barcode for a location is unique per company. But when uninstalling MRP, some locations such as pbm_loc_id or sam_loc_id are set to active = False and when re-installing MRP, the function _create_missing_locations tried to re-create these locations and the sql constraint was raised. opw:1967534 --- addons/stock/models/stock_warehouse.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 913b94bb5a5cc..84abe9c8e9f48 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -488,7 +488,15 @@ def _create_missing_locations(self, vals): if not warehouse[location] and location not in vals: location_values['location_id'] = vals.get('view_location_id', warehouse.view_location_id.id) location_values['company_id'] = vals.get('company_id', warehouse.company_id.id) - missing_location[location] = self.env['stock.location'].create(location_values).id + inactive_loc = self.env['stock.location'].with_context(active_test=False).search([ + ('barcode', '=', location_values.get('barcode')), + ('company_id', '=', location_values['company_id']) + ]) + if not inactive_loc: + missing_location[location] = self.env['stock.location'].create(location_values).id + else: + inactive_loc.write(location_values) + missing_location[location] = inactive_loc.id if missing_location: warehouse.write(missing_location)