[FIX] stock: fixing product cost price updates in case of negative quants

bzr revid: qdp-launchpad@openerp.com-20130924124906-gdmnzv85hnjrtqgb
This commit is contained in:
Quentin (OpenERP) 2013-09-24 14:49:06 +02:00
parent 856b4a284e
commit 434838b9a5
2 changed files with 9 additions and 7 deletions

View File

@ -366,8 +366,6 @@ class stock_quant(osv.osv):
solved_quant_ids.append(to_solve_quant.id) solved_quant_ids.append(to_solve_quant.id)
self._quant_split(cr, uid, to_solve_quant, min(solving_qty, to_solve_quant.qty), context=context) self._quant_split(cr, uid, to_solve_quant, min(solving_qty, to_solve_quant.qty), context=context)
solving_qty -= min(solving_qty, to_solve_quant.qty) solving_qty -= min(solving_qty, to_solve_quant.qty)
#merge history (and cost?)
self._quants_merge(cr, uid, solved_quant_ids, solving_quant, context=context)
remaining_solving_quant = self._quant_split(cr, uid, solving_quant, qty, context=context) remaining_solving_quant = self._quant_split(cr, uid, solving_quant, qty, context=context)
remaining_neg_quant = self._quant_split(cr, uid, quant_neg, -qty, context=context) remaining_neg_quant = self._quant_split(cr, uid, quant_neg, -qty, context=context)
#if the reconciliation was not complete, we need to link together the remaining parts #if the reconciliation was not complete, we need to link together the remaining parts
@ -375,11 +373,13 @@ 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) 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: if remaining_to_solve_quant_ids:
self.write(cr, uid, remaining_to_solve_quant_ids, {'propagated_from_id': remaining_neg_quant.id}, context=context) self.write(cr, uid, remaining_to_solve_quant_ids, {'propagated_from_id': remaining_neg_quant.id}, context=context)
quant_cost = solving_quant.cost #delete the reconciled quants, as it is replaced by the solved quants
#delete the reconciled quants, as it is replaced by the solving quant self.unlink(cr, SUPERUSER_ID, [quant_neg.id], context=context)
self.unlink(cr, SUPERUSER_ID, [quant_neg.id, solving_quant.id], context=context)
#price update + accounting entries adjustments #price update + accounting entries adjustments
self._price_update(cr, uid, solved_quant_ids, quant_cost, context=context) self._price_update(cr, uid, solved_quant_ids, solving_quant.cost, context=context)
#merge history (and cost?)
self._quants_merge(cr, uid, solved_quant_ids, solving_quant, context=context)
self.unlink(cr, SUPERUSER_ID, [solving_quant.id], context=context)
solving_quant = remaining_solving_quant solving_quant = remaining_solving_quant
#solving_quant, dummy = self._reconcile_single_negative_quant(cr, uid, to_solve_quant, solving_quant, quant_neg, qty, context=context) #solving_quant, dummy = self._reconcile_single_negative_quant(cr, uid, to_solve_quant, solving_quant, quant_neg, qty, context=context)

View File

@ -60,14 +60,16 @@ class stock_quant(osv.osv):
return super(stock_quant, self)._get_inventory_value(cr, uid, line, prodbrow, context=context) return super(stock_quant, self)._get_inventory_value(cr, uid, line, prodbrow, context=context)
def _price_update(self, cr, uid, quant_ids, newprice, context=None): def _price_update(self, cr, uid, quant_ids, newprice, context=None):
''' This function is called at the end of negative quant reconciliation and does the accounting entries adjustemnts and the update of the product cost price if needed
'''
if context is None: if context is None:
context = {} context = {}
super(stock_quant, self)._price_update(cr, uid, quant_ids, newprice, context=context) super(stock_quant, self)._price_update(cr, uid, quant_ids, newprice, context=context)
ctx = context.copy() ctx = context.copy()
for quant in self.browse(cr, uid, quant_ids, context=context): for quant in self.browse(cr, uid, quant_ids, context=context):
move = self._get_latest_move(cr, uid, quant, context=context) move = self._get_latest_move(cr, uid, quant, context=context)
ctx['force_valuation_amount'] = newprice - quant.cost
# this is where we post accounting entries for adjustment # this is where we post accounting entries for adjustment
ctx['force_valuation_amount'] = newprice - quant.cost
self._account_entry_move(cr, uid, quant, move, context=ctx) self._account_entry_move(cr, uid, quant, move, context=ctx)
#update the standard price of the product, only if we would have done it if we'd have had enough stock at first, which means #update the standard price of the product, only if we would have done it if we'd have had enough stock at first, which means
#1) the product cost's method is 'real' #1) the product cost's method is 'real'