From 1df4969d238938035be651e01254982e4d0e856d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Thu, 14 Jan 2021 16:43:45 +0000 Subject: [PATCH] [FIX] stock: add warning when creating second warehouse Add a warning to explain that create a second warehouse will activate the multi-location automatically. task-2439909 X-original-commit: 4964a9482b8b195f5b629ea5c91f7d7bfcce2163 --- addons/sale_mrp/tests/test_sale_mrp_procurement.py | 8 ++++---- addons/stock/i18n/stock.pot | 6 ++++++ addons/stock/models/stock_warehouse.py | 12 ++++++++++++ addons/stock_dropshipping/tests/test_crossdock.py | 12 ++++++------ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/addons/sale_mrp/tests/test_sale_mrp_procurement.py b/addons/sale_mrp/tests/test_sale_mrp_procurement.py index ce076c7b4bf..4de6c6d0a4c 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_procurement.py +++ b/addons/sale_mrp/tests/test_sale_mrp_procurement.py @@ -77,10 +77,10 @@ class TestSaleMrpProcurement(TransactionCase): self.env.ref('stock.route_warehouse0_mto').active = True # Create warehouse self.customer_location = self.env['ir.model.data'].xmlid_to_res_id('stock.stock_location_customers') - warehouse_form = Form(self.env['stock.warehouse']) - warehouse_form.name = 'Test Warehouse' - warehouse_form.code = 'TWH' - self.warehouse = warehouse_form.save() + self.warehouse = self.env['stock.warehouse'].create({ + 'name': 'Test Warehouse', + 'code': 'TWH' + }) self.uom_unit = self.env.ref('uom.product_uom_unit') diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index 6642a8016ec..3e44012c0a2 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -7958,3 +7958,9 @@ msgstr "" #, python-format msgid "You can't desactivate the multi-location if you have more than once warehouse by company" msgstr "" + +#. module: stock +#: code:addons/stock/models/stock_warehouse.py:0 +#, python-format +msgid "Creating a new warehouse will automatically activate the Storage Locations setting" +msgstr "" diff --git a/addons/stock/models/stock_warehouse.py b/addons/stock/models/stock_warehouse.py index 68980a2fba2..3df2f07be43 100644 --- a/addons/stock/models/stock_warehouse.py +++ b/addons/stock/models/stock_warehouse.py @@ -92,6 +92,18 @@ class Warehouse(models.Model): ('warehouse_code_uniq', 'unique(code, company_id)', 'The short name of the warehouse must be unique per company!'), ] + @api.onchange('company_id') + def _onchange_company_id(self): + group_user = self.env.ref('base.group_user') + group_stock_multi_warehouses = self.env.ref('stock.group_stock_multi_warehouses') + if group_stock_multi_warehouses not in group_user.implied_ids: + return { + 'warning': { + 'title': _('Warning'), + 'message': _('Creating a new warehouse will automatically activate the Storage Locations setting') + } + } + @api.model def create(self, vals): # create view location for warehouse then create all locations diff --git a/addons/stock_dropshipping/tests/test_crossdock.py b/addons/stock_dropshipping/tests/test_crossdock.py index f50d3dee19c..2d13a7c735c 100644 --- a/addons/stock_dropshipping/tests/test_crossdock.py +++ b/addons/stock_dropshipping/tests/test_crossdock.py @@ -13,12 +13,12 @@ class TestCrossdock(common.TransactionCase): supplier_crossdock = self.env['res.partner'].create({'name': "Crossdocking supplier"}) # I first create a warehouse with pick-pack-ship and reception in 2 steps - wh_f = Form(self.env['stock.warehouse']) - wh_f.name = 'WareHouse PickPackShip' - wh_f.code = 'whpps' - wh_f.reception_steps = 'two_steps' - wh_f.delivery_steps = 'pick_pack_ship' - wh_pps = wh_f.save() + wh_pps = self.env['stock.warehouse'].create({ + 'name': 'WareHouse PickPackShip', + 'code': 'whpps', + 'reception_steps': 'two_steps', + 'delivery_steps': 'pick_pack_ship', + }) # Check that cross-dock route is active self.assertTrue(wh_pps.crossdock_route_id.active,