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

accounting: fix balance constraint bug with acquired nodes

When checking constraints, ignore lines where the node is an acquired
organisation, we should only consider lines where node is an account.

(cherry picked from commit c61cde5b)
parent 5c685241
......@@ -53,11 +53,11 @@ class AccountingTransactionBalanceConstraint(ConstraintMixin):
destination_sum = {}
for line in obj.getMovementList(
portal_type=obj.getPortalAccountingMovementTypeList()):
if line.getSourceValue() is not None:
if line.getSourceValue(portal_type='Account') is not None:
section = line.getSourceSectionValue()
source_sum[section] = source_sum.get(section, 0) + \
(line.getSourceInventoriatedTotalAssetPrice() or 0)
if line.getDestinationValue() is not None:
if line.getDestinationValue(portal_type='Account') is not None:
section = line.getDestinationSectionValue()
destination_sum[section] = destination_sum.get(section, 0) + \
(line.getDestinationInventoriatedTotalAssetPrice() or 0)
......
......@@ -679,6 +679,58 @@ class TestTransactionValidation(AccountingTestCase):
self.assertEqual([], accounting_transaction.checkConsistency())
self.portal.portal_workflow.doActionFor(accounting_transaction, 'stop_action')
def test_NonBalancedSourceAccountingTransactionNoAccountSourceAcquired(self):
# Accounting Transactions have to be balanced to be validated,
# the constraint should take care that the lines may acquire
# a source from the transaction
accounting_transaction = self._makeOne(
portal_type='Accounting Transaction',
start_date=DateTime('2007/01/02'),
destination_section_value=self.organisation_module.client_1,
source_value=self.section,
resource='currency_module/yen',
lines=(dict(destination_value=self.account_module.payable,
source_asset_debit=39,
source_debit=500),
dict(source_value=self.account_module.receivable,
destination_value=self.account_module.receivable,
source_asset_credit=38.99,
source_credit=500)))
self.assertRaises(ValidationFailed,
self.portal.portal_workflow.doActionFor,
accounting_transaction, 'stop_action')
for line in accounting_transaction.getMovementList():
if line.getSourceId() == 'receivable':
line.setSource(None)
# but if there are no accounts defined it's not a problem
self.portal.portal_workflow.doActionFor(accounting_transaction, 'stop_action')
def test_NonBalancedDestinationAccountingTransactionNoAccountDestinationAcquired(self):
# Accounting Transactions have to be balanced to be validated,
# the constraint should take care that the lines may acquire
# a destination from the transaction
accounting_transaction = self._makeOne(
portal_type='Accounting Transaction',
start_date=DateTime('2007/01/02'),
destination_section_value=self.organisation_module.client_1,
destination_value=self.organisation_module.client_1,
resource='currency_module/yen',
lines=(dict(source_value=self.account_module.payable,
destination_asset_debit=39,
source_debit=500),
dict(source_value=self.account_module.receivable,
destination_value=self.account_module.receivable,
destination_asset_credit=38.99,
source_credit=500)))
self.assertRaises(ValidationFailed,
self.portal.portal_workflow.doActionFor,
accounting_transaction, 'stop_action')
for line in accounting_transaction.getMovementList():
if line.getDestinationId() == 'receivable':
line.setDestination(None)
# but if there are no accounts defined it's not a problem
self.portal.portal_workflow.doActionFor(accounting_transaction, 'stop_action')
def test_AccountingTransactionValidationRefusedWithCategoriesAsSections(self):
# Validating a transaction with categories as sections is refused.
# See http://wiki.erp5.org/Discussion/AccountingProblems
......
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