From 502b45d5bace3d71e89e9343634b806c4db976be Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 11 Oct 2005 15:17:45 +0000
Subject: [PATCH] unify the implementation of getExplanation[Value, Uid]

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3995 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/SimulationMovement.py | 63 ++++++++-------------
 1 file changed, 25 insertions(+), 38 deletions(-)

diff --git a/product/ERP5/Document/SimulationMovement.py b/product/ERP5/Document/SimulationMovement.py
index b662c5843e..5dbee75893 100755
--- a/product/ERP5/Document/SimulationMovement.py
+++ b/product/ERP5/Document/SimulationMovement.py
@@ -310,61 +310,48 @@ class SimulationMovement(Movement):
     """
     return self.getRootAppliedRule().hasActivity(**kw)
 
-  security.declareProtected(Permissions.AccessContentsInformation, 'getExplanation')
+  security.declareProtected( Permissions.AccessContentsInformation,
+                             'getExplanation')
   def getExplanation(self):
+    """Returns the delivery's relative_url if any or the order's
+    relative_url related to the root applied rule if any.
     """
-      Returns the delivery if any or the order related to the root applied rule if any
-      Name should be changed to generic name (getExplanationUid)
-    """
-    if self.getDeliveryValue() is None:
-      ra = self.getRootAppliedRule()
-      order = ra.getCausalityValue()
-      if order is not None:
-        return order.getRelativeUrl()
-      else:
-        # Ex. zero stock rule
-        return ra.getRelativeUrl()
-    else:
-      return self.getDelivery()
+    explanation_value = self.getExplanationValue()
+    if explanation_value is not None :
+      return explanation_value.getRelativeUrl()
 
-  security.declareProtected(Permissions.AccessContentsInformation, 'getExplanationUid')
+  security.declareProtected( Permissions.AccessContentsInformation,
+                             'getExplanationUid')
   def getExplanationUid(self):
+    """Returns the delivery's uid if any or the order's uid related to
+    the root applied rule if any.
     """
-      Returns the delivery if any or the order related to the root applied rule if any
-      Name should be changed to generic name (getExplanationUid)
+    explanation_value = self.getExplanationValue()
+    if explanation_value is not None :
+      return explanation_value.getUid()
+    
+  security.declareProtected( Permissions.AccessContentsInformation,
+                             'getExplanationValue')
+  def getExplanationValue(self):
+    """Returns the delivery if any or the order related to the root
+    applied rule if any.
     """
     if self.getDeliveryValue() is None:
       ra = self.getRootAppliedRule()
       order = ra.getCausalityValue()
       if order is not None:
-        return order.getUid()
+        return order
       else:
         # Ex. zero stock rule
-        return ra.getUid()
+        return ra
     else:
       explanation_value = self.getDeliveryValue()
-      while explanation_value.getPortalType() not in self.getPortalDeliveryTypeList() and \
+      while explanation_value.getPortalType() not in \
+              self.getPortalDeliveryTypeList() and \
           explanation_value != self.getPortalObject():
             explanation_value = explanation_value.getParent()
       if explanation_value != self.getPortalObject():
-        return explanation_value.getUid()
-
-  security.declareProtected(Permissions.AccessContentsInformation, 'getExplanationValue')
-  def getExplanationValue(self):
-    """
-      Returns the delivery if any or the order related to the root applied rule if any
-      Name should be changed to generic name (getExplanationUid)
-    """
-    if self.getDeliveryValue() is None:
-      ra = self.getRootAppliedRule()
-      order = ra.getCausalityValue()
-      if order is not None:
-        return order
-      else:
-        # Ex. zero stock rule
-        return ra
-    else:
-      return self.getDeliveryValue()
+        return explanation_value
 
   def isFrozen(self):
     """
-- 
2.30.9