From d4eb7afcf1f052c74869c6532ca32f9e168e1a84 Mon Sep 17 00:00:00 2001 From: "Mathias Mathy (MAMA)" Date: Thu, 6 Oct 2022 13:27:27 +0000 Subject: [PATCH] [FIX] stock: rename routes on warehouses' name change When a warehouse is renamed, associated route's name shall be renamed accordingly. As previously, the call to 'route.write()' in method '_update_name_and_code' was done after the 'super().write()', there was no way to remember the old name of the warehouse, and the 'replace' was so uneffective. The effectivenes of the replace is reestablished by doing the 'super().write' after the call to '_update_name_and_code', however, it breaks the method '_get_sequence_values' because it expects the name and code to be already written. That's why the optional parameters 'name' and 'code' are added to this last method. Task : 2985735 closes odoo/odoo#102968 X-original-commit: 3ebb80828f2d0bc15dd53c594c07bc374cc5be8d Signed-off-by: Arnold Moyaux (arm) --- addons/stock/models/stock_warehouse.py | 34 ++++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index d327c184fe8..3c3330b426f 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -183,11 +183,11 @@ class Warehouse(models.Model): for warehouse in self: warehouse._update_partner_data(vals['partner_id'], warehouse.company_id.id) - res = super(Warehouse, self).write(vals) - if vals.get('code') or vals.get('name'): warehouses._update_name_and_code(vals.get('name'), vals.get('code')) + res = super().write(vals) + 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] @@ -886,7 +886,7 @@ class Warehouse(models.Model): if warehouse.mto_pull_id: warehouse.mto_pull_id.write({'name': warehouse.mto_pull_id.name.replace(warehouse.name, new_name, 1)}) for warehouse in self: - sequence_data = warehouse._get_sequence_values() + sequence_data = warehouse._get_sequence_values(name=new_name, code=new_code) # `ir.sequence` write access is limited to system user if self.user_has_groups('stock.group_stock_manager'): warehouse = warehouse.sudo() @@ -1013,39 +1013,41 @@ class Warehouse(models.Model): }, }, max_sequence + 6 - def _get_sequence_values(self): + def _get_sequence_values(self, name=False, code=False): """ Each picking type is created with a sequence. This method returns the sequence values associated to each picking type. """ + name = name if name else self.name + code = code if code else self.code return { 'in_type_id': { - 'name': self.name + ' ' + _('Sequence in'), - 'prefix': self.code + '/IN/', 'padding': 5, + 'name': name + ' ' + _('Sequence in'), + 'prefix': code + '/IN/', 'padding': 5, 'company_id': self.company_id.id, }, 'out_type_id': { - 'name': self.name + ' ' + _('Sequence out'), - 'prefix': self.code + '/OUT/', 'padding': 5, + 'name': name + ' ' + _('Sequence out'), + 'prefix': code + '/OUT/', 'padding': 5, 'company_id': self.company_id.id, }, 'pack_type_id': { - 'name': self.name + ' ' + _('Sequence packing'), - 'prefix': self.code + '/PACK/', 'padding': 5, + 'name': name + ' ' + _('Sequence packing'), + 'prefix': code + '/PACK/', 'padding': 5, 'company_id': self.company_id.id, }, 'pick_type_id': { - 'name': self.name + ' ' + _('Sequence picking'), - 'prefix': self.code + '/PICK/', 'padding': 5, + 'name': name + ' ' + _('Sequence picking'), + 'prefix': code + '/PICK/', 'padding': 5, 'company_id': self.company_id.id, }, 'int_type_id': { - 'name': self.name + ' ' + _('Sequence internal'), - 'prefix': self.code + '/INT/', 'padding': 5, + 'name': name + ' ' + _('Sequence internal'), + 'prefix': code + '/INT/', 'padding': 5, 'company_id': self.company_id.id, }, 'return_type_id': { - 'name': self.name + ' ' + _('Sequence return'), - 'prefix': self.code + '/RET/', 'padding': 5, + 'name': name + ' ' + _('Sequence return'), + 'prefix': code + '/RET/', 'padding': 5, 'company_id': self.company_id.id, }, }