From eccf8ab4e5d5d024701eafc9b4441f222be79d87 Mon Sep 17 00:00:00 2001 From: Ahmed Khalaf Date: Tue, 11 Oct 2022 13:11:02 +0000 Subject: [PATCH] [FIX] stock_account, purchase_stock: bill price change fix Before this commit, if a user creates a bill from a PO and confirms it. A stock valuation layer is created. if the user sets the bill to drafts and changes the product price. a new layer corrects the difference. if the user does it again, the new layer ignores the previous correction layers, resulting in wrong valuation. This commit hides the 'Reset to Draft' button when there are correction layers found. closes odoo/odoo#103347 X-original-commit: d3d41c7679f9068a7b986925b15d0d7670233bfc Signed-off-by: Arnold Moyaux (arm) --- addons/stock_account/models/account_move.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index 65e8c3ad7ec..5a581755fa8 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -11,6 +11,15 @@ class AccountMove(models.Model): stock_move_id = fields.Many2one('stock.move', string='Stock Move', index='btree_not_null') stock_valuation_layer_ids = fields.One2many('stock.valuation.layer', 'account_move_id', string='Stock Valuation Layer') + def _compute_show_reset_to_draft_button(self): + for move in self: + for line in move.line_ids: + # if a line has correction layers hide the 'Reset to Darft' button + if line._get_stock_valuation_layers(move).stock_valuation_layer_ids.filtered('account_move_line_id'): + move.show_reset_to_draft_button = False + return + super()._compute_show_reset_to_draft_button() + # ------------------------------------------------------------------------- # OVERRIDE METHODS # ------------------------------------------------------------------------- @@ -293,7 +302,6 @@ class AccountMoveLine(models.Model): price_unit /= prec layers_price_unit = line._get_stock_valuation_layers_price_unit(layers) layers_to_correct = line._get_stock_layer_price_difference(layers, layers_price_unit, price_unit) - svl_vals_list += line._prepare_in_invoice_svl_vals(layers_to_correct) return self.env['stock.valuation.layer'].sudo().create(svl_vals_list)