[Erp5-report] r16407 - in /erp5/trunk/products/ERP5: Document/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Sep 17 15:22:18 CEST 2007


Author: jerome
Date: Mon Sep 17 15:22:17 2007
New Revision: 16407

URL: http://svn.erp5.org?rev=16407&view=rev
Log:
Make sure balance transaction line from getMovementHistoryList can be retrieved with getObject

Modified:
    erp5/trunk/products/ERP5/Document/BalanceTransaction.py
    erp5/trunk/products/ERP5/tests/testAccounting.py

Modified: erp5/trunk/products/ERP5/Document/BalanceTransaction.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BalanceTransaction.py?rev=16407&r1=16406&r2=16407&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BalanceTransaction.py (original)
+++ erp5/trunk/products/ERP5/Document/BalanceTransaction.py Mon Sep 17 15:22:17 2007
@@ -227,6 +227,8 @@
               dict(destination_uid=node_uid,
                    destination_section_uid=section_uid,
                    resource_uid=movement.getResourceUid(),
+                   uid=movement.getUid(),
+                   relative_url=movement.getRelativeUrl(),
                    quantity=movement.getQuantity(),
                    total_price=movement\
                     .getDestinationInventoriatedTotalAssetPrice(), ))
@@ -246,6 +248,8 @@
                    destination_section_uid=section_uid,
                    source_section_uid=mirror_section_uid,
                    resource_uid=movement.getResourceUid(),
+                   uid=movement.getUid(),
+                   relative_url=movement.getRelativeUrl(),
                    quantity=movement.getQuantity(),
                    total_price=movement\
                     .getDestinationInventoriatedTotalAssetPrice(), ))
@@ -265,6 +269,8 @@
                    destination_section_uid=section_uid,
                    destination_payment_uid=payment_uid,
                    resource_uid=movement.getResourceUid(),
+                   uid=movement.getUid(),
+                   relative_url=movement.getRelativeUrl(),
                    quantity=movement.getQuantity(),
                    total_price=movement\
                     .getDestinationInventoriatedTotalAssetPrice(), ))
@@ -288,7 +294,7 @@
         matching_diff = None
         for diff in stock_diff_list:
           for prop in [k for k in diff.keys() if k not in ('quantity',
-                          'total_price')]:
+                          'total_price', 'uid', 'relative_url')]:
             if diff[prop] != new_stock.get(prop):
               break
           else:
@@ -347,10 +353,26 @@
     def factory(*args, **kw):
       doc = newTempBalanceTransactionLine(self, self.getId(),
                                          uid=self.getUid())
+      relative_url = kw.pop('relative_url', None)
       destination_total_asset_price = kw.pop('total_price', None)
       if destination_total_asset_price is not None:
         kw['destination_total_asset_price'] = destination_total_asset_price
       doc._edit(*args, **kw)
+
+      if relative_url:
+        
+        def URLGetter(url):
+          def getRelativeUrl():
+            return url
+          return getRelativeUrl
+        doc.getRelativeUrl = URLGetter(relative_url)
+        
+        def PathGetter(path):
+          def getPath():
+            return path
+          return getPath
+        doc.getPath = PathGetter(relative_url)
+
       return doc
 
     return factory
@@ -396,6 +418,8 @@
     
     # Catalog differences calculated from lines
     self.portal_catalog.catalogObjectList(stock_object_list,
-         method_id_list=('z_catalog_stock_list',),
+         method_id_list=('z_catalog_stock_list',
+                         'z_catalog_object_list',
+                         'z_catalog_movement_category_list'),
          disable_cache=1, check_uid=0)
     

Modified: erp5/trunk/products/ERP5/tests/testAccounting.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testAccounting.py?rev=16407&r1=16406&r2=16407&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testAccounting.py (original)
+++ erp5/trunk/products/ERP5/tests/testAccounting.py Mon Sep 17 15:22:17 2007
@@ -219,6 +219,13 @@
 class TestClosingPeriod(AccountingTestCase):
   """Various tests for closing the period.
   """
+  def beforeTearDown(self):
+    # we manually remove the content of stock table, because unindexObject
+    # might not work correctly on Balance Transaction, and we don't want
+    # leave something in stock table that will change the next test.
+    self.portal.erp5_sql_connection.manage_test('truncate stock')
+    get_transaction().commit()
+
   def test_createBalanceOnNode(self):
     period = self.section.newContent(portal_type='Accounting Period')
     period.setStartDate(DateTime(2006, 1, 1))
