From 0c26d6598006b8b1e4654645a81d1fbbf592bcde Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Mon, 22 Jul 2019 08:38:58 +0000 Subject: [PATCH] [FIX] stock_account: traceback when create quant How to reproduce: - Active multilocation in inventory setting; - Go on product form view; - Click on Update Quantity / On Hand button; - Create a new quant. With stock_account, we encounter a traceback when creating a new quant in some case where the `location_id` isn't set by default, because it tries to compute the value and it checks location to know if the quant must be valueted or not. Task #2039731 --- addons/stock_account/models/stock_quant.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/stock_quant.py b/addons/stock_account/models/stock_quant.py index 7d537a7b986..8226d1c8cce 100644 --- a/addons/stock_account/models/stock_quant.py +++ b/addons/stock_account/models/stock_quant.py @@ -11,7 +11,7 @@ class StockQuant(models.Model): value = fields.Monetary('Value', compute='_compute_value', groups='stock.group_stock_manager') currency_id = fields.Many2one(related='product_id.currency_id', groups='stock.group_stock_manager') - @api.depends('quantity') + @api.depends('company_id', 'location_id', 'owner_id', 'product_id', 'quantity') def _compute_value(self): """ For standard and AVCO valuation, compute the current accounting valuation of the quants by multiplying the quantity by @@ -21,6 +21,11 @@ class StockQuant(models.Model): a estimation more than a real value). """ for quant in self: + # If the user didn't enter a location yet while enconding a quant. + if not quant.location_id: + quant.value = 0 + return + if not quant.location_id._should_be_valued() or\ (quant.owner_id and quant.owner_id != quant.company_id.partner_id): quant.value = 0