Restrict updating party required of account with moves

Closes #14710
This commit is contained in:
Sergi Almacellas Abellana
2026-08-17 23:31:29 +02:00
parent 69c8e681ba
commit 90daf2e88b
2 changed files with 23 additions and 0 deletions
+20
View File
@@ -1422,6 +1422,26 @@ class Account(
}),
]
@classmethod
def check_modification(cls, mode, accounts, values=None, external=False):
pool = Pool()
MoveLine = pool.get('account.move.line')
super().check_modification(
mode, accounts, values=values, external=external)
# Only external to allow update from template
if mode == 'write' and external and 'party_required' in values:
if to_check := [
a.id for a in accounts
if a.party_required != values['party_required']]:
if lines := MoveLine.search([
('account', 'in', to_check),
],
limit=1, order=[]):
line, = lines
raise AccessError(gettext(
'account.msg_account_party_required_with_moves',
account=line.account.rec_name))
class AccountParty(ActivePeriodMixin, ModelSQL):
__name__ = 'account.account.party'
+3
View File
@@ -110,6 +110,9 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_account_no_type_lines">
<field name="text">You cannot remove type of account "%(account)s" because it has move lines.</field>
</record>
<record model="ir.message" id="msg_account_party_required_with_moves">
<field name="text">You cannot change the "Party Required" field of account "%(account)s" because it contains lines.</field>
</record>
<record model="ir.message" id="msg_deferral_unique">
<field name="text">Deferral must be unique by account and fiscal year.</field>