[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
This commit is contained in:
Goffin Simon 2016-01-29 12:25:30 +01:00
parent edeb5a8c0f
commit bafa1a677e
2 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -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),