From ea8d52a4600b74cb97c6dc3da340af5843291653 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 2 Sep 2016 17:36:14 +0200 Subject: [PATCH] [IMP] mrp: warning message if unique serial numbers When consuming products tracked by unique serial number, no check is done on the quantity consumed for a given serial number. It means that negative quants might be created without any warning to the user. We implement a simple warning thanks to a onchange. opw-687129 --- addons/mrp/i18n/mrp.pot | 12 ++++++++++++ addons/mrp/wizard/mrp_product_produce.py | 25 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index 6d3699f7642..a169ab242ba 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -890,6 +890,12 @@ msgstr "" msgid "Is Follower" msgstr "" +#. module: mrp +#: code:addons/mrp/wizard/mrp_product_produce.py:127 +#, python-format +msgid "Issue with lot quantity!" +msgstr "" + #. module: mrp #: model:ir.model.fields,help:mrp.field_mrp_routing_location_id msgid "Keep empty if you produce at the location where the finished products are needed.Set a location if you produce at a fixed location. This can be a partner location if you subcontract the manufacturing operations." @@ -2215,6 +2221,12 @@ msgid "You can not delete a Bill of Material with running manufacturing orders.\ "Please close or cancel it first." msgstr "" +#. module: mrp +#: code:addons/mrp/wizard/mrp_product_produce.py:128 +#, python-format +msgid "You plan to consume more than 1.00 unit of product %s with unique lot number %s" +msgstr "" + #. module: mrp #: model:ir.ui.view,arch_db:mrp.view_mrp_product_template_form_inherited msgid "days" diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py index 365f5f5a466..bc03ff1765c 100644 --- a/addons/mrp/wizard/mrp_product_produce.py +++ b/addons/mrp/wizard/mrp_product_produce.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from openerp import api, _ from openerp.osv import fields, osv import openerp.addons.decimal_precision as dp @@ -104,3 +105,27 @@ class mrp_product_produce(osv.osv_memory): self.pool.get('mrp.production').action_produce(cr, uid, production_id, data.product_qty, data.mode, data, context=context) return {} + + @api.onchange('consume_lines') + def _onchange_consume_lines(self): + ''' + The purpose of the method is to warn the user if we plan to consume more than one unit of + a product with unique serial number. + ''' + for product in self.consume_lines.mapped('product_id'): + if product.tracking != 'serial': + continue + + qty_by_lot = {} + lines = self.consume_lines.filtered(lambda r: r.product_id == product) + for line in lines: + qty_by_lot.setdefault(line.lot_id, 0.0) + qty_by_lot[line.lot_id] += line.product_qty + + if qty_by_lot[line.lot_id] > 1.0: + warning_mess = { + 'title': _('Issue with lot quantity!'), + 'message' : _('You plan to consume more than 1.00 unit of product %s with unique lot number %s') % \ + (product.name, line.lot_id.name) + } + return {'warning': warning_mess}