[Erp5-report] r26733 - in /erp5/trunk/products/ERP5/Document: AppliedRule.py Delivery.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Apr 30 12:52:05 CEST 2009


Author: luke
Date: Thu Apr 30 12:52:03 2009
New Revision: 26733

URL: http://svn.erp5.org?rev=26733&view=rev
Log:
 - provide a method to get first specialise value matching portal type list criteria for delivery
 - implement getBusinessProcessValue and getTradeConditionValue by searching up in simulation tree to find proper document

Modified:
    erp5/trunk/products/ERP5/Document/AppliedRule.py
    erp5/trunk/products/ERP5/Document/Delivery.py

Modified: erp5/trunk/products/ERP5/Document/AppliedRule.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/AppliedRule.py?rev=26733&r1=26732&r2=26733&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/AppliedRule.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/AppliedRule.py [utf8] Thu Apr 30 12:52:03 2009
@@ -206,28 +206,54 @@
         return self
       return self.getParentValue().getRootAppliedRule()
 
+    def _getExplanationSpecialiseValue(self, portal_type_list):
+      """Returns first found specialise value of delivery or order
+      In case if self is root Applied Rule uses causality
+      Otherwise uses delivery, than order of parent movements
+      Recurses to parents"""
+      def findSpecialiseValueBySimulation(movement):
+        specialise_value = None
+        if movement.getPortalType() != 'Simulation Movement':
+          return None
+        delivery, order = movement.getDeliveryValue(), movement.getOrderValue()
+
+        if delivery is not None:
+          specialise_value = delivery.getExplanationValue() \
+              .getRootSpecialiseValue(portal_type_list)
+          if specialise_value is not None:
+            return specialise_value
+        if order is not None:
+          specialise_value = order.getExplanationValue() \
+              .getRootSpecialiseValue(portal_type_list)
+          if specialise_value is not None:
+            return specialise_value
+        return findSpecialiseValueBySimulation(movement.getParentValue() \
+            .getParentValue())
+
+      if self.getRootAppliedRule() == self:
+        return self.getCausalityValue() \
+            .getRootSpecialiseValue(portal_type_list)
+      movement = self.getParentValue()
+      return findSpecialiseValueBySimulation(movement)
+
+
+    security.declareProtected(Permissions.AccessContentsInformation,
+                             'getTradeConditionValue')
+    def getTradeConditionValue(self):
+      """Return the trade condition that has been used in this
+      simulation, or None if none has been used.
+      """
+      return self._getExplanationSpecialiseValue(
+          ('Purchase Trade Condition', 'Sale Trade Condition'))
+
     security.declareProtected(Permissions.AccessContentsInformation,
                              'getBusinessProcessValue')
     def getBusinessProcessValue(self):
       """Return the business process model that has been used in this
-      simulation, or None if no business process has been used.
-      """
-      root = self.getRootAppliedRule()
-      causality = root.getCausalityValue()
-
-      def findBusinessProcessModel(context):
-        if context.getPortalType() == 'Business Process':
-          return context
-        for specialise in context.getSpecialiseValueList():
-          business_process = findBusinessProcessModel(specialise)
-          if business_process is not None:
-            return business_process
-
-      if causality is not None and getattr(causality, 'getSpecialiseValueList',
-                                            None) is not None:
-        return findBusinessProcessModel(causality)
-
-      return None
+      simulation, or None if none  has been used.
+      """
+      return self._getExplanationSpecialiseValue(
+          ('Business Process',))
 
     security.declareProtected(Permissions.ModifyPortalContent,
                               'notifySimulationChange')

Modified: erp5/trunk/products/ERP5/Document/Delivery.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Delivery.py?rev=26733&r1=26732&r2=26733&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Delivery.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Delivery.py [utf8] Thu Apr 30 12:52:03 2009
@@ -884,3 +884,19 @@
       else:
         raise 'SimulationError', '%s_getRuleReference script is missing.' \
               % self.getPortalType()
+
+    security.declareProtected( Permissions.AccessContentsInformation,
+                               'getRootSpecialiseValue')
+    def getRootSpecialiseValue(self, portal_type_list):
+      """Returns first specialise value matching portal type"""
+      def findSpecialiseValue(context):
+        if context.getPortalType() in portal_type_list:
+          return context
+        if getattr(context, 'getSpecialiseValueList', None) is not None:
+          for specialise in context.getSpecialiseValueList():
+            specialise_value = findSpecialiseValue(specialise)
+            if specialise_value is not None:
+              return specialise_value
+        return None
+      return findSpecialiseValue(self)
+




More information about the Erp5-report mailing list