Skip to content

Commit

Permalink
[FIX] stock: Error when re-installing manufacturing application
Browse files Browse the repository at this point in the history
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
  • Loading branch information
simongoffin committed Apr 23, 2019
1 parent 19aa7c4 commit c7bfdec
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion addons/stock/models/stock_warehouse.py
Expand Up @@ -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)

Expand Down

0 comments on commit c7bfdec

Please sign in to comment.