[FIX] stock: raise a warning if the user deactivates 'lot & serial numbers' settings while products use it

The "lots & serial numbers" feature can be deactivated at any point.
If there are active products that are tracked, either by lot or serial number,
it can be confusing since deactivating it will hide the relevant fields.
Therefore we raise a warning at onchange if there are tracked active products.

opw 2036173

closes odoo/odoo#35108

Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
This commit is contained in:
Nans Lefebvre
2019-07-25 14:29:45 +00:00
parent b82df99d7a
commit c7beb9994f
2 changed files with 16 additions and 1 deletions
+7
View File
@@ -6495,6 +6495,13 @@ msgstr ""
msgid "You need to supply a Lot/Serial number for product %s."
msgstr ""
#. module: stock
#: code:addons/stock/models/res_config_settings.py:70
#, python-format
msgid "You should not remove the 'lots and serial numbers' option while the following products are still tracked by lot or serial number:\n"
" %s"
msgstr ""
#. module: stock
#: code:addons/stock/models/product.py:394
#: code:addons/stock/models/product.py:538
+9 -1
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class ResConfigSettings(models.TransientModel):
@@ -64,6 +65,13 @@ class ResConfigSettings(models.TransientModel):
def _onchange_group_stock_production_lot(self):
if not self.group_stock_production_lot:
self.group_lot_on_delivery_slip = False
tracked_products = self.env['product.template'].search([('tracking', 'in', ['lot', 'serial']),])
if not self.group_stock_production_lot and tracked_products:
names = ", ".join(tracked_products.mapped('display_name') if len(tracked_products) <= 10
else tracked_products[:10].mapped('display_name') + ["..."])
raise UserError(_("You should not remove the 'lots and serial numbers' "
"option while the following products are still tracked by lot "
"or serial number:\n %s") % names)
@api.onchange('group_stock_adv_location')
def onchange_adv_location(self):