[Erp5-report] r28075 - in /erp5/trunk/products/ERP5: ./ Document/ interfaces/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jul 14 16:29:31 CEST 2009


Author: jerome
Date: Tue Jul 14 16:29:31 2009
New Revision: 28075

URL: http://svn.erp5.org?rev=28075&view=rev
Log:
introduce IAggregatedAmountList and change
TradeCondition.getAggregatedAmountList to return an AggregatedAmountList
instead of a simple list. Some XXX are left.

Modified:
    erp5/trunk/products/ERP5/AggregatedAmountList.py
    erp5/trunk/products/ERP5/Document/TradeCondition.py
    erp5/trunk/products/ERP5/interfaces/transformation.py
    erp5/trunk/products/ERP5/tests/testERP5Interfaces.py

Modified: erp5/trunk/products/ERP5/AggregatedAmountList.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/AggregatedAmountList.py?rev=28075&r1=28074&r2=28075&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/AggregatedAmountList.py [utf8] (original)
+++ erp5/trunk/products/ERP5/AggregatedAmountList.py [utf8] Tue Jul 14 16:29:31 2009
@@ -28,15 +28,21 @@
 ##############################################################################
 
 from UserList import UserList
+
+import zope.interface
 from Globals import InitializeClass
 from Products.PythonScripts.Utility import allow_class
 from AccessControl import ClassSecurityInfo
-from UserList import UserList
+
+from Products.ERP5.interfaces.transformation import IAggregatedAmountList
+
 class AggregatedAmountList(UserList):
   """
     Temporary object needed to aggregate Amount value
     And to calculate some report or total value
   """
+  zope.interface.implements(IAggregatedAmountList)
+
   meta_type = "AggregatedAmountList"
   security = ClassSecurityInfo()
 #  security.declareObjectPublic()

Modified: erp5/trunk/products/ERP5/Document/TradeCondition.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/TradeCondition.py?rev=28075&r1=28074&r2=28075&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] Tue Jul 14 16:29:31 2009
@@ -88,7 +88,6 @@
               .getPreferredNormalResourceUseCategoryList()
       # check if the existing movements are in aggregated movements
       movement_to_delete_list = []
-      movement_to_add_list = []
       for movement in existing_movement_list:
         keep_movement = False
         # check if the movement is a generated one or entered by the user.
@@ -112,8 +111,9 @@
             keep_movement = True
         if not keep_movement:
           movement_to_delete_list.append(movement)
-      movement_to_add_list = [amount for amount in aggregated_amount_list if
-          amount.getReference() not in modified_reference_list]
+      movement_to_add_list = AggregatedAmountList(
+                  [amount for amount in aggregated_amount_list if
+                    amount.getReference() not in modified_reference_list])
       return {'movement_to_delete_list' : movement_to_delete_list,
               'movement_to_add_list': movement_to_add_list}
 
@@ -228,15 +228,20 @@
           **kw))
       movement_list = result
 
-      # remove movement that should not be created
-      final_movement_list = []
+      # remove amounts that should not be created, or with "incorrect" references.
+      # XXX what are incorrect references ???
+      # getTradeModelLineComposedList should have removed duplicate reference
+      # in the model graph
+      # TODO: review this part
+      aggregated_amount_list = AggregatedAmountList()
       for movement in movement_list:
-        movement_ref = movement.getReference()
+        movement_reference = movement.getReference()
         for model_line in trade_model_line_composed_list:
-          if model_line.getReference() == movement_ref and\
+          if model_line.getReference() == movement_reference and\
               model_line.isCreateLine():
-            final_movement_list.append(movement)
-      return final_movement_list
+            aggregated_amount_list.append(movement)
+
+      return aggregated_amount_list
 
     security.declareProtected( Permissions.AccessContentsInformation, 'getCell')
     def getCell(self, *kw , **kwd):

Modified: erp5/trunk/products/ERP5/interfaces/transformation.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/interfaces/transformation.py?rev=28075&r1=28074&r2=28075&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/interfaces/transformation.py [utf8] (original)
+++ erp5/trunk/products/ERP5/interfaces/transformation.py [utf8] Tue Jul 14 16:29:31 2009
@@ -30,10 +30,18 @@
 
 from zope.interface import Interface
 
+try:
+  from zope.interface.common.sequence import ISequence
+except ImportError:
+  # ISequence does not exists in old zope.interface versions
+  class ISequence(Interface):
+    pass
+
+
 class ITransformation(Interface):
   """
-    Common Interface to implementing querying of Indirect Amount
-    Models (TaxModelLine, InvoiceModelLine, etc) shall be based on this
+    Common Interface to implementing querying of indirect amount
+    models (TaxModelLine, InvoiceModelLine, etc) shall be based on this
     interface
   """
 
@@ -48,17 +56,16 @@
     rounding - boolean argument, which controls if rounding shall be applied on
       generated movements or not
 
-    Returns list of instance of AggregatedAmountList class
+    Returns an instance implementing IAggregatedAmountList.
 
     Note: This method shall be linear in case if context is order, line,
     applied rule or movement. In case of built delivery this method shall
     be wise enough to CORRECTLY un-linearise calculation, eg. tax is
     time dependent, paysheet build from invoices.
     """
-    pass
 
   def updateAggregatedAmountList(context, movement_list=None, rounding=False):
-    """Updates existing movement and returns new or deleted if any according to model
+    """Updates existing movements and returns new or deleted if any according to model
 
     context - represents object on which update shall happen
 
@@ -68,9 +75,18 @@
     rounding - boolean argument, which controls if rounding shall be applied on
       generated movements or not
 
-    Returns a dictionary of list of instances of AggregatedAmountList class.
-    Dictionary contain lists described by keys:
-      * movement_to_add_list - list for movements which shall be added
-      * movement_to_delete_list - list of movements which shall be deleted
+    Returns a dictionary with two keys:
+      * movement_to_add_list - an instance of IAggregatedAmountList for amounts
+        that have to be added in the context.
+        FIXME: this is not 'movement'
+      * movement_to_delete_list - a list of movements from movement_list or from the
+        context that shall be deleted.
     """
-    pass
+
+
+class IAggregatedAmountList(ISequence):
+  """An Aggregated Amount List is a list of amounts aggregated together.
+
+  It is a sequence of objects implementing IAmount interface.
+  """
+

Modified: erp5/trunk/products/ERP5/tests/testERP5Interfaces.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testERP5Interfaces.py?rev=28075&r1=28074&r2=28075&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testERP5Interfaces.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testERP5Interfaces.py [utf8] Tue Jul 14 16:29:31 2009
@@ -61,6 +61,12 @@
 class TestERP5Interfaces(ERP5TypeTestCase):
   """Tests implementation of interfaces"""
 
+  def test_AggregatedAmountList_implements_IAggregatedAmountList(self):
+    # AggregatedAmountList is not a document
+    from Products.ERP5.interfaces.transformation import IAggregatedAmountList
+    from Products.ERP5.AggregatedAmountList import AggregatedAmountList
+    verifyClass(IAggregatedAmountList, AggregatedAmountList)
+  
 def makeTestMethod(document, interface):
   """Common method which checks if documents implements interface"""
   def testMethod(self):




More information about the Erp5-report mailing list