diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 44f6942c943..f83d4bd030f 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -159,10 +159,11 @@ class Warehouse(models.Model): for warehouse in warehouses: # check if we need to delete and recreate route depends = [depend for depends in [value.get('depends', []) for value in warehouse._get_routes_values().values()] for depend in depends] - if any(depend in vals for depend in depends): + if 'code' in vals or any(depend in vals for depend in depends): picking_type_vals = warehouse._create_or_update_sequences_and_picking_types() if picking_type_vals: warehouse.write(picking_type_vals) + if any(depend in vals for depend in depends): route_vals = warehouse._create_or_update_route() if route_vals: warehouse.write(route_vals) @@ -807,13 +808,26 @@ class Warehouse(models.Model): """ input_loc, output_loc = self._get_input_output_locations(self.reception_steps, self.delivery_steps) return { - 'in_type_id': {'default_location_dest_id': input_loc.id}, - 'out_type_id': {'default_location_src_id': output_loc.id}, + 'in_type_id': { + 'default_location_dest_id': input_loc.id, + 'barcode': self.code.replace(" ", "").upper() + "-RECEIPTS", + }, + 'out_type_id': { + 'default_location_src_id': output_loc.id, + 'barcode': self.code.replace(" ", "").upper() + "-DELIVERY", + }, 'pick_type_id': { 'active': self.delivery_steps != 'ship_only', - 'default_location_dest_id': output_loc.id if self.delivery_steps == 'pick_ship' else self.wh_pack_stock_loc_id.id}, - 'pack_type_id': {'active': self.delivery_steps == 'pick_pack_ship'}, - 'int_type_id': {}, + 'default_location_dest_id': output_loc.id if self.delivery_steps == 'pick_ship' else self.wh_pack_stock_loc_id.id, + 'barcode': self.code.replace(" ", "").upper() + "-PICK", + }, + 'pack_type_id': { + 'active': self.delivery_steps == 'pick_pack_ship', + 'barcode': self.code.replace(" ", "").upper() + "-PACK", + }, + 'int_type_id': { + 'barcode': self.code.replace(" ", "").upper() + "-INTERNAL", + }, } def _get_picking_type_create_values(self, max_sequence): @@ -831,7 +845,6 @@ class Warehouse(models.Model): 'use_existing_lots': False, 'default_location_src_id': False, 'sequence': max_sequence + 1, - 'barcode': self.code.replace(" ", "").upper() + "-RECEIPTS", 'show_reserved': False, 'sequence_code': 'IN', 'company_id': self.company_id.id, @@ -842,7 +855,6 @@ class Warehouse(models.Model): 'use_existing_lots': True, 'default_location_dest_id': False, 'sequence': max_sequence + 5, - 'barcode': self.code.replace(" ", "").upper() + "-DELIVERY", 'sequence_code': 'OUT', 'company_id': self.company_id.id, }, 'pack_type_id': { @@ -853,7 +865,6 @@ class Warehouse(models.Model): 'default_location_src_id': self.wh_pack_stock_loc_id.id, 'default_location_dest_id': output_loc.id, 'sequence': max_sequence + 4, - 'barcode': self.code.replace(" ", "").upper() + "-PACK", 'sequence_code': 'PACK', 'company_id': self.company_id.id, }, 'pick_type_id': { @@ -863,7 +874,6 @@ class Warehouse(models.Model): 'use_existing_lots': True, 'default_location_src_id': self.lot_stock_id.id, 'sequence': max_sequence + 3, - 'barcode': self.code.replace(" ", "").upper() + "-PICK", 'sequence_code': 'PICK', 'company_id': self.company_id.id, }, 'int_type_id': { @@ -875,7 +885,6 @@ class Warehouse(models.Model): 'default_location_dest_id': self.lot_stock_id.id, 'active': self.reception_steps != 'one_step' or self.delivery_steps != 'ship_only' or self.user_has_groups('stock.group_stock_multi_locations'), 'sequence': max_sequence + 2, - 'barcode': self.code.replace(" ", "").upper() + "-INTERNAL", 'sequence_code': 'INT', 'company_id': self.company_id.id, }, diff --git a/addons/stock/tests/test_warehouse.py b/addons/stock/tests/test_warehouse.py index f5ffd7b1907..d1444161a17 100644 --- a/addons/stock/tests/test_warehouse.py +++ b/addons/stock/tests/test_warehouse.py @@ -615,3 +615,17 @@ class TestWarehouse(TestStockCommon): self.assertTrue(warehouse.int_type_id.active) self.assertTrue(warehouse.pick_type_id.active) self.assertTrue(warehouse.pack_type_id.active) + + def test_edit_warehouse_1(self): + wh = Form(self.env['stock.warehouse']) + wh.name = "Chicago" + wh.code = "chic" + warehouse = wh.save() + self.assertEqual(warehouse.int_type_id.barcode, 'CHIC-INTERNAL') + self.assertEqual(warehouse.int_type_id.sequence_id.prefix, 'chic/INT/') + + wh = Form(warehouse) + wh.code = 'CH' + wh.save() + self.assertEqual(warehouse.int_type_id.barcode, 'CH-INTERNAL') + self.assertEqual(warehouse.int_type_id.sequence_id.prefix, 'CH/INT/')