From bc3d5ca7755d8a0d9a3e4c185b26e201ed8fefc3 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Wed, 18 Oct 2017 03:56:42 -0800 Subject: [PATCH] [FIX] stock.move : add more information in UserError of product_uom Constrains Steps to reproduce the bug: - Create a bom with lines - Change on one product in product view form the uom with diffrent category (exemple : unit -> meter) - Create un manufactoring order : you have an error You try to move a product using a UoM that is not compatible with the UoM of the product moved. Please use an UoM in the same UoM category., the error message doesn't give with product there are an issue. ( if you have hundred of line in your Bom, it is very difficult). This fix improves the error message. opw:800328 --- addons/stock/i18n/stock.pot | 16 ++++++++++++++++ addons/stock/models/stock_move.py | 6 ++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index d3a06ce060f..559aa1d3b85 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -15,6 +15,22 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: stock +#: code:addons/stock/models/stock_move.py:230 +#, python-format +msgid "\n" +"\n" +"%s --> Product UoM is %s (%s) - Move UoM is %s (%s)" +msgstr "" + +#. module: stock +#: code:addons/stock/models/stock_move.py:231 +#, python-format +msgid "\n" +"\n" +"Blocking: %s" +msgstr "" + #. module: stock #: model:ir.model.fields,help:stock.field_stock_config_settings_module_stock_dropshipping msgid "\n" diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 719bf08ea1a..2cd17da87ed 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -223,10 +223,12 @@ class StockMove(models.Model): @api.constrains('product_uom') def _check_uom(self): - moves_error = self.filtered(lambda move: move.product_id.uom_id.category_id.id != move.product_uom.category_id.id) + moves_error = self.filtered(lambda move: move.product_id.uom_id.category_id != move.product_uom.category_id) if moves_error: user_warning = _('You try to move a product using a UoM that is not compatible with the UoM of the product moved. Please use an UoM in the same UoM category.') - user_warning += '\n\nBlocking: %s' % ' ,'.join(moves_error.mapped('name')) + for move in moves_error: + user_warning += _('\n\n%s --> Product UoM is %s (%s) - Move UoM is %s (%s)') % (move.product_id.display_name, move.product_id.uom_id.name, move.product_id.uom_id.category_id.name, move.product_uom.name, move.product_uom.category_id.name) + user_warning += _('\n\nBlocking: %s') % ' ,'.join(moves_error.mapped('name')) raise UserError(user_warning) @api.model_cr