[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
This commit is contained in:
Nicolas Martinelli
2016-09-05 08:39:18 +02:00
parent 9f0d3800cc
commit ea8d52a460
2 changed files with 37 additions and 0 deletions
+12
View File
@@ -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"
+25
View File
@@ -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}