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

accounting: review condition to use bank account from parents group

The condition for an organisation to be able to use bank account from
other organisations higher in the group hierarchy should not be the
presence of bank account in this organisation, but whether or not it
acts as an independant accounting entity, and this is defined by the
presence of accounting periods.
parent 628a30a7
"""Returns an item list of the acceptable bank accounts.
If `organisation` is passed, then we only show bank accounts available for that
organisation, using the following policy:
- if organisation contains bank accounts directly, only those bank accounts
can be selected
- if organisation is independant accounting entity (ie. have accounting periods),
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
- if organisation higher in the group hierarchy contains bank accounts, bank
accounts from parent organisations can be selected
- it means a higher in the group cannot use bank account from organisations
below, maybe we'll want to change this ...
If organisation is not passed, this script will return all bank accounts
applicable for section_category and section_category_strict_membership.
......@@ -20,11 +20,12 @@ if skip_invalidated_bank_accounts:
if organisation:
organisation_value = portal.restrictedTraverse(organisation)
# if organisation contains bank accounts, only take into account those.
bank_account_list = organisation_value.searchFolder(**search_kw)
# else we lookup in parent organisations
if not bank_account_list:
# if organisation is an independant 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)
# else we lookup in organisations from parent groups.
else:
group_value = organisation_value.getGroupValue(None)
if group_value is not None:
uid_list = []
......
......@@ -4332,6 +4332,11 @@ class TestTransactions(AccountingTestCase):
portal_type='Accounting Period',
)
main_section_accounting_period.start()
bank_account = self.section.newContent(
portal_type='Bank Account',
reference='from section'
)
bank_account.validate()
self.tic()
source_transaction = self._makeOne(
......@@ -4345,6 +4350,9 @@ class TestTransactions(AccountingTestCase):
self.assertIn(
('from main section', parent_bank_account.getRelativeUrl()),
source_transaction.AccountingTransaction_getSourcePaymentItemList())
self.assertIn(
('from section', bank_account.getRelativeUrl()),
source_transaction.AccountingTransaction_getSourcePaymentItemList())
destination_transaction = self._makeOne(
portal_type='Payment Transaction',
......@@ -4357,6 +4365,65 @@ class TestTransactions(AccountingTestCase):
self.assertIn(
('from main section', parent_bank_account.getRelativeUrl()),
destination_transaction.AccountingTransaction_getDestinationPaymentItemList())
self.assertIn(
('from section', bank_account.getRelativeUrl()),
destination_transaction.AccountingTransaction_getDestinationPaymentItemList())
def test_AccountingTransaction_getSourcePaymentItemList_parent_section_with_accounting_period(self):
# AccountingTransaction_getSourcePaymentItemList and AccountingTransaction_getDestinationPaymentItemList
# allows to select bank accounts from parent groups of source section, but not if
# the organisation has accounting periods, in this case it acts as an independant section.
parent_bank_account = self.main_section.newContent(
portal_type='Bank Account',
reference='from main section'
)
parent_bank_account.validate()
main_section_accounting_period = self.main_section.newContent(
portal_type='Accounting Period',
)
main_section_accounting_period.start()
bank_account = self.section.newContent(
portal_type='Bank Account',
reference='from section'
)
bank_account.validate()
# open an accounting periods in this section, it will act as an independant section
# and will not allow bank accounts from parent sections.
section_accounting_period = self.section.newContent(
portal_type='Accounting Period',
)
section_accounting_period.start()
self.tic()
source_transaction = self._makeOne(
portal_type='Payment Transaction',
source_section_value=self.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.assertNotIn(
('from main section', parent_bank_account.getRelativeUrl()),
source_transaction.AccountingTransaction_getSourcePaymentItemList())
self.assertIn(
('from section', bank_account.getRelativeUrl()),
source_transaction.AccountingTransaction_getSourcePaymentItemList())
destination_transaction = self._makeOne(
portal_type='Payment Transaction',
destination_section_value=self.section,
source_section_value=self.organisation_module.client_1,
lines=(dict(destination_value=self.account_module.goods_purchase,
destination_debit=500),
dict(destination_value=self.account_module.receivable,
destination_credit=500)))
self.assertNotIn(
('from main section', parent_bank_account.getRelativeUrl()),
destination_transaction.AccountingTransaction_getDestinationPaymentItemList())
self.assertIn(
('from section', bank_account.getRelativeUrl()),
destination_transaction.AccountingTransaction_getDestinationPaymentItemList())
class TestAccountingWithSequences(ERP5TypeTestCase):
......
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