@@ -944,7 +951,116 @@
                               node_uid=node_uid))
     
 
-
+  def test_BalanceTransactionLineBrainGetObject(self):
+    # Balance Transaction Line can be retrieved using Brain.getObject
+    balance = self.accounting_module.newContent(
+                          portal_type='Balance Transaction',
+                          destination_section_value=self.section,
+                          start_date=DateTime(2006, 12, 31),
+                          resource_value=self.currency_module.euro,)
+    balance_line = balance.newContent(
+                portal_type='Balance Transaction Line',
+                destination_value=self.account_module.receivable,
+                destination_debit=100,)
+    balance_line2 = balance.newContent(
+                portal_type='Balance Transaction Line',
+                destination_value=self.account_module.payable,
+                destination_credit=100,)
+    balance.stop()
+    get_transaction().commit()
+    self.tic()
+    
+    stool = self.portal.portal_simulation
+    # the account 'receivable' has a balance of 100
+    node_uid = self.account_module.receivable.getUid()
+    self.assertEquals(100, stool.getInventory(
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid))
+    # there is one line in getMovementHistoryList:
+    mvt_history_list = stool.getMovementHistoryList(
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid)
+    self.assertEquals(1, len(mvt_history_list))
+    self.assertEquals(mvt_history_list[0].getObject(),
+                      balance_line)
+
+    # There is also one line on payable account
+    node_uid = self.account_module.payable.getUid()
+    mvt_history_list = stool.getMovementHistoryList(
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid)
+    self.assertEquals(1, len(mvt_history_list))
+    self.assertEquals(mvt_history_list[0].getObject(),
+                      balance_line2)
+
+  def test_BalanceTransactionDate(self):
+    # check that dates are correctly used for Balance Transaction indexing
+    balance = self.accounting_module.newContent(
+                          portal_type='Balance Transaction',
+                          destination_section_value=self.section,
+                          start_date=DateTime(2006, 12, 31),
+                          resource_value=self.currency_module.euro,)
+    balance_line = balance.newContent(
+                portal_type='Balance Transaction Line',
+                destination_value=self.account_module.receivable,
+                destination_debit=100,)
+    balance.stop()
+    get_transaction().commit()
+    self.tic()
+    
+    stool = self.portal.portal_simulation
+    # the account 'receivable' has a balance of 100 after 2006/12/31
+    node_uid = self.account_module.receivable.getUid()
+    self.assertEquals(100, stool.getInventory(
+                              at_date=DateTime(2006, 12, 31),
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid))
+    self.assertEquals(1, len(stool.getMovementHistoryList(
+                              at_date=DateTime(2006, 12, 31),
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid)))
+    # and 0 before
+    self.assertEquals(0, stool.getInventory(
+                              at_date=DateTime(2005, 12, 31),
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid))
+    self.assertEquals(0, len(stool.getMovementHistoryList(
+                              at_date=DateTime(2005, 12, 31),
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid)))
+
+
+  def test_BalanceTransactionLineInventoryAPIParentPortalType(self):
+    # related keys like parent_portal_type= can be used in inventory API to get
+    # balance transaction lines
+    balance = self.accounting_module.newContent(
+                          portal_type='Balance Transaction',
+                          destination_section_value=self.section,
+                          start_date=DateTime(2006, 12, 31),
+                          resource_value=self.currency_module.euro,)
+    balance_line = balance.newContent(
+                portal_type='Balance Transaction Line',
+                destination_value=self.account_module.receivable,
+                destination_debit=100,)
+    balance.stop()
+    get_transaction().commit()
+    self.tic()
+    
+    stool = self.portal.portal_simulation
+    # the account 'receivable' has a balance of 100
+    node_uid = self.account_module.receivable.getUid()
+    self.assertEquals(100, stool.getInventory(
+                              parent_portal_type='Balance Transaction',
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid))
+    # there is one line in getMovementHistoryList:
+    mvt_history_list = stool.getMovementHistoryList(
+                              parent_portal_type='Balance Transaction',
+                              section_uid=self.section.getUid(),
+                              node_uid=node_uid)
+    self.assertEquals(1, len(mvt_history_list))
+
+  # TODO : test deletion ?
 
 class TestAccounting(ERP5TypeTestCase):
   """The first test for Accounting




More information about the Erp5-report mailing list