From 969d5560101f8230beaef4c9ac34b4662453d74f Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Sun, 7 Nov 2010 03:12:22 +0000
Subject: [PATCH] Fix Delivery_updateAppliedRule on Zope 2.12

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40005 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_base/Delivery_updateAppliedRule.xml             | 8 ++++++--
 bt5/erp5_base/bt/revision                                | 2 +-
 product/ERP5/Document/Delivery.py                        | 9 +++++----
 product/ERP5/Document/SubscriptionItem.py                | 9 +++++----
 product/ERP5Type/Errors.py                               | 2 ++
 5 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_updateAppliedRule.xml b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_updateAppliedRule.xml
index c83c3aae9d..3cc06b4bf4 100644
--- a/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_updateAppliedRule.xml
+++ b/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Delivery_updateAppliedRule.xml
@@ -50,7 +50,9 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>delivery = context\n
+            <value> <string>from Products.ERP5Type.Errors import SimulationError\n
+\n
+delivery = context\n
 delivery_type = context.getPortalType()\n
 \n
 # XXX The following dict is only for backward compatibility.\n
@@ -80,7 +82,7 @@ applied_rule_dict = {\n
 \n
 try:\n
   applied_rule = delivery.getRuleReference()\n
-except \'SimulationError\':\n
+except SimulationError:\n
   marker = []\n
   applied_rule = applied_rule_dict.get(delivery_type, marker)\n
   if applied_rule is marker:\n
@@ -133,6 +135,8 @@ elif applied_rule:\n
                           <tuple>
                             <string>activate_kw</string>
                             <string>kw</string>
+                            <string>Products.ERP5Type.Errors</string>
+                            <string>SimulationError</string>
                             <string>context</string>
                             <string>delivery</string>
                             <string>_getattr_</string>
diff --git a/bt5/erp5_base/bt/revision b/bt5/erp5_base/bt/revision
index 523780a1a7..3f7ea5fb78 100644
--- a/bt5/erp5_base/bt/revision
+++ b/bt5/erp5_base/bt/revision
@@ -1 +1 @@
-894
\ No newline at end of file
+895
\ No newline at end of file
diff --git a/product/ERP5/Document/Delivery.py b/product/ERP5/Document/Delivery.py
index 9ce8691b19..25594acbc8 100644
--- a/product/ERP5/Document/Delivery.py
+++ b/product/ERP5/Document/Delivery.py
@@ -34,6 +34,7 @@ from Products.CMFCore.utils import getToolByName
 from AccessControl import ClassSecurityInfo
 from Products.ERP5Type import Permissions, PropertySheet, interfaces
 from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter
+from Products.ERP5Type.Errors import SimulationError
 from Products.ERP5Type.XMLObject import XMLObject
 from Products.ERP5.Document.ImmobilisationDelivery import ImmobilisationDelivery
 from Products.ERP5.mixin.amount_generator import AmountGeneratorMixin
@@ -765,8 +766,8 @@ class Delivery(XMLObject, ImmobilisationDelivery,
         # Re expand the rule if possible
         my_applied_rule = my_applied_rule_list[0]
       else:
-        raise "SimulationError", 'Delivery %s has more than one applied'\
-            ' rule.' % self.getRelativeUrl()
+        raise SimulationError('Delivery %s has more than one applied'
+                              ' rule.' % self.getRelativeUrl())
 
       my_applied_rule_id = None
       expand_activate_kw = {}
@@ -917,8 +918,8 @@ class Delivery(XMLObject, ImmobilisationDelivery,
       if method is not None:
         return method()
       else:
-        raise 'SimulationError', '%s_getRuleReference script is missing.' \
-              % self.getPortalType().replace(' ', '')
+        raise SimulationError('%s_getRuleReference script is missing.'
+                              % self.getPortalType().replace(' ', ''))
 
     security.declareProtected( Permissions.AccessContentsInformation,
                                'getRootSpecialiseValue')
diff --git a/product/ERP5/Document/SubscriptionItem.py b/product/ERP5/Document/SubscriptionItem.py
index 1cde3d8e67..83f1974a4b 100644
--- a/product/ERP5/Document/SubscriptionItem.py
+++ b/product/ERP5/Document/SubscriptionItem.py
@@ -32,6 +32,7 @@ from AccessControl import ClassSecurityInfo
 
 from Products.CMFCore.utils import getToolByName
 from Products.ERP5Type import Permissions, PropertySheet, interfaces
+from Products.ERP5Type.Errors import SimulationError
 from Products.ERP5.Document.Item import Item
 from Products.ERP5.mixin.rule import MovementGeneratorMixin
 from Products.ERP5.mixin.periodicity import PeriodicityMixin
@@ -119,8 +120,8 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
         rule_value_list = portal_rules.searchRuleList(self, 
                  tested_base_category_list=tested_base_category_list)
         if len(rule_value_list) > 1:
-          raise "SimulationError", 'Expandable Document %s has more than one matching'\
-                                   ' rule.' % self.getRelativeUrl()
+          raise SimulationError('Expandable Document %s has more than one'
+                                ' matching rule.' % self.getRelativeUrl())
         if len(rule_value_list):
           rule_value = rule_value_list[0]
           my_applied_rule = rule_value.constructNewAppliedRule(portal_simulation,
@@ -134,8 +135,8 @@ class SubscriptionItem(Item, MovementGeneratorMixin, PeriodicityMixin):
       # Re expand the rule if possible
       my_applied_rule = my_applied_rule_list[0]
     else:
-      raise "SimulationError", 'Expandable Document %s has more than one root applied'\
-          ' rule.' % self.getRelativeUrl()
+      raise SimulationError('Expandable Document %s has more than one root'
+                            ' applied rule.' % self.getRelativeUrl())
 
     return my_applied_rule
 
diff --git a/product/ERP5Type/Errors.py b/product/ERP5Type/Errors.py
index 88f6e5f960..f599412f66 100644
--- a/product/ERP5Type/Errors.py
+++ b/product/ERP5Type/Errors.py
@@ -42,6 +42,7 @@ class UnsupportedWorkflowMethod(WorkflowException):
 class ImmobilisationValidityError(Exception):pass
 class ImmobilisationCalculationError(Exception):pass
 class TransformationRuleError(Exception):pass
+class SimulationError(Exception):pass
 
 
 allow_class(DeferredCatalogError)
@@ -51,3 +52,4 @@ allow_class(ImmobilisationCalculationError)
 allow_class(WorkflowException)
 allow_class(UnsupportedWorkflowMethod)
 allow_class(TransformationRuleError)
+allow_class(SimulationError)
-- 
2.30.9