Commit b0febdde authored by Jérome Perrin's avatar Jérome Perrin

accounting: in select fields display which organisation bank accounts belongs to

parent cdb92e87
...@@ -48,19 +48,36 @@ else: ...@@ -48,19 +48,36 @@ else:
item_list = [('', '')] item_list = [('', '')]
for bank in bank_account_list:
bank = bank.getObject()
# If we have bank accounts from more than one organisation, include
# the organisation as hierarchy to show which organisation the bank
# account belongs to.
include_organisation_hierarchy = len(set(
['/'.join(b.path.split('/')[:-1]) for b in bank_account_list])) > 1
previous_organisation = None
# sort bank accounts in a way that bank accounts from the same
# organisation are consecutive
for brain in sorted(bank_account_list, key=lambda b:b.path):
bank = brain.getObject()
if include_organisation_hierarchy:
organisation = bank.getParentValue()
if organisation != previous_organisation:
previous_organisation = organisation
# include non-selectable element to show hierarchy
item_list.append((organisation.getTranslatedTitle(), None))
if bank.getReference() and bank.getTitle() \ if bank.getReference() and bank.getTitle() \
and bank.getReference() != bank.getTitle(): and bank.getReference() != bank.getTitle():
item_list.append(('%s - %s' % ( bank.getReference(), item_list.append(('%s - %s' % ( bank.getReference(),
bank.getTitle() or bank.getTitle() or
bank.getSourceFreeText() or bank.getSourceFreeText() or
bank.getSourceTitle()), bank.getSourceTitle()),
bank.getRelativeUrl())) bank.getRelativeUrl()))
else: else:
item_list.append(( bank.getReference() or item_list.append(( bank.getReference() or
bank.getTitle() or bank.getTitle() or
bank.getSourceFreeText() or bank.getSourceFreeText() or
bank.getSourceTitle(), bank.getSourceTitle(),
bank.getRelativeUrl() )) bank.getRelativeUrl() ))
......
...@@ -4354,6 +4354,17 @@ class TestTransactions(AccountingTestCase): ...@@ -4354,6 +4354,17 @@ class TestTransactions(AccountingTestCase):
('from section', bank_account.getRelativeUrl()), ('from section', bank_account.getRelativeUrl()),
source_transaction.AccountingTransaction_getSourcePaymentItemList()) source_transaction.AccountingTransaction_getSourcePaymentItemList())
# We include non selectable elements in the drop down to show which to which organisation
# the bank account belongs to.
self.assertEqual(
[('', ''),
(self.main_section.getTitle(), None),
('from main section', parent_bank_account.getRelativeUrl()),
(self.section.getTitle(), None),
('from section', bank_account.getRelativeUrl()),
],
source_transaction.AccountingTransaction_getSourcePaymentItemList())
destination_transaction = self._makeOne( destination_transaction = self._makeOne(
portal_type='Payment Transaction', portal_type='Payment Transaction',
destination_section_value=self.section, destination_section_value=self.section,
...@@ -4369,6 +4380,29 @@ class TestTransactions(AccountingTestCase): ...@@ -4369,6 +4380,29 @@ class TestTransactions(AccountingTestCase):
('from section', bank_account.getRelativeUrl()), ('from section', bank_account.getRelativeUrl()),
destination_transaction.AccountingTransaction_getDestinationPaymentItemList()) destination_transaction.AccountingTransaction_getDestinationPaymentItemList())
main_section_transaction = self._makeOne(
portal_type='Payment Transaction',
source_section_value=self.main_section,
destination_section_value=self.organisation_module.client_1,
lines=(dict(source_value=self.account_module.goods_purchase,
source_debit=500),
dict(source_value=self.account_module.receivable,
source_credit=500)))
self.assertIn(
('from main section', parent_bank_account.getRelativeUrl()),
main_section_transaction.AccountingTransaction_getSourcePaymentItemList())
self.assertNotIn(
('from section', bank_account.getRelativeUrl()),
main_section_transaction.AccountingTransaction_getSourcePaymentItemList())
# We don't have this non selectable element when all bank accounts are from
# the same organisation
self.assertEqual(
[('', ''),
('from main section', parent_bank_account.getRelativeUrl()),
],
main_section_transaction.AccountingTransaction_getSourcePaymentItemList())
def test_AccountingTransaction_getSourcePaymentItemList_parent_section_with_accounting_period(self): def test_AccountingTransaction_getSourcePaymentItemList_parent_section_with_accounting_period(self):
# AccountingTransaction_getSourcePaymentItemList and AccountingTransaction_getDestinationPaymentItemList # AccountingTransaction_getSourcePaymentItemList and AccountingTransaction_getDestinationPaymentItemList
# allows to select bank accounts from parent groups of source section, but not if # allows to select bank accounts from parent groups of source section, but not if
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment