From 287b293283ccab16cc0f692a109738217b47ed53 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 25 Mar 2015 12:38:16 +0100 Subject: [PATCH] [FIX] stock_account: valuation entry for reconciled neg quant not always possible Skip the creation of the corrective valuation entry when a negative quant is reconciled with an incoming shipment, when: - the cost has not changed, so the journal entry would be useless (credit/debit = 0) - or, when the accounting period for the move causing the negative quant is already closed, and must not be updated (presumably the valuation was manually set before closing that period) --- addons/stock_account/stock_account.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py index 2fcc661c079..7ff3f3001b8 100644 --- a/addons/stock_account/stock_account.py +++ b/addons/stock_account/stock_account.py @@ -79,13 +79,22 @@ class stock_quant(osv.osv): ''' if context is None: context = {} + account_period = self.pool['account.period'] super(stock_quant, self)._price_update(cr, uid, quant_ids, newprice, context=context) - ctx = context.copy() for quant in self.browse(cr, uid, quant_ids, context=context): move = self._get_latest_move(cr, uid, quant, context=context) - # 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) + valuation_update = newprice - quant.cost + # this is where we post accounting entries for adjustment, if needed + if not quant.company_id.currency_id.is_zero(valuation_update): + # adjustment journal entry needed, cost has been updated + period_id = (context.get('force_period') or + account_period.find(cr, uid, move.date, context=context)[0]) + period = account_period.browse(cr, uid, period_id, context=context) + # If neg quant period already closed (likely with manual valuation), skip update + if period.state != 'done': + ctx = dict(context, force_valuation_amount=valuation_update) + 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 #1) the product cost's method is 'real' #2) we just fixed a negative quant caused by an outgoing shipment