From 9a7f2e922790b02e65217dc89efb477a49bacf4c Mon Sep 17 00:00:00 2001 From: Sergio Morillo Date: Wed, 29 Dec 2021 16:16:22 +0100 Subject: [PATCH] Check categories are not mixed amoung warehouses. This commit refs #21470 --- location.py | 10 ++++++ tests/test_stock_product_category_location.py | 32 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/location.py b/location.py index b3e9249..dae18f8 100644 --- a/location.py +++ b/location.py @@ -122,3 +122,13 @@ class Location(metaclass=PoolMeta): return super().view_attributes() + [ ('//page[@id="categories"]', 'states', { 'invisible': ~Eval('type').in_(['warehouse', 'storage'])})] + + @classmethod + def copy(cls, records, default=None): + if default is None: + default = {} + else: + default = default.copy() + default.setdefault('categories', None) + default.setdefault('wh_categories', None) + return super().copy(records, default=default) diff --git a/tests/test_stock_product_category_location.py b/tests/test_stock_product_category_location.py index 3c7d9ca..ada40c2 100644 --- a/tests/test_stock_product_category_location.py +++ b/tests/test_stock_product_category_location.py @@ -71,7 +71,7 @@ class StockProductCategoryLocationTestCase(ModuleTestCase): child_cat, = Category.create([{'name': 'CAT2', 'parent': new_cat.id}]) cat_loc_rec = { 'category': new_cat.id, - 'warehouse': storage.parent.id, + 'warehouse': storage.warehouse.id, 'location': storage.id } CatLoc.create([cat_loc_rec]) @@ -86,6 +86,36 @@ class StockProductCategoryLocationTestCase(ModuleTestCase): self.assertEqual(child_cat.get_default_location(), storage_new) + @with_transaction() + def test_warehouse_isolation(self): + """Add the category default location for a warehouse""" + pool = Pool() + Location = pool.get('stock.location') + Category = pool.get('product.category') + CatLoc = pool.get('stock.product.category.location') + + storage, = Location.search([('code', '=', 'STO')]) + storage_new, = Location.create([{ + 'code': 'STO2', + 'name': 'Storage 2', + 'type': 'storage', + 'parent': storage.id + }]) + new_cat, = Category.create([{'name': 'CAT1'}]) + cat_loc_rec = { + 'category': new_cat.id, + 'warehouse': storage.warehouse.id, + 'location': storage.id + } + CatLoc.create([cat_loc_rec]) + + self.assertEqual(new_cat.get_default_location(), storage) + + # create new warehouse + new_wh, = Location.copy([storage.warehouse]) + + self.assertEqual(new_cat.get_default_location(warehouse=new_wh), None) + def suite(): suite = trytond.tests.test_tryton.suite()