[Erp5-report] r26652 - /erp5/trunk/products/ERP5/Document/TradeCondition.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Apr 27 11:46:04 CEST 2009


Author: luke
Date: Mon Apr 27 11:46:04 2009
New Revision: 26652

URL: http://svn.erp5.org?rev=26652&view=rev
Log:
 - implement aggregated amount list of trade models in trade condition

Modified:
    erp5/trunk/products/ERP5/Document/TradeCondition.py

Modified: erp5/trunk/products/ERP5/Document/TradeCondition.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/TradeCondition.py?rev=26652&r1=26651&r2=26652&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/TradeCondition.py [utf8] Mon Apr 27 11:46:04 2009
@@ -1,8 +1,10 @@
+# -*- coding: utf8 -*-
 ##############################################################################
 #
-# Copyright (c) 2002, 2004 Nexedi SARL and Contributors. All Rights Reserved.
+# Copyright (c) 2002-2009 Nexedi SA and Contributors. All Rights Reserved.
 #                    Jean-Paul Smets-Solanes <jp at nexedi.com>
 #                    Romain Courteaud <romain at nexedi.com>
+#                    Łukasz Nowak <luke at nexedi.com>
 #
 # WARNING: This program as such is intended to be used by professional
 # programmers who take the whole responsability of assessing all potential
@@ -31,14 +33,18 @@
 from AccessControl import ClassSecurityInfo
 
 from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
+from Products.ERP5.Document.Transformation import Transformation
 from Products.ERP5.Document.Path import Path
+from Products.ERP5.AggregatedAmountList import AggregatedAmountList
 
-class TradeCondition(Path):
+class TradeCondition(Path, Transformation):
     """
       Trade Conditions are used to store the conditions (payment, logistic,...)
       which should be applied (and used in the orders) when two companies make
       business together
     """
+    edited_property_list = ['price', 'causality','resource','quantity',
+        'base_application_list', 'base_contribution_list']
 
     meta_type = 'ERP5 Trade Condition'
     portal_type = 'Trade Condition'
@@ -60,3 +66,41 @@
                       , PropertySheet.Order
                       )
 
+    def updateAggregatedAmountList(self, context, destination_portal_type, **kw):
+      # XXX: Shall not create new, only update existing and return new
+      existing_object_list = context.objectValues(portal_type=destination_portal_type)
+      for o in self.getAggregatedAmountList(context = context, **kw):
+        update_kw = {}
+        create_new = 1
+        for p in self.edited_property_list:
+          update_kw[p] = o.getProperty(p)
+        for e in existing_object_list:
+          if e.getProperty('resource') == o.getProperty('resource'):
+            # we need to update existing
+            e.edit(**update_kw)
+            create_new = 0
+            break
+        if create_new:
+          context.newContent(
+            portal_type = destination_portal_type,
+            **update_kw
+          )
+
+    def getAggregatedAmountList(self, context, **kw):
+      result = AggregatedAmountList()
+
+      need_to_run = 1
+      movement_list = []
+      while need_to_run:
+        need_to_run = 0
+        for model in self.objectValues(portal_type='Trade Model Line'):
+          model_result = model.getAggregatedAmountList(context,
+            movement_list=movement_list, current_aggregated_amount_list = result,
+            **kw)
+          result.extend(model_result)
+        if len(result) != len(movement_list):
+          # something was added
+          need_to_run = 1
+        movement_list = result
+
+      return result




More information about the Erp5-report mailing list