From faca1dd1872eee7ad26584996cc87aa671eee4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 24 Mar 2025 18:44:31 +0100 Subject: [PATCH] Order bank account per owners Closes #13937 --- modules/bank/CHANGELOG | 1 + modules/bank/bank.py | 13 ++++++++++++- modules/bank/bank.xml | 7 +++++++ modules/bank/party.py | 12 ++++++++++-- modules/bank/view/bank_account_form.xml | 4 ++++ .../bank/view/bank_account_list_owners_sequence.xml | 8 ++++++++ modules/bank/view/party_form.xml | 2 +- 7 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 modules/bank/view/bank_account_list_owners_sequence.xml diff --git a/modules/bank/CHANGELOG b/modules/bank/CHANGELOG index 975f31bb7d..b166d51586 100644 --- a/modules/bank/CHANGELOG +++ b/modules/bank/CHANGELOG @@ -1,3 +1,4 @@ +* Order account per owners * Remove support for Python 3.8 * Add support for Python 3.13 diff --git a/modules/bank/bank.py b/modules/bank/bank.py index 0d57eef79b..7e9bb5ee0a 100644 --- a/modules/bank/bank.py +++ b/modules/bank/bank.py @@ -12,7 +12,8 @@ except ImportError: from trytond.i18n import gettext from trytond.model import ( - DeactivableMixin, Exclude, ModelSQL, ModelView, fields, sequence_ordered) + DeactivableMixin, Exclude, Index, ModelSQL, ModelView, fields, + sequence_ordered) from trytond.pool import Pool from trytond.pyson import Eval, If from trytond.tools import is_full_text, lstrip_wildcard @@ -93,6 +94,7 @@ class Account(DeactivableMixin, ModelSQL, ModelView): help="The bank where the account is open.") owners = fields.Many2Many('bank.account-party.party', 'account', 'owner', 'Owners') + owners_sequence = fields.Integer("Owners Sequence") currency = fields.Many2One('currency.currency', 'Currency') numbers = fields.One2Many( 'bank.account.number', 'account', 'Numbers', @@ -101,6 +103,15 @@ class Account(DeactivableMixin, ModelSQL, ModelView): ], help="Add the numbers which identify the bank account.") + @classmethod + def __setup__(cls): + super().__setup__() + table = cls.__table__() + cls._sql_indexes.add( + Index(table, + (table.owners_sequence, Index.Range(order='ASC NULLS FIRST')), + (table.id, Index.Range(order='ASC')))) + def get_rec_name(self, name): for number in self.numbers: if number.number: diff --git a/modules/bank/bank.xml b/modules/bank/bank.xml index 00c825f8fe..ddd40e9f62 100644 --- a/modules/bank/bank.xml +++ b/modules/bank/bank.xml @@ -78,8 +78,15 @@ this repository contains the full copyright notices and license terms. --> bank.account tree + bank_account_list + + bank.account + tree + + bank_account_list_owners_sequence + Accounts diff --git a/modules/bank/party.py b/modules/bank/party.py index 32a19d50e8..e2e498a592 100644 --- a/modules/bank/party.py +++ b/modules/bank/party.py @@ -8,10 +8,18 @@ from trytond.transaction import Transaction class Party(metaclass=PoolMeta): __name__ = 'party.party' bank_accounts = fields.Many2Many( - 'bank.account-party.party', 'owner', 'account', "Bank Accounts") + 'bank.account-party.party', 'owner', 'account', "Bank Accounts", + order=[ + ('account.owners_sequence', 'ASC NULLS FIRST'), + ('account.id', 'ASC'), + ]) bank_accounts_used = fields.Many2Many( 'bank.account-party.party', 'owner', 'account', "Bank Accounts Used", - filter=[('active', '=', True)]) + filter=[('active', '=', True)], + order=[ + ('account.owners_sequence', 'ASC NULLS FIRST'), + ('account.id', 'ASC'), + ]) @classmethod def search_rec_name(cls, name, clause): diff --git a/modules/bank/view/bank_account_form.xml b/modules/bank/view/bank_account_form.xml index 37d9bc02ef..3df419e1a6 100644 --- a/modules/bank/view/bank_account_form.xml +++ b/modules/bank/view/bank_account_form.xml @@ -8,7 +8,11 @@ this repository contains the full copyright notices and license terms. -->