[FIX] stock_account: raise error when valuation is zero

Commit ddbe0e1 introduces an error when the user tries to move a product
with a cost of zero. In extreme case, this is incompatible with commit
262d98b. For example, if one buys 10000 units for 17.60, and consumes one
unit at a time. The latter commit will split the quants in:
- 9999 quants at cost zero
- 1 quant at cost 17.60
This is the only solution to get a correct accounting.

However, that creates quants with a cost of zero, which therefore cannot
be moved anymore (consumed in MRP or sold).

We restrict the warning to products configured with "Standard Price".
Indeed, in this configuration, it is very lokely that the user made a
mistake / forgot to define the price of the product.

opw-686301
This commit is contained in:
Nicolas Martinelli
2016-08-22 08:22:08 +02:00
parent 43aee6db75
commit 2c0cae221a
+11 -7
View File
@@ -325,7 +325,10 @@ class stock_quant(osv.osv):
valuation_amount = currency_obj.round(cr, uid, move.company_id.currency_id, valuation_amount * qty)
#check that all data is correct
if move.company_id.currency_id.is_zero(valuation_amount):
raise UserError(_("The found valuation amount for product %s is zero. Which means there is probably a configuration error. Check the costing method and the standard price") % (move.product_id.name,))
if move.product_id.cost_method == 'standard':
raise UserError(_("The found valuation amount for product %s is zero. Which means there is probably a configuration error. Check the costing method and the standard price") % (move.product_id.name,))
else:
return []
partner_id = (move.picking_id.partner_id and self.pool.get('res.partner')._find_accounting_partner(move.picking_id.partner_id).id) or False
debit_line_vals = {
'name': move.name,
@@ -362,12 +365,13 @@ class stock_quant(osv.osv):
move_obj = self.pool.get('account.move')
for cost, qty in quant_cost_qty.items():
move_lines = self._prepare_account_move_line(cr, uid, move, qty, cost, credit_account_id, debit_account_id, context=context)
date = context.get('force_period_date', fields.date.context_today(self, cr, uid, context=context))
new_move = move_obj.create(cr, uid, {'journal_id': journal_id,
'line_ids': move_lines,
'date': date,
'ref': move.picking_id.name}, context=context)
move_obj.post(cr, uid, [new_move], context=context)
if move_lines:
date = context.get('force_period_date', fields.date.context_today(self, cr, uid, context=context))
new_move = move_obj.create(cr, uid, {'journal_id': journal_id,
'line_ids': move_lines,
'date': date,
'ref': move.picking_id.name}, context=context)
move_obj.post(cr, uid, [new_move], context=context)
#def _reconcile_single_negative_quant(self, cr, uid, to_solve_quant, quant, quant_neg, qty, context=None):
# move = self._get_latest_move(cr, uid, to_solve_quant, context=context)