From f273282ae4baffd8393e2518ec4e12086f4ec36c Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 19 May 2020 15:27:09 +0200 Subject: [PATCH] [IMP] improve constraint error message on quant When this error is triggered by a manufacturing order, it is useful to know which product / SN is causing the issue, esp. with large BoMs --- addons/stock/i18n/stock.pot | 6 ++++++ addons/stock/models/stock_quant.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index 1c1f3aee59026..1803677cad6b5 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -348,6 +348,12 @@ msgstr "" msgid "A serial number should only be linked to a single product." msgstr "" +#. module: stock +#: code:addons/stock/models/stock_quant.py:81 +#, python-format +msgid "Serial %s of product %s would have a quantity of %f." +msgstr "" + #. module: stock #: model:ir.model.fields,help:stock.field_product_product__type #: model:ir.model.fields,help:stock.field_product_template__type diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 20a4bd640c6db..538e17f3593bb 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -77,7 +77,9 @@ def check_product_id(self): def check_quantity(self): for quant in self: if float_compare(quant.quantity, 1, precision_rounding=quant.product_uom_id.rounding) > 0 and quant.lot_id and quant.product_id.tracking == 'serial': - raise ValidationError(_('A serial number should only be linked to a single product.')) + msg = _('A serial number should only be linked to a single product.') + msg += " " + _('Serial %s of product %s would have a quantity of %f.') % (quant.lot_id.name, quant.product_id.display_name, quant.quantity) + raise ValidationError(msg) @api.constrains('location_id') def check_location_id(self):