diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 2221edac80a..0bd4b0a454e 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -549,8 +549,7 @@ class Warehouse(models.Model): """ for warehouse in self: company_id = vals.get('company_id', warehouse.company_id.id) - vals.update(company_id=company_id) - sub_locations = warehouse._get_locations_values(vals, warehouse.code) + sub_locations = warehouse._get_locations_values(dict(vals, company_id=company_id), warehouse.code) missing_location = {} for location, location_values in sub_locations.items(): if not warehouse[location] and location not in vals: diff --git a/addons/stock/tests/test_warehouse.py b/addons/stock/tests/test_warehouse.py index 6c513d5c9b6..95fdd8b8129 100644 --- a/addons/stock/tests/test_warehouse.py +++ b/addons/stock/tests/test_warehouse.py @@ -2,6 +2,7 @@ from odoo.addons.stock.tests.common2 import TestStockCommon from odoo.tests import Form +from odoo.tools import mute_logger class TestWarehouse(TestStockCommon): @@ -432,6 +433,20 @@ class TestWarehouse(TestStockCommon): # Ensure there still no quants in distribution warehouse self.assertEqual(sum(self.env['stock.quant']._gather(product, warehouse_distribution_wavre.lot_stock_id).mapped('quantity')), 0) + def test_noleak(self): + # non-regression test to avoid company_id leaking to other warehouses (see blame) + wh = self.env["stock.warehouse"].search([]) + + assert len(set(wh.mapped("company_id.id"))) > 1 + + companies_before = wh.mapped(lambda w: (w.id, w.company_id)) + # writing on any field should change the company of warehouses + with mute_logger("odoo.models"): + wh.write({"whatever": "no one cares"}) + companies_after = wh.mapped(lambda w: (w.id, w.company_id)) + + self.assertEqual(companies_after, companies_before) + def test_toggle_active_warehouse_1(self): """ Basic test that create a warehouse with classic configuration. Archive it and check that locations, picking types, routes, rules are