[Erp5-report] r23755 - in /erp5/trunk/products/ERP5: Constraint/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Sep 23 12:51:10 CEST 2008


Author: jerome
Date: Tue Sep 23 12:51:07 2008
New Revision: 23755

URL: http://svn.erp5.org?rev=23755&view=rev
Log:
AccountingTransactionBalance was not handling correctly transactions where
parties are defined at line level

Modified:
    erp5/trunk/products/ERP5/Constraint/AccountingTransactionBalance.py
    erp5/trunk/products/ERP5/tests/testAccounting.py

Modified: erp5/trunk/products/ERP5/Constraint/AccountingTransactionBalance.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Constraint/AccountingTransactionBalance.py?rev=23755&r1=23754&r2=23755&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Constraint/AccountingTransactionBalance.py (original)
+++ erp5/trunk/products/ERP5/Constraint/AccountingTransactionBalance.py Tue Sep 23 12:51:07 2008
@@ -46,36 +46,41 @@
     """Implement here the consistency checker
     """
     error_list = []
-    source_sum = 0
-    destination_sum = 0
+    source_sum = dict()
+    destination_sum = dict()
     for line in obj.getMovementList(
           portal_type=obj.getPortalAccountingMovementTypeList()):
       if line.getSourceValue() is not None:
-        source_sum += line.getSourceInventoriatedTotalAssetPrice() or 0
+        section = line.getSourceSectionValue()
+        source_sum[section] = source_sum.get(section, 0) + \
+            (line.getSourceInventoriatedTotalAssetPrice() or 0)
       if line.getDestinationValue() is not None:
-        destination_sum += \
-          line.getDestinationInventoriatedTotalAssetPrice() or 0
+        section = line.getDestinationSectionValue()
+        destination_sum[section] = destination_sum.get(section, 0) + \
+          (line.getDestinationInventoriatedTotalAssetPrice() or 0)
     
-    source_section = obj.getSourceSectionValue()
-    destination_section = obj.getDestinationSectionValue()
-    source_precision = destination_precision = 2
+    for section, total in source_sum.items():
+      precision = 2
+      if section is not None and\
+          section.getPortalType() == 'Organisation':
+        section_currency = section.getPriceCurrencyValue()
+        if section_currency is not None:
+          precision = section_currency.getQuantityPrecision()
+        if round(total, precision) != 0:
+          error_list.append(self._generateError(obj, self._getMessage(
+                'message_transaction_not_balanced_for_source')))
+          break
+    
+    for section, total in destination_sum.items():
+      precision = 2
+      if section is not None and\
+          section.getPortalType() == 'Organisation':
+        section_currency = section.getPriceCurrencyValue()
+        if section_currency is not None:
+          precision = section_currency.getQuantityPrecision()
+        if round(total, precision) != 0:
+          error_list.append(self._generateError(obj, self._getMessage(
+                'message_transaction_not_balanced_for_source')))
+          break
 
-    if source_section is not None and\
-                 source_section.getPortalType() == 'Organisation':
-      source_currency = source_section.getPriceCurrencyValue()
-      if source_currency is not None:
-        source_precision = source_currency.getQuantityPrecision()
-    if round(source_sum, source_precision) != 0:
-      error_list.append(self._generateError(obj, self._getMessage(
-            'message_transaction_not_balanced_for_source')))
-
-    if destination_section is not None and\
-                 destination_section.getPortalType() == 'Organisation':
-      destination_currency = destination_section.getPriceCurrencyValue()
-      if destination_currency is not None:
-        destination_precision = destination_currency.getQuantityPrecision()
-    if round(destination_sum, destination_precision) != 0:
-      error_list.append(self._generateError(obj, self._getMessage(
-              'message_transaction_not_balanced_for_destination')))
-    
     return error_list

Modified: erp5/trunk/products/ERP5/tests/testAccounting.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testAccounting.py?rev=23755&r1=23754&r2=23755&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testAccounting.py (original)
+++ erp5/trunk/products/ERP5/tests/testAccounting.py Tue Sep 23 12:51:07 2008
@@ -512,6 +512,74 @@
       if line.getDestinationId() == 'receivable':
         line.setDestination(None)
     # but if there are no accounts defined it's not a problem
+    self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
+
+  def test_NonBalancedAccountingTransactionSectionOnLines(self):
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               resource='currency_module/yen',
+               lines=(dict(source_value=self.account_module.goods_sales,
+                           destination_value=self.account_module.goods_purchase,
+                           destination_section_value=self.organisation_module.client_1,
+                           source_debit=500),
+                      dict(source_value=self.account_module.goods_purchase,
+                           source_credit=500)))
+
+    # This is not balanced for client 1
+    self.assertRaises(ValidationFailed,
+        self.portal.portal_workflow.doActionFor,
+        transaction, 'stop_action')
+
+    for line in transaction.getMovementList():
+      line.setDestinationSection(None)
+    self.assertEquals([], transaction.checkConsistency())
+    self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
+
+  def test_NonBalancedAccountingTransactionDifferentSectionOnLines(self):
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               resource='currency_module/yen',
+               lines=(dict(source_value=self.account_module.goods_sales,
+                           destination_value=self.account_module.goods_purchase,
+                           destination_section_value=self.organisation_module.client_1,
+                           source_debit=500),
+                      dict(source_value=self.account_module.goods_purchase,
+                           destination_value=self.account_module.goods_sales,
+                           destination_section_value=self.organisation_module.client_2,
+                           source_credit=500)))
+
+    # This is not balanced for client 1 and client 2, but if you look globally,
+    # it looks balanced.
+    self.assertRaises(ValidationFailed,
+        self.portal.portal_workflow.doActionFor,
+        transaction, 'stop_action')
+    self.assertEquals(1, len(transaction.checkConsistency()),
+                         transaction.checkConsistency())
+
+    for line in transaction.getMovementList():
+      line.setDestinationSectionValue(
+          self.organisation_module.client_2)
+
+    self.assertEquals([], transaction.checkConsistency())
+    self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
+
+  def test_NonBalancedAccountingTransactionSectionPersonOnLines(self):
+    transaction = self._makeOne(
+               portal_type='Accounting Transaction',
+               start_date=DateTime('2007/01/02'),
+               resource='currency_module/yen',
+               lines=(dict(source_value=self.account_module.goods_purchase,
+                           destination_value=self.account_module.goods_purchase,
+                           destination_section_value=self.person_module.john_smith,
+                           source_debit=500),
+                      dict(source_value=self.account_module.goods_purchase,
+                           source_credit=500)))
+
+    # This is not balanced for john smith, but as he is a person, it's not a
+    # problem
+    self.assertEquals([], transaction.checkConsistency())
     self.portal.portal_workflow.doActionFor(transaction, 'stop_action')
 
   def test_AccountingTransactionValidationRefusedWithCategoriesAsSections(self):




More information about the Erp5-report mailing list