Commit 5e85b655 authored by Jérome Perrin's avatar Jérome Perrin

accounting: only allow validated bank accounts belonging to sections

The only check with accounting transactions regarding bank account
was that the bank account is not invalidated. This makes the
constraint more strict by checking that the bank account belongs to
the corresponding entity and also that the bank account is validated.

A few tests needed to be updated to validate the bank accounts. Also
a legacy sequence test has been removed because it is now covered by
normal tests.
parent ae15e7e1
...@@ -20,17 +20,24 @@ container.script_validateTransaction(state_change) ...@@ -20,17 +20,24 @@ container.script_validateTransaction(state_change)
# parties or bank accounts # parties or bank accounts
transaction_lines = transaction.objectValues(portal_type=transaction.getPortalAccountingMovementTypeList()) transaction_lines = transaction.objectValues(portal_type=transaction.getPortalAccountingMovementTypeList())
id_to_delete_list = [] id_to_delete_list = []
getBankAccountItemList = portal.AccountModule_getBankAccountItemList
for line in transaction_lines: for line in transaction_lines:
for account, third_party, bank_account, bank_account_relative_url_list_getter in (
for account, third_party, bank_account in ( (
( line.getSourceValue(portal_type='Account'), line.getSourceValue(portal_type='Account'),
line.getDestinationSectionValue(portal_type=section_portal_type_list), line.getDestinationSectionValue(portal_type=section_portal_type_list),
line.getSourcePaymentValue(portal_type=bank_account_portal_type),), line.getSourcePaymentValue(portal_type=bank_account_portal_type),
( line.getDestinationValue(portal_type='Account'), lambda: (x[1] for x in getBankAccountItemList(
organisation=line.getSourceSection(portal_type=section_portal_type_list))),
),
(
line.getDestinationValue(portal_type='Account'),
line.getSourceSectionValue(portal_type=section_portal_type_list), line.getSourceSectionValue(portal_type=section_portal_type_list),
line.getDestinationPaymentValue(portal_type=bank_account_portal_type),), line.getDestinationPaymentValue(portal_type=bank_account_portal_type),
): lambda: (x[1] for x in getBankAccountItemList(
organisation=line.getDestinationSection(portal_type=section_portal_type_list))),
),
):
if account is not None and account.getValidationState() != 'validated': if account is not None and account.getValidationState() != 'validated':
raise ValidationFailed(translateString( raise ValidationFailed(translateString(
"Account ${account_title} is not validated.", "Account ${account_title} is not validated.",
...@@ -43,7 +50,7 @@ for line in transaction_lines: ...@@ -43,7 +50,7 @@ for line in transaction_lines:
mapping=dict(third_party_name=third_party.getTitle()))) mapping=dict(third_party_name=third_party.getTitle())))
if bank_account is not None: if bank_account is not None:
if bank_account.getValidationState() in invalid_state_list: if bank_account.getRelativeUrl() not in bank_account_relative_url_list_getter():
raise ValidationFailed(translateString( raise ValidationFailed(translateString(
"Bank Account ${bank_account_reference} is invalid.", "Bank Account ${bank_account_reference} is invalid.",
mapping=dict(bank_account_reference=bank_account.getReference()))) mapping=dict(bank_account_reference=bank_account.getReference())))
......
...@@ -22,12 +22,15 @@ organisation = portal.organisation_module.newContent( ...@@ -22,12 +22,15 @@ organisation = portal.organisation_module.newContent(
title=organisation_id, title=organisation_id,
group_value=portal.portal_categories.group.demo_group, group_value=portal.portal_categories.group.demo_group,
) )
organisation.validate()
bank_account_id = "erp5_payment_mean_bank" bank_account_id = "erp5_payment_mean_bank"
bank_account = organisation.newContent( bank_account = organisation.newContent(
portal_type='Bank Account', portal_type='Bank Account',
id=bank_account_id, id=bank_account_id,
title=bank_account_id title=bank_account_id
) )
bank_account.validate()
payment_mean_id = "erp5_payment_mean_ui_test_payment_transaction_group" payment_mean_id = "erp5_payment_mean_ui_test_payment_transaction_group"
payment_mean = portal.payment_transaction_group_module.newContent( payment_mean = portal.payment_transaction_group_module.newContent(
......
...@@ -314,7 +314,7 @@ class TestOrderMixin(SubcontentReindexingWrapper): ...@@ -314,7 +314,7 @@ class TestOrderMixin(SubcontentReindexingWrapper):
portal_type=organisation_portal_type) portal_type=organisation_portal_type)
organisation.newContent(id='bank', organisation.newContent(id='bank',
portal_type='Bank Account', portal_type='Bank Account',
title='bank%s' % organisation.getId()) title='bank%s' % organisation.getId()).validate()
organisation.setDefaultAddressStreetAddress('rue xv') organisation.setDefaultAddressStreetAddress('rue xv')
organisation.setDefaultAddressZipCode('12345') organisation.setDefaultAddressZipCode('12345')
if title is None: if title is None:
......
...@@ -68,6 +68,7 @@ my_organisation.validate() ...@@ -68,6 +68,7 @@ my_organisation.validate()
bank_account = my_organisation.newContent(portal_type="Bank Account", bank_account = my_organisation.newContent(portal_type="Bank Account",
title=howto_dict["sale_howto_bank_account_title"], title=howto_dict["sale_howto_bank_account_title"],
reference=howto_dict["sale_howto_bank_account_reference"],) reference=howto_dict["sale_howto_bank_account_reference"],)
bank_account.validate()
organisation = portal.organisation_module.newContent(portal_type='Organisation', organisation = portal.organisation_module.newContent(portal_type='Organisation',
title=howto_dict['sale_howto_organisation2_title'], title=howto_dict['sale_howto_organisation2_title'],
......
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