From cfa987933c6f91573e8ead8428c2beb531e73f4b Mon Sep 17 00:00:00 2001 From: "Nicolas Viseur (vin)" Date: Thu, 21 Dec 2023 08:56:16 +0000 Subject: [PATCH] [FIX] account: trusted account lock Fix a small issue with the trusted account lock system, where we would raise an error when you change the partner or account number on a record at the same time as you untrust it. Before this fix it would be blocked, and you would need to untrust, save, and then redo the change in a second edition for it to work. At the same time, we will allow the process to untrust an account and change values at the same time. Task id #3647635 closes odoo/odoo#147089 X-original-commit: 3815ccea98c95130a770772aa29c87112e695914 Signed-off-by: Brice Bartoletti (bib) Signed-off-by: Nicolas Viseur (vin) --- addons/account/models/res_partner_bank.py | 10 +++++++++- addons/account/views/res_partner_bank_views.xml | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/account/models/res_partner_bank.py b/addons/account/models/res_partner_bank.py index f059b134e16..0a20ef3680a 100644 --- a/addons/account/models/res_partner_bank.py +++ b/addons/account/models/res_partner_bank.py @@ -279,7 +279,15 @@ class ResPartnerBank(models.Model): # Some fields should not be editable based on conditions. It is enforced in the view, but not in python which # leaves them vulnerable to edits via the shell/... So we need to ensure that the user has the rights to edit # these fields when writing too. - if ('acc_number' in vals or 'partner_id' in vals) and any(account.lock_trust_fields for account in self): + # While we do lock changes if the account is trusted, we still want to allow to change them if we go from not trusted -> trusted or from trusted -> not trusted. + any_trusted_accounts = any(account.lock_trust_fields for account in self) + if not any_trusted_accounts: + should_allow_changes = True # If we were on a non-trusted account, we will allow to change (setting/... one last time before trusting) + else: + # If we were on a trusted account, we only allow changes if the account is moving to untrusted. + should_allow_changes = ('allow_out_payment' in vals and vals['allow_out_payment'] is False) + + if ('acc_number' in vals or 'partner_id' in vals) and not should_allow_changes: raise UserError(_("You cannot modify the account number or partner of an account that has been trusted.")) if 'allow_out_payment' in vals and not self.user_has_groups('account.group_validate_bank_account'): diff --git a/addons/account/views/res_partner_bank_views.xml b/addons/account/views/res_partner_bank_views.xml index f8c7383d306..e0a398f85ce 100644 --- a/addons/account/views/res_partner_bank_views.xml +++ b/addons/account/views/res_partner_bank_views.xml @@ -18,10 +18,12 @@ lock_trust_fields + 1 lock_trust_fields + 1