diff --git a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getBankAccountItemList.py b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getBankAccountItemList.py index 07fda6e3ee09c044619afc446e2743953491b780..cbf53b5894b3779bb7d93a84a6f6871cd307044c 100644 --- a/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getBankAccountItemList.py +++ b/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/AccountModule_getBankAccountItemList.py @@ -1,12 +1,12 @@ """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 = [] diff --git a/product/ERP5/tests/testAccounting.py b/product/ERP5/tests/testAccounting.py index a1f575810a84e6a8526da05e2a9eb0f335c0f41b..71dc63d81c5340bec8064896850654ada3fedb36 100644 --- a/product/ERP5/tests/testAccounting.py +++ b/product/ERP5/tests/testAccounting.py @@ -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):