[FIX] stock: correctly works on non unique recordsets

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

closes odoo/odoo#36656

X-original-commit: ca5def07346ac85bfb53304d6a73aaa85882d3d8
Signed-off-by: Christophe Simonis <chs@odoo.com>
This commit is contained in:
Christophe Simonis
2019-09-10 17:50:10 +00:00
parent 3c43fb61a3
commit 9ae6a2f6fe
2 changed files with 16 additions and 2 deletions
+1 -2
View File
@@ -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:
+15
View File
@@ -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