From bafa1a677e0b7d5063e932a15ad7a448359ccbe0 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Fri, 29 Jan 2016 12:25:30 +0100 Subject: [PATCH] [FIX] stock: creation of stock inventory adjustement The system cannot create two inventory adjustements in state 'in Progess' with the same product, with the same location, same package, same lot and same owner. Example:if two adjustments(ADJ1, ADJ2) are created with the same product(P) and with the same location(L), let's say: qty_available for P is 10 in ADJ1: Theoritical Quantity=10 and Real Quantity=20 => a quant with +10 is created in ADJ2: Theoritical Quantity=10 and Real Quantity=30 => a quant with +20 is created When ADJ1 is validated then qty_available for P is now 20(that 's ok) When ADJ2 is validated then qty_available for P is now 40(that's wrong because the Real Quantity is expected which is 30) This is why this fix is required. opw:660658 --- addons/stock/i18n/stock.pot | 6 ++++++ addons/stock/stock.py | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/addons/stock/i18n/stock.pot b/addons/stock/i18n/stock.pot index daae3a0fc74..805485062d1 100644 --- a/addons/stock/i18n/stock.pot +++ b/addons/stock/i18n/stock.pot @@ -51,6 +51,12 @@ msgstr "" msgid " (reserved)" msgstr "" +#. module: stock +#: code:addons/stock/stock.py:2954 +#, python-format +msgid "You cannot have two inventory adjustements in state 'in Progess' with the same product(%s), same location(%s), same package, same owner and same lot. Please first validate the first inventory adjustement with this product before creating another one." +msgstr "" + #. module: stock #: code:addons/stock/stock.py:3090 #, python-format diff --git a/addons/stock/stock.py b/addons/stock/stock.py index a4deff3d161..8cef6087172 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -2942,6 +2942,18 @@ class stock_inventory_line(osv.osv): 'product_uom_id': lambda self, cr, uid, ctx=None: self.pool['ir.model.data'].get_object_reference(cr, uid, 'product', 'product_uom_unit')[1] } + def create(self, cr, uid, values, context=None): + product_obj = self.pool.get('product.product') + dom = [('product_id', '=', values.get('product_id')), ('inventory_id.state', '=', 'confirm'), + ('location_id', '=', values.get('location_id')), ('partner_id', '=', values.get('partner_id')), + ('package_id', '=', values.get('package_id')), ('prod_lot_id', '=', values.get('prod_lot_id'))] + res = self.search(cr, uid, dom, context=context) + if res: + location = self.pool['stock.location'].browse(cr, uid, values.get('location_id'), context=context) + product = product_obj.browse(cr, uid, values.get('product_id'), context=context) + raise Warning(_("You cannot have two inventory adjustements in state 'in Progess' with the same product(%s), same location(%s), same package, same owner and same lot. Please first validate the first inventory adjustement with this product before creating another one.") % (product.name, location.name)) + return super(stock_inventory_line, self).create(cr, uid, values, context=context) + def _get_quants(self, cr, uid, line, context=None): quant_obj = self.pool["stock.quant"] dom = [('company_id', '=', line.company_id.id), ('location_id', '=', line.location_id.id), ('lot_id', '=', line.prod_lot_id.id),