From 848ab96637f7874004791b01ba4a6e8cf6fad6e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aur=C3=A9lien=20Calonne?= <aurel@nexedi.com>
Date: Fri, 11 Jan 2008 16:13:54 +0000
Subject: [PATCH] if we installed a new category, generate new accessors

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18668 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BusinessTemplate.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index f697065471..866c4be3d2 100644
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -31,7 +31,7 @@ from Globals import Persistent, PersistentMapping
 from Acquisition import Implicit, aq_base
 from AccessControl import ClassSecurityInfo
 from Products.CMFCore.utils import getToolByName
-from Products.ERP5Type.Base import WorkflowMethod
+from Products.ERP5Type.Base import WorkflowMethod, _aq_reset
 from Products.ERP5Type.Utils import readLocalDocument, \
                                     writeLocalDocument, \
                                     importLocalDocument, \
@@ -1085,6 +1085,7 @@ class CategoryTemplateItem(ObjectTemplateItem):
   def install(self, context, trashbin, **kw):
     update_dict = kw.get('object_to_update')
     force = kw.get('force')
+    new_category = False
     if context.getTemplateFormatVersion() == 1:
       portal = context.getPortalObject()
       category_tool = portal.portal_categories
@@ -1121,6 +1122,9 @@ class CategoryTemplateItem(ObjectTemplateItem):
             object_uid = container[category_id].getUid()
             subobjects_dict = self._backupObject(action, trashbin, container_path, category_id)
             container.manage_delObjects([category_id])
+          else:
+            # mark that we installed a new category to call aq_reset later
+            new_category = True
           category = container.newContent(portal_type=obj.getPortalType(), id=category_id)
           if object_uid is not None:
             category.setUid(object_uid)
@@ -1163,6 +1167,9 @@ class CategoryTemplateItem(ObjectTemplateItem):
           # XXX call backup here
           subobjects_dict = self._backupObject('backup', trashbin, container_path, category_id)
           container.manage_delObjects([category_id])
+        else:
+          # mark that we installed a new category to call aq_reset later
+          new_category = True
         category = container.newContent(portal_type=obj.getPortalType(), id=category_id)
         for prop in obj.propertyIds():
           if prop not in ('id', 'uid'):
@@ -1186,7 +1193,10 @@ class CategoryTemplateItem(ObjectTemplateItem):
             subobject = connection.importFile(subobject_data)
             if subobject_id not in category.objectIds():
               category._setObject(subobject_id, subobject)
-
+    if new_category:
+      # reset accessors if we installed a new category
+      _aq_reset()
+              
 
 class SkinTemplateItem(ObjectTemplateItem):
 
-- 
2.30.9