From 127ae583b43d17c3620aec0b5977db543195d056 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 24 Apr 2009 08:57:09 +0000
Subject: [PATCH] tests for AccountingTransaction_getTotalDebit and
 AccountingTransaction_getTotalCredit

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

diff --git a/product/ERP5/tests/testAccounting.py b/product/ERP5/tests/testAccounting.py
index 27a450562f..88bdca3c12 100644
--- a/product/ERP5/tests/testAccounting.py
+++ b/product/ERP5/tests/testAccounting.py
@@ -2409,6 +2409,108 @@ class TestTransactions(AccountingTestCase):
     self.failIf(invoice_line.getGroupingReference())
     self.failIf(payment_line.getGroupingReference())
 
+  def test_AccountingTransaction_getTotalDebitCredit(self):
+    # source view
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               destination_section_value=self.organisation_module.client_1,
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           source_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           source_credit=400)))
+    self.assertTrue(transaction.AccountingTransaction_isSourceView())
+    self.assertEquals(500, transaction.AccountingTransaction_getTotalDebit())
+    self.assertEquals(400, transaction.AccountingTransaction_getTotalCredit())
+
+    # destination view
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               source_section_value=self.organisation_module.client_1,
+               destination_section_value=self.section,
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           destination_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           destination_credit=400)))
+    self.assertFalse(transaction.AccountingTransaction_isSourceView())
+    self.assertEquals(500, transaction.AccountingTransaction_getTotalDebit())
+    self.assertEquals(400, transaction.AccountingTransaction_getTotalCredit())
+
+    # source view, with conversion on our side
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               destination_section_value=self.organisation_module.client_1,
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           source_asset_debit=50,
+                           source_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           source_asset_credit=40,
+                           source_credit=400)))
+    self.assertTrue(transaction.AccountingTransaction_isSourceView())
+    self.assertEquals(50, transaction.AccountingTransaction_getTotalDebit())
+    self.assertEquals(40, transaction.AccountingTransaction_getTotalCredit())
+
+    # destination view, with conversion on our side
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               source_section_value=self.organisation_module.client_1,
+               destination_section_value=self.section,
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           destination_asset_debit=50,
+                           destination_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           destination_asset_credit=40,
+                           destination_credit=400)))
+    self.assertFalse(transaction.AccountingTransaction_isSourceView())
+    self.assertEquals(50, transaction.AccountingTransaction_getTotalDebit())
+    self.assertEquals(40, transaction.AccountingTransaction_getTotalCredit())
+
+    # source view, with conversion on other side
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               destination_section_value=self.organisation_module.client_1,
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           destination_asset_debit=50,
+                           source_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           destination_asset_credit=40,
+                           source_credit=400)))
+    self.assertTrue(transaction.AccountingTransaction_isSourceView())
+    self.assertEquals(500, transaction.AccountingTransaction_getTotalDebit())
+    self.assertEquals(400, transaction.AccountingTransaction_getTotalCredit())
+    
+    # destination view, with conversion on other side
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               source_section_value=self.organisation_module.client_1,
+               destination_section_value=self.section,
+               lines=(dict(source_value=self.account_module.payable,
+                           destination_value=self.account_module.receivable,
+                           source_asset_debit=50,
+                           destination_debit=500),
+                      dict(source_value=self.account_module.receivable,
+                           destination_value=self.account_module.payable,
+                           source_asset_credit=40,
+                           destination_credit=400)))
+    self.assertFalse(transaction.AccountingTransaction_isSourceView())
+    self.assertEquals(500, transaction.AccountingTransaction_getTotalDebit())
+    self.assertEquals(400, transaction.AccountingTransaction_getTotalCredit())
+
 
 
 class TestAccountingWithSequences(AccountingTestCase):
-- 
2.30.9