From 61231577a27f046d707b4f1763c44a17bfec54e6 Mon Sep 17 00:00:00 2001 From: "lase@odoo.com" Date: Fri, 29 Mar 2024 15:39:15 +0100 Subject: [PATCH] [FIX] account: assign a vehicle to a posted journal entry steps to reproduce: - Go to Accounting > Accounting > Actions > Lock Dates - Set a Tax Return Lock Date to a date of the previous month - Create and confirm vendor Bill with a taxed line of positive price - Go to Accounting > Reporting > Audit Reports > Journal Report - Hover over the Vendor Bills and click on "journal items" - Add the optional vehicle field to the recods - Select your expense line and try to add a vehicle > Invalid Operation "You cannot modify the taxes related to a posted journal item..." Cause of the issue: Modifying the "vehicle_id" of the account move line will trigger a call of the `_sync_dynamic_line` method in order to modify other account move line linked to the same account move: https://github.com/odoo/odoo/blob/6a4808802c67f98696338d0b6f6a07934c8003fb/addons/account/models/account_move.py#L2285-L2287 During the call of this write method, the account move line that we did not directly modified will not be excluded: https://github.com/odoo/odoo/blob/6a4808802c67f98696338d0b6f6a07934c8003fb/addons/account/models/account_move_line.py#L1571 as `..._field_will_change(line, vals,"vehicule_id")` will be `True`. The error will therefore be raised two lines later because a 'tax_id' is present in vals as a 'tax_id' was set on our related account move line. Expected behaviour: Since the 'tax_id' present in vals is the same as the one already set on our account move line, we are not modifying the taxes related to a posted journal item and we should not raise the error. opw-3810718 closes odoo/odoo#161387 X-original-commit: 3cd87c61c852eef96195a39a4011a6baa39e3078 Signed-off-by: Claire Bretton (clbr) --- addons/account/models/account_move_line.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 852cb43fa42..3f3a68443c6 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -1572,9 +1572,8 @@ class AccountMoveLine(models.Model): line_to_write -= line continue - if line.parent_state == 'posted': - if any(key in vals for key in ('tax_ids', 'tax_line_id')): - raise UserError(_('You cannot modify the taxes related to a posted journal item, you should reset the journal entry to draft to do so.')) + if line.parent_state == 'posted' and any(self.env['account.move']._field_will_change(line, vals, field_name) for field_name in ('tax_ids', 'tax_line_id')): + raise UserError(_('You cannot modify the taxes related to a posted journal item, you should reset the journal entry to draft to do so.')) # Check the lock date. if line.parent_state == 'posted' and any(self.env['account.move']._field_will_change(line, vals, field_name) for field_name in protected_fields['fiscal']):