[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)
This commit is contained in:
parent
f090652c99
commit
287b293283
|
@ -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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue