From 8c4e775cea853bbfbeffd0f6dd38644ddd2e1215 Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Thu, 2 Nov 2023 09:52:47 +0000 Subject: [PATCH] [FIX] stock: fix production_lot settings For existing users who had previously disabled the "Lots & Serial Numbers" settings, by applying this fix: https://github.com/odoo/odoo/pull/138907/commits/376ee1289eba840f1d8b2b6149d933bdedd47518 They will get the user error each time they try to access the settings. Therefore, we prefer to prevent this and trigger the error only when necessary. opw-3452946 closes odoo/odoo#141921 X-original-commit: 608439b09cb68409dec10427d5b927ce0a27d526 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/stock/i18n/stock.pot | 9 +++++++++ addons/stock/models/res_config_settings.py | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index c9302002735..0221234dc5a 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -10225,6 +10225,15 @@ msgstr "" msgid "You have processed less products than the initial demand." msgstr "" +#. module: stock +#. odoo-python +#: code:addons/stock/models/res_config_settings.py:0 +#, python-format +msgid "" +"You have product(s) in stock that have lot/serial number tracking enabled. \n" +"Switch off tracking on all the products before switching off this setting." +msgstr "" + #. module: stock #. odoo-python #: code:addons/stock/models/product.py:0 diff --git a/addons/stock/models/res_config_settings.py b/addons/stock/models/res_config_settings.py index 866c58e48e2..dec37d0bd2f 100644 --- a/addons/stock/models/res_config_settings.py +++ b/addons/stock/models/res_config_settings.py @@ -134,4 +134,8 @@ class ResConfigSettings(models.TransientModel): ('show_operations', '=', False) ]).show_operations = True + if not self.group_stock_production_lot and previous_group.get('group_stock_production_lot'): + if self.env['product.product'].search_count([('tracking', '!=', 'none')], limit=1): + raise UserError(_("You have product(s) in stock that have lot/serial number tracking enabled. \nSwitch off tracking on all the products before switching off this setting.")) + return