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 @@ ...@@ -2,12 +2,15 @@
If `organisation` is passed, then we only show bank accounts available for that If `organisation` is passed, then we only show bank accounts available for that
organisation, using the following policy: organisation, using the following policy:
- if organisation is independent accounting entity (ie. have accounting periods), - 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 - 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 - if organisation higher in the group hierarchy contains bank accounts, bank
accounts from parent organisations can be selected 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 If organisation is not passed, this script will return all bank accounts
applicable for section_category and section_category_strict_membership. applicable for section_category and section_category_strict_membership.
...@@ -16,21 +19,22 @@ base_category is anyway included. ...@@ -16,21 +19,22 @@ base_category is anyway included.
""" """
portal = context.getPortalObject() portal = context.getPortalObject()
search_kw = dict( search_kw = dict(
portal_type=portal.getPortalPaymentNodeTypeList(), portal_type=portal.getPortalPaymentNodeTypeList(),
validation_state='validated', validation_state='validated',
) )
if organisation: if organisation:
organisation_value = portal.restrictedTraverse(organisation) entity_value = portal.restrictedTraverse(organisation)
# if entity is an independent accounting section and contains bank accounts,
# if organisation is an independent accounting section and contains bank accounts,
# only take into account those. # only take into account those.
if organisation_value == organisation_value.Organisation_getMappingRelatedOrganisation(): if entity_value.getPortalType() != 'Organisation' \
bank_account_list = organisation_value.searchFolder(**search_kw) or entity_value == entity_value.Organisation_getMappingRelatedOrganisation():
bank_account_list = entity_value.searchFolder(**search_kw)
# else we lookup in organisations from parent groups. # else we lookup in organisations from parent groups.
else: else:
group_value = organisation_value.getGroupValue(None) group_value = entity_value.getGroupValue(None)
if group_value is not None: if group_value is not None:
uid_list = [] uid_list = []
while group_value.getPortalType() != 'Base Category': while group_value.getPortalType() != 'Base Category':
......
...@@ -4666,6 +4666,36 @@ class TestTransactions(AccountingTestCase): ...@@ -4666,6 +4666,36 @@ class TestTransactions(AccountingTestCase):
self.assertEqual( self.assertEqual(
at.AccountingTransaction_getDestinationPaymentItemList(), [('', '')]) 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): def test_AccountingTransaction_getSourcePaymentItemList_parent_section(self):
# AccountingTransaction_getSourcePaymentItemList and AccountingTransaction_getDestinationPaymentItemList # AccountingTransaction_getSourcePaymentItemList and AccountingTransaction_getDestinationPaymentItemList
# allows to select bank accounts from parent groups of source section # 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