From 2c0cae221a24c003a3572a2c5780204b8d30ca55 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 19 Aug 2016 14:52:21 +0200 Subject: [PATCH] [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 --- addons/stock_account/stock_account.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py index 13378669dc1..4b9d5c8a843 100644 --- a/addons/stock_account/stock_account.py +++ b/addons/stock_account/stock_account.py @@ -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)