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

accounting: show the context when showing invalid bank accounts

parent 74a00c76
......@@ -17,6 +17,7 @@ applicable for section_category and section_category_strict_membership.
If `base_category` is passed, the currently linked bank account with the specified
base_category is anyway included.
"""
from Products.ERP5Type.Message import translateString
portal = context.getPortalObject()
......@@ -58,44 +59,45 @@ else:
item_list = [('', '')]
# If we have bank accounts from more than one organisation, include
# the organisation as hierarchy to show which organisation the bank
# If we have bank accounts from more than one entity, include
# the entity as hierarchy to show which entity the bank
# account belongs to.
include_organisation_hierarchy = len(set(
include_entity_hierarchy = len(set(
['/'.join(b.path.split('/')[:-1]) for b in bank_account_list])) > 1
bank_account_list = [brain.getObject() for brain in sorted(
bank_account_list, key=lambda b:b.path
)]
if base_category is not None:
current_value = context.getProperty(base_category + '_value')
if current_value not in bank_account_list:
bank_account_list.append(current_value)
previous_organisation = None
def getItemList(bank_account):
reference = bank_account.getReference()
title = bank_account.getTitle() or bank_account.getSourceFreeText() or bank_account.getSourceTitle()
label = title
if reference != title:
label = '{} - {}'.format(reference, title)
return (label, bank_account.getRelativeUrl())
previous_entity = None
# sort bank accounts in a way that bank accounts from the same
# organisation are consecutive
# entity are consecutive
for bank in bank_account_list:
if include_organisation_hierarchy:
organisation = bank.getParentValue()
if organisation != previous_organisation:
previous_organisation = organisation
if include_entity_hierarchy:
entity = bank.getParentValue()
if entity != previous_entity:
previous_entity = entity
# include non-selectable element to show hierarchy
item_list.append((organisation.getTranslatedTitle(), None))
if bank.getReference() and bank.getTitle() \
and bank.getReference() != bank.getTitle():
item_list.append(('%s - %s' % ( bank.getReference(),
bank.getTitle() or
bank.getSourceFreeText() or
bank.getSourceTitle()),
bank.getRelativeUrl()))
else:
item_list.append(( bank.getReference() or
bank.getTitle() or
bank.getSourceFreeText() or
bank.getSourceTitle(),
bank.getRelativeUrl() ))
item_list.append((entity.getTranslatedTitle(), None))
item_list.append(getItemList(bank))
if base_category is not None:
current_value = context.getProperty(base_category + '_value')
if current_value and current_value not in bank_account_list:
item_list.append((
translateString(
'Invalid bank account from ${entity_title}',
mapping={'entity_title': current_value.getParentTitle()}), None))
item_list.append(getItemList(current_value))
return item_list
......@@ -4835,6 +4835,63 @@ class TestTransactions(AccountingTestCase):
('from section', bank_account.getRelativeUrl()),
destination_transaction.AccountingTransaction_getDestinationPaymentItemList())
def test_AccountingTransaction_getSourcePaymentItemList_bank_accounts_from_other_entities(self):
client_1_bank_account = self.portal.organisation_module.client_1.newContent(
portal_type='Bank Account',
title='client_1 bank account'
)
client_1_bank_account.validate()
source_transaction = self._makeOne(
portal_type='Payment Transaction',
destination_section_value=self.section,
# section is client 2 but account is for client 1
source_section_value=self.organisation_module.client_2,
source_payment_value=client_1_bank_account,
lines=(
dict(
destination_value=self.account_module.goods_purchase,
destination_debit=500),
dict(
destination_value=self.account_module.receivable,
destination_credit=500)))
self.assertEqual(
[
(str(label), value) for (label, value) in
source_transaction.AccountingTransaction_getSourcePaymentItemList()
],
[
('', ''),
('Invalid bank account from Client 1', None),
('client_1 bank account', client_1_bank_account.getRelativeUrl()),
],
)
destination_transaction = self._makeOne(
portal_type='Payment Transaction',
source_section_value=self.section,
# section is client 2 but account is for client 1
destination_section_value=self.organisation_module.client_2,
destination_payment_value=client_1_bank_account,
lines=(
dict(
destination_value=self.account_module.goods_purchase,
destination_debit=500),
dict(
destination_value=self.account_module.receivable,
destination_credit=500)))
self.assertEqual(
[
(str(label), value) for (label, value) in destination_transaction.
AccountingTransaction_getDestinationPaymentItemList()
],
[
('', ''),
('Invalid bank account from Client 1', None),
('client_1 bank account', client_1_bank_account.getRelativeUrl()),
],
)
class TestAccountingWithSequences(ERP5TypeTestCase):
"""The first test for Accounting
......
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