[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) <bib@odoo.com>
Signed-off-by: Nicolas Viseur (vin) <vin@odoo.com>
This commit is contained in:
Nicolas Viseur (vin)
2023-12-22 02:53:07 +00:00
parent 80db9716d3
commit cfa987933c
2 changed files with 11 additions and 1 deletions
+9 -1
View File
@@ -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'):
@@ -18,10 +18,12 @@
<xpath expr="//field[@name='acc_number']" position="attributes">
<attribute name="readonly">lock_trust_fields</attribute>
<attribute name="force_save">1</attribute>
</xpath>
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="readonly">lock_trust_fields</attribute>
<attribute name="force_save">1</attribute>
</xpath>
<xpath expr="//field[@name='allow_out_payment']" position="replace">