From 244c8ee6259fdb699b992996d8ef9ff82b3294b1 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Tue, 18 Nov 2014 16:38:21 +0100 Subject: [PATCH] [FIX] Propate propagated_from_id when reconciling negative quants to the quant that loses it When a negative quant is created but the positive quant counterpart is reconciling a negative quant that of course also has a positive counterpart, the latter should eventually let its field propagated_from_id tell that it originated from the very first negative quant as the second negative quant will have disappeared through reconciliation. --- addons/stock/stock.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 80a9aaf..cb690e8 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -550,10 +550,12 @@ class stock_quant(osv.osv): """ solving_quant = quant dom = [('qty', '<', 0)] + prod = quant.product_id.id if quant.lot_id: dom += [('lot_id', '=', quant.lot_id.id)] dom += [('owner_id', '=', quant.owner_id.id)] dom += [('package_id', '=', quant.package_id.id)] + dom += [('id', '!=', quant.propagated_from_id.id)] quants = self.quants_get(cr, uid, quant.location_id, quant.product_id, quant.qty, dom, context=context) product_uom_rounding = quant.product_id.uom_id.rounding for quant_neg, qty in quants: @@ -577,6 +579,8 @@ class stock_quant(osv.osv): remaining_to_solve_quant_ids = self.search(cr, uid, [('propagated_from_id', '=', quant_neg.id), ('id', 'not in', solved_quant_ids)], context=context) if remaining_to_solve_quant_ids: self.write(cr, SUPERUSER_ID, remaining_to_solve_quant_ids, {'propagated_from_id': remaining_neg_quant.id}, context=context) + if solving_quant.propagated_from_id: + self.write(cr, uid, solved_quant_ids, {'propagated_from_id': solving_quant.propagated_from_id.id}) #delete the reconciled quants, as it is replaced by the solved quants self.unlink(cr, SUPERUSER_ID, [quant_neg.id], context=context) #price update + accounting entries adjustments @@ -586,6 +590,8 @@ class stock_quant(osv.osv): self.unlink(cr, SUPERUSER_ID, [solving_quant.id], context=context) solving_quant = remaining_solving_quant + + def _price_update(self, cr, uid, ids, newprice, context=None): self.write(cr, SUPERUSER_ID, ids, {'cost': newprice}, context=context) -- 1.7.10.4