From 88a0dffdb7ffe41ea27d8098b4d99885faeb0504 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Tue, 6 Jul 2010 10:57:28 +0000
Subject: [PATCH]  - check behaviour of Invoice_getRemainingTotalPayablePrice
 in case if Payment Transaction is deleted  - clean up site in tear down using
 user with Manager role to avoid issues with unaccessible objects

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

diff --git a/product/ERP5/tests/testAccounting.py b/product/ERP5/tests/testAccounting.py
index d675fe1771..d57a878ea7 100644
--- a/product/ERP5/tests/testAccounting.py
+++ b/product/ERP5/tests/testAccounting.py
@@ -206,6 +206,7 @@ class AccountingTestCase(ERP5TypeTestCase):
     """
     if os.environ.get('erp5_save_data_fs'):
       return
+    self.login('ERP5TypeTestCase')
     transaction.abort()
     self.accounting_module.manage_delObjects(
                       list(self.accounting_module.objectIds()))
@@ -2594,6 +2595,31 @@ class TestTransactions(AccountingTestCase):
         self.assertEquals(100, line.getSourceCredit())
         self.assertEquals(None, line.getSourceTotalAssetPrice())
       
+  # tests for Invoice_getRemainingTotalPayablePrice
+  def test_Invoice_getRemainingTotalPayablePriceDeletedPayment(self):
+    """Checks in case of deleted Payments related to invoice"""
+    # Simple case of creating a related payment transaction.
+    payment_node = self.section.newContent(portal_type='Bank Account')
+    invoice = self._makeOne(
+               destination_section_value=self.organisation_module.client_1,
+               lines=(dict(source_value=self.account_module.goods_purchase,
+                           source_debit=100),
+                      dict(source_value=self.account_module.receivable,
+                           source_credit=100)))
+    payment = invoice.Invoice_createRelatedPaymentTransaction(
+                                  node=self.account_module.bank.getRelativeUrl(),
+                                  payment=payment_node.getRelativeUrl(),
+                                  payment_mode='check',
+                                  batch_mode=1)
+    transaction.commit()
+    self.tic()
+    remaining_price = invoice.Invoice_getRemainingTotalPayablePrice()
+    self.assertEqual(-100, remaining_price)
+    payment.delete()
+    transaction.commit()
+    self.tic()
+    remaining_price = invoice.Invoice_getRemainingTotalPayablePrice()
+    self.assertEqual(-100, remaining_price)
 
   # tests for Grouping References
   def test_GroupingReferenceResetedOnCopyPaste(self):
-- 
2.30.9