From 69fa111e95f1697a007aae8be32fe51188789da2 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 13 Jul 2017 12:50:30 +0200 Subject: [PATCH] [FIX] stock_account: negative quant cost - Set up a product with 'Real Price' costing method, in real time valuation - Receive 1000 units at $0.10 each - Create a landed cost of $456.70, validate => it creates a quants of 999 units at cost $0.56 and 1 unit at cost $-2.74. - Perform an inventory adjustment, and set the quantity to 0 instead of 1000, post inventory. An error arises due to the constrain debit + credit >= 0. This is caused by the method `_prepare_account_move_line` from `stock.move`, which cannot handle negative cost for quants. opw-752063 Fixes #17707 --- addons/stock_account/models/stock.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py index 074a0ab748d..f6045aa6353 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -312,8 +312,8 @@ class StockMove(models.Model): 'product_uom_id': self.product_id.uom_id.id, 'ref': self.picking_id.name, 'partner_id': partner_id, - 'debit': debit_value, - 'credit': 0, + 'debit': debit_value if debit_value > 0 else 0, + 'credit': -debit_value if debit_value < 0 else 0, 'account_id': debit_account_id, } credit_line_vals = { @@ -323,8 +323,8 @@ class StockMove(models.Model): 'product_uom_id': self.product_id.uom_id.id, 'ref': self.picking_id.name, 'partner_id': partner_id, - 'credit': credit_value, - 'debit': 0, + 'credit': credit_value if credit_value > 0 else 0, + 'debit': -credit_value if credit_value < 0 else 0, 'account_id': credit_account_id, } res = [(0, 0, debit_line_vals), (0, 0, credit_line_vals)]