Commit ea3937c9 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kazuhiko Shiozaki

accounting: support passing a person in AccountModule_getBankAccountItemList

The parameter is still named `organisation` for "API stability", but
this parameter can be a person.

This was already used by the fields on accounting transaction for
source/destination_payment and more or less working already, except
for the case where the person had a subordination to an organisation
member of the group, in that case instead of showing the bank accounts
from the person this was showing the bank accounts from the
organisation
parent 4fbaf7c9
......@@ -2,12 +2,15 @@
If `organisation` is passed, then we only show bank accounts available for that
organisation, using the following policy:
- if organisation is independent accounting entity (ie. have accounting periods),
only bank accounts from this organisation can be selected
only bank accounts from this organisation can be selected.
- otherwise, bank accounts from this organisation and all organisation directly
members of the parent groups can be us
members of the parent groups can be used
- if organisation higher in the group hierarchy contains bank accounts, bank
accounts from parent organisations can be selected
`organisation` can actually be a person or other portal types, in this case they
are assumed to be independent accounting entities.
If organisation is not passed, this script will return all bank accounts
applicable for section_category and section_category_strict_membership.
......@@ -16,21 +19,22 @@ base_category is anyway included.
"""
portal = context.getPortalObject()
search_kw = dict(
portal_type=portal.getPortalPaymentNodeTypeList(),
validation_state='validated',
)
if organisation:
organisation_value = portal.restrictedTraverse(organisation)
# if organisation is an independent accounting section and contains bank accounts,
entity_value = portal.restrictedTraverse(organisation)
# if entity is an independent accounting section and contains bank accounts,
# only take into account those.
if organisation_value == organisation_value.Organisation_getMappingRelatedOrganisation():
bank_account_list = organisation_value.searchFolder(**search_kw)
if entity_value.getPortalType() != 'Organisation' \
or entity_value == entity_value.Organisation_getMappingRelatedOrganisation():
bank_account_list = entity_value.searchFolder(**search_kw)
# else we lookup in organisations from parent groups.
else:
group_value = organisation_value.getGroupValue(None)
group_value = entity_value.getGroupValue(None)
if group_value is not None:
uid_list = []
while group_value.getPortalType() != 'Base Category':
......
......@@ -4666,6 +4666,36 @@ class TestTransactions(AccountingTestCase):
self.assertEqual(
at.AccountingTransaction_getDestinationPaymentItemList(), [('', '')])
def test_AccountingTransaction_getSourcePaymentItemList_person_member_of_group(self):
bank_account = self.main_section.newContent(
portal_type='Bank Account',
reference='should not be displayed'
)
bank_account.validate()
self.tic()
source_transaction = self._makeOne(
portal_type='Payment Transaction',
source_section_value=self.section,
destination_section_value=self.person_module.john_smith,
lines=(dict(source_value=self.account_module.goods_purchase,
source_debit=500),
dict(source_value=self.account_module.receivable,
source_credit=500)))
self.assertEqual(
source_transaction.AccountingTransaction_getSourcePaymentItemList(), [('', '')])
destination_transaction = self._makeOne(
portal_type='Payment Transaction',
destination_section_value=self.section,
source_section_value=self.person_module.john_smith,
lines=(dict(destination_value=self.account_module.goods_purchase,
destination_debit=500),
dict(destination_value=self.account_module.receivable,
destination_credit=500)))
self.assertEqual(
destination_transaction.AccountingTransaction_getDestinationPaymentItemList(), [('', '')])
def test_AccountingTransaction_getSourcePaymentItemList_parent_section(self):
# AccountingTransaction_getSourcePaymentItemList and AccountingTransaction_getDestinationPaymentItemList
# allows to select bank accounts from parent groups of source section
......
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