Skip to content
Browse files

[FIX] stock: correctly works on non unique recordsets

Followup of 3d6e917 to avoid leaking
the company of first warehouse on all others when writing on multiple

closes #36656

X-original-commit: ca5def0
Signed-off-by: Christophe Simonis <>
  • Loading branch information...
KangOl committed Sep 9, 2019
1 parent 3c43fb6 commit 9ae6a2f6fe608ecda03c4a60e5f8c81bea22a93c
Showing with 16 additions and 2 deletions.
  1. +1 −2 addons/stock/models/
  2. +15 −0 addons/stock/tests/
@@ -549,8 +549,7 @@ def _create_missing_locations(self, vals):
for warehouse in self:
company_id = vals.get('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:
@@ -2,6 +2,7 @@

from odoo.addons.stock.tests.common2 import TestStockCommon
from odoo.tests import Form
from import mute_logger

class TestWarehouse(TestStockCommon):
@@ -432,6 +433,20 @@ def test_mutiple_resupply_warehouse(self):
# 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(""))) > 1

companies_before = wh.mapped(lambda w: (, 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.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

0 comments on commit 9ae6a2f

Please sign in to comment.
You can’t perform that action at this time.