From 5ec1ebf1e8116033e82167094680785c23f4af52 Mon Sep 17 00:00:00 2001
From: Alexandre Boeglin <alex@nexedi.com>
Date: Mon, 3 Apr 2006 17:15:31 +0000
Subject: [PATCH] fixed not correctly initialized variables by putting them in
 a _check_catalog method and calling it from install, as when importing, build
 is called with no_action=1.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6441 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/Alarm.py               | 18 ++++++++++++++++--
 product/ERP5/Document/Amount.py              |  7 ++++++-
 product/ERP5/Document/BusinessTemplate.py    |  4 ++++
 product/ERP5/Document/SimulationMovement.py  |  2 ++
 product/ERP5/Document/TransformedResource.py |  4 +++-
 product/ERP5/PropertySheet/Person.py         |  3 +--
 product/ERP5/Tool/CategoryTool.py            |  6 +++---
 7 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/product/ERP5/Document/Alarm.py b/product/ERP5/Document/Alarm.py
index f2c8a45f29..2a480c9f5f 100644
--- a/product/ERP5/Document/Alarm.py
+++ b/product/ERP5/Document/Alarm.py
@@ -34,6 +34,7 @@ from Products.ERP5.Document.Periodicity import Periodicity
 from Products.CMFCore.WorkflowCore import WorkflowMethod
 from Acquisition import aq_base, aq_parent, aq_inner, aq_acquire
 from Products.CMFCore.utils import getToolByName
+from Products.PageTemplates.Expressions import getEngine
 from DateTime import DateTime
 
 from zLOG import LOG
@@ -81,6 +82,17 @@ class Alarm(Periodicity, XMLObject):
       """
       return self.hasActivity()
 
+    def callActiveSenseMethod(self, tales_expression):
+      """
+      This resolves the active_sense_method, and calls it
+      """
+      context = {  'here' : self.aq_parent,
+                'context' : self.aq_parent,
+                'request' : None }
+
+      compiled_tales = getEngine().compile(tales_expression)
+      return getEngine().getContext(context).evaluate(compiled_tales) 
+
     security.declareProtected(Permissions.ModifyPortalContent, 'activeSense')
     def activeSense(self):
       """
@@ -99,8 +111,10 @@ class Alarm(Periodicity, XMLObject):
       self.reindexObject()
       method_id = self.getActiveSenseMethodId()
       if method_id is not None:
-        method = getattr(self.activate(),method_id)
-        return method()
+        return self.activate().callActiveSenseMethod(method_id)
+#        method = getattr(self.activate(),method_id)
+#        return method()
+        s
 
     security.declareProtected(Permissions.ModifyPortalContent, 'sense')
     def sense(self):
diff --git a/product/ERP5/Document/Amount.py b/product/ERP5/Document/Amount.py
index 5519648524..f47ce32024 100644
--- a/product/ERP5/Document/Amount.py
+++ b/product/ERP5/Document/Amount.py
@@ -306,7 +306,12 @@ class Amount(Base, Variated):
         raise KeyError, "Can not set the property variation '%s'" % \
                         property_id
       else:
-        self.setProperty(property_id, property_value)
+        try:
+          self.setProperty(property_id, property_value)
+        except KeyError:
+          LOG("Amount", 200, "Can not set %s with value %s on %s" % \
+                    (property_id, property_value, self.getRelativeUrl()))
+          raise
 
   security.declareProtected(Permissions.AccessContentsInformation,
                                                  'getQuantityUnitRangeItemList')
diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index c0287f324b..2628f536bb 100644
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -1395,6 +1395,9 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
 
   def build(self, context, **kw):
     ObjectTemplateItem.build(self, context, **kw)
+    self._check_catalog(context)
+
+  def _check_catalog(self, context):
     try:
       catalog = context.portal_catalog.getSQLCatalog()
     except KeyError:
@@ -1471,6 +1474,7 @@ class CatalogMethodTemplateItem(ObjectTemplateItem):
 
   def install(self, context, trashbin, **kw):
     ObjectTemplateItem.install(self, context, trashbin, **kw)
+    self._check_catalog(context)
     try:
       catalog = context.portal_catalog.getSQLCatalog()
     except KeyError:
