From 4adb7014bbcdcfc571e52530180f8f2794250826 Mon Sep 17 00:00:00 2001 From: "Djamel (otd)" Date: Tue, 1 Jun 2021 12:53:10 +0000 Subject: [PATCH] =?UTF-8?q?[FIX]=20stock=5Faccount:=20use=20=E2=80=9Caccou?= =?UTF-8?q?nt=5Fjournal=5Fid=E2=80=9D=20only=20if=20the=20valuation=20is?= =?UTF-8?q?=20real=5Ftime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Go to inventory > create a new product -Create a new product category: * Select "Manual" inventory Valuation * Choose "First In First Out (FIFO)" costing Method * Be sure that in "Automated" inventory valuation, stock journal is not settled - Save - Update quantity of the product - Go to Inventory > Inventory Valuation> Choose the product newly created - Click on the "+" button to make manual valuation Problem: An error is triggered because we try to access stock_journal when it is false. Solution: Use “account_journal_id” only if the valuation is real_time and relax the required constraint of `account_journal_id` in case of manual inventory Valuation (which is not used in that case). Opw-2541497 closes odoo/odoo#71660 X-original-commit: 421271934c3eed43d2edcb410d3d75757c1fb81b Signed-off-by: William Henrotin --- .../wizard/stock_valuation_layer_revaluation.py | 6 +++--- .../wizard/stock_valuation_layer_revaluation_views.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/stock_account/wizard/stock_valuation_layer_revaluation.py b/addons/stock_account/wizard/stock_valuation_layer_revaluation.py index 01ac9371a3c..f56a20da2a4 100644 --- a/addons/stock_account/wizard/stock_valuation_layer_revaluation.py +++ b/addons/stock_account/wizard/stock_valuation_layer_revaluation.py @@ -16,12 +16,12 @@ class StockValuationLayerRevaluation(models.TransientModel): res = super().default_get(default_fields) if res.get('product_id'): product = self.env['product.product'].browse(res['product_id']) - accounts = product.product_tmpl_id.get_product_accounts() if product.categ_id.property_cost_method == 'standard': raise UserError(_("You cannot revalue a product with a standard cost method.")) if product.quantity_svl <= 0: raise UserError(_("You cannot revalue a product with an empty or negative stock.")) - if 'account_journal_id' not in res and 'account_journal_id' in default_fields: + if 'account_journal_id' not in res and 'account_journal_id' in default_fields and product.categ_id.property_valuation == 'real_time': + accounts = product.product_tmpl_id.get_product_accounts() res['account_journal_id'] = accounts['stock_journal'].id return res @@ -39,7 +39,7 @@ class StockValuationLayerRevaluation(models.TransientModel): new_value_by_qty = fields.Monetary("New value by quantity", compute='_compute_new_value') reason = fields.Char("Reason", help="Reason of the revaluation") - account_journal_id = fields.Many2one('account.journal', "Journal", required=True, check_company=True) + account_journal_id = fields.Many2one('account.journal', "Journal", check_company=True) account_id = fields.Many2one('account.account', "Counterpart Account", domain=[('deprecated', '=', False)], check_company=True) date = fields.Date("Accounting Date") diff --git a/addons/stock_account/wizard/stock_valuation_layer_revaluation_views.xml b/addons/stock_account/wizard/stock_valuation_layer_revaluation_views.xml index f35f3dde560..c867b84b585 100644 --- a/addons/stock_account/wizard/stock_valuation_layer_revaluation_views.xml +++ b/addons/stock_account/wizard/stock_valuation_layer_revaluation_views.xml @@ -25,7 +25,7 @@ - +