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