diff --git a/product/ERP5/Document/SimulationMovement.py b/product/ERP5/Document/SimulationMovement.py
index 21bd1edb95..ccec9c7682 100644
--- a/product/ERP5/Document/SimulationMovement.py
+++ b/product/ERP5/Document/SimulationMovement.py
@@ -454,6 +454,8 @@ class SimulationMovement(Movement):
        self.getResource()           != delivery.getResource() or \
        self.getVariationCategoryList() != delivery.getVariationCategoryList()\
                                                                        or \
+       #self.getAggregateValueList() != delivery.getAggregateValueList()\
+                                                                       or \
        self.getAggregateList() != delivery.getAggregateList() or \
        self.getStartDate()          != delivery.getStartDate() or \
        self.getStopDate()           != delivery.getStopDate():
diff --git a/product/ERP5/Document/TransformedResource.py b/product/ERP5/Document/TransformedResource.py
index ba039db6e9..6a2d656fe1 100644
--- a/product/ERP5/Document/TransformedResource.py
+++ b/product/ERP5/Document/TransformedResource.py
@@ -329,6 +329,8 @@ class TransformedResource(Predicate, XMLObject, XMLMatrix, Amount):
         )
         tmp_amount.setVariationCategoryList(variation_category_list)
         # Variation property dict
-        tmp_amount.setVariationPropertyDict(self.getVariationPropertyDict())
+
+        prop_dict = self.getVariationPropertyDict()
+        tmp_amount.setVariationPropertyDict(prop_dict)
         aggregated_amount_list.append(tmp_amount)
       return aggregated_amount_list
diff --git a/product/ERP5/PropertySheet/Person.py b/product/ERP5/PropertySheet/Person.py
index fb89dd3107..969a088dfa 100644
--- a/product/ERP5/PropertySheet/Person.py
+++ b/product/ERP5/PropertySheet/Person.py
@@ -182,7 +182,7 @@ class Person:
     , 'storage_id'          : 'default_career'
     , 'description'         : 'The default career hold some properties of a Person.'
     , 'type'                : 'content'
-    , 'portal_type'         : ( 'Career', )
+    , 'portal_type'         : 'Career'
     , 'acquired_property_id': ( 'start_date', 'stop_date', 'title', 'description'
                               , 'subordination', 'subordination_title', 'subordination_value'
                               , 'subordination_uid_list', 'subordination_uid'
@@ -193,7 +193,6 @@ class Person:
                               , 'role', 'role_id', 'role_title', 'role_value'
                               , 'function', 'function_id', 'function_title', 'function_value'
                               )
-    , 'deprecated'          : 1
     , 'mode'                : 'w'
     },
   )
diff --git a/product/ERP5/Tool/CategoryTool.py b/product/ERP5/Tool/CategoryTool.py
index 7cb849f5e5..f1ff6e8faa 100644
--- a/product/ERP5/Tool/CategoryTool.py
+++ b/product/ERP5/Tool/CategoryTool.py
@@ -103,8 +103,8 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
               my_base_category = base_category
             bo = getattr(self, my_base_category, None)
             if bo is not None:
-              bo_uid = int(bo.getUid())
-              uid_dict[(int(o.uid), bo_uid, 1)] = 1 # Strict membership
+              bo_uid = bo.getUid()
+              uid_dict[(o.getUid(), bo_uid, 1)] = 1 # Strict membership
               if o.meta_type == 'ERP5 Category' or o.meta_type == 'ERP5 Base Category' or \
                 o.meta_type == 'CMF Category' or o.meta_type == 'CMF Base Category':
                 # This goes up in the category tree
@@ -113,7 +113,7 @@ class CategoryTool(CopyContainer, CMFCategoryTool, BaseTool):
                 if not strict:
                   while o.meta_type == 'ERP5 Category' or o.meta_type == 'CMF Category':
                     o = o.aq_parent
-                    uid_dict[(int(o.uid), bo_uid, 0)] = 1 # Non strict
+                    uid_dict[(o.getUid(), bo_uid, 0)] = 1 # Non strict
         except (TypeError, KeyError):
           LOG('WARNING: CategoriesTool',0, 'Unable to find uid for %s' % path)
       return uid_dict.keys()
-- 
2.30.9