From 05b35969300e51bf3c93cdb5debc7649ed716c81 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 5 Nov 2007 15:46:13 +0000
Subject: [PATCH] more tests for debit == credit validation with potential
 rounding issues

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17388 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/tests/testAccounting.py | 47 ++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/product/ERP5/tests/testAccounting.py b/product/ERP5/tests/testAccounting.py
index d2f44b39d1..f9a4cec466 100644
--- a/product/ERP5/tests/testAccounting.py
+++ b/product/ERP5/tests/testAccounting.py
@@ -359,6 +359,53 @@ class TestTransactionValidation(AccountingTestCase):
     transaction.setSourcePaymentValue(bank_account)
     self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
 
+  def test_NonBalancedAccountingTransaction(self):
+    # Accounting Transactions have to be balanced to be validated
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               destination_section_value=self.organisation_module.client_1,
+               resource='currency_module/yen',
+               lines=(dict(source_value=self.account_module.payable,
+                           source_asset_debit=39,
+                           source_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           source_asset_credit=38.99,
+                           source_credit=500)))
+    # refused because not balanced
+    self.assertRaises(ValidationFailed,
+        self.portal.portal_workflow.doActionFor,
+        transaction, 'stop_action')
+    for line in transaction.getMovementList():
+      if line.getSourceId() == 'payable':
+        line.setSourceAssetDebit(38.99)
+    self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
+
+  def test_NonBalancedDestinationAccountingTransaction(self):
+    # Accounting Transactions have to be balanced to be validated,
+    # also for destination
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               destination_section_value=self.organisation_module.client_1,
+               resource='currency_module/yen',
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           destination_asset_debit=39,
+                           source_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           destination_asset_credit=38.99,
+                           source_credit=500)))
+    # refused because not balanced
+    self.assertRaises(ValidationFailed,
+        self.portal.portal_workflow.doActionFor,
+        transaction, 'stop_action')
+    for line in transaction.getMovementList():
+      if line.getDestinationId() == 'receivable':
+        line.setDestinationAssetDebit(38.99)
+    self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
+
 
 class TestClosingPeriod(AccountingTestCase):
   """Various tests for closing the period.
-- 
2.30.9