From 10506558d53268bf59026517f2bb1f67e84e7f13 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Fri, 28 Jan 2011 15:47:42 +0000
Subject: [PATCH] * support 'Paths of objects whose workflow history should be
 kept' and 'Paths of objects that should be kept' in Business Template
 definition. * support more 'Removed but ...' and 'Modified but ...' cases in
 business template installation dialogue.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42752 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BusinessTemplate.py     |  47 ++-
 .../erp5_core/BusinessTemplate_getDiffUrl.xml |   2 +-
 .../BusinessTemplate_getModifiedObject.xml    |   4 +-
 .../my_template_keep_path_list.xml            | 298 ++++++++++++++++++
 .../my_template_keep_workflow_path_list.xml   | 298 ++++++++++++++++++
 .../listbox_choice.xml                        |   2 +-
 .../TemplateTool_getDetailedDiff.xml          |   2 +-
 .../TemplateTool_getModifiedObjectList.xml    |   4 +-
 .../listbox_choice.xml                        |   2 +-
 .../ERP5/bootstrap/erp5_core/bt/change_log    |   4 +
 product/ERP5/bootstrap/erp5_core/bt/revision  |   2 +-
 .../PropertySheet/BusinessTemplate.py         |  10 +
 12 files changed, 664 insertions(+), 11 deletions(-)
 create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_path_list.xml
 create mode 100644 product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_workflow_path_list.xml

diff --git a/product/ERP5/Document/BusinessTemplate.py b/product/ERP5/Document/BusinessTemplate.py
index d4d935c80e..a59568d90d 100644
--- a/product/ERP5/Document/BusinessTemplate.py
+++ b/product/ERP5/Document/BusinessTemplate.py
@@ -839,10 +839,16 @@ class ObjectTemplateItem(BaseTemplateItem):
         new_io.close()
         old_io.close()
         if new_obj_xml != old_obj_xml:
-          modified_object_list[path] = 'Modified', type_name
+          if context.isKeepObject(path):
+            modified_object_list[path] = 'Modified but should be kept', type_name
+          else:
+            modified_object_list[path] = 'Modified', type_name
       # get removed object
       for path in set(installed_item._objects) - set(self._objects):
-        modified_object_list[path] = 'Removed', type_name
+        if context.isKeepObject(path):
+          modified_object_list[path] = 'Removed but should be kept', type_name
+        else:
+          modified_object_list[path] = 'Removed', type_name
     return modified_object_list
 
   def _backupObject(self, action, trashbin, container_path, object_id, **kw):
@@ -966,6 +972,10 @@ class ObjectTemplateItem(BaseTemplateItem):
             action = update_dict[path]
             if action == 'nothing':
               continue
+          elif context.isKeepObject(path):
+            # do nothing if the object is specified in keep list in
+            # force mode.
+            continue
           # get subobjects in path
           path_list = path.split('/')
           container_path = path_list[:-1]
@@ -993,6 +1003,7 @@ class ObjectTemplateItem(BaseTemplateItem):
           saved_uid_dict = {}
           subobjects_dict = {}
           portal_type_dict = {}
+          workflow_history = None
           old_obj = container._getOb(object_id, None)
           object_existed = old_obj is not None
           if old_obj is not None:
@@ -1015,6 +1026,11 @@ class ObjectTemplateItem(BaseTemplateItem):
                 portal_type_dict[attr] = getattr(old_obj, attr, ())
               portal_type_dict['workflow_chain'] = \
                 getChainByType(context)[1].get('chain_' + object_id, '')
+            # try to keep workflow history for specified objects.
+            workflow_history = getattr(old_obj, 'workflow_history', None)
+            if workflow_history is not None \
+                   and context.isKeepWorkflowObject(path):
+                workflow_history = deepcopy(workflow_history)
             container.manage_delObjects([object_id])
 
           # install object
@@ -1093,6 +1109,9 @@ class ObjectTemplateItem(BaseTemplateItem):
                 # an object which cannot (e.g. External Method).
                 LOG('BusinessTemplate', WARNING,
                     'could not restore %r in %r' % (subobject_id, obj))
+          # copy workflow history if required
+          if workflow_history is not None:
+            setattr(obj, 'workflow_history', workflow_history)
           if obj.meta_type in ('Z SQL Method',):
             fixZSQLMethod(portal, obj)
           # portal transforms specific initialization
@@ -5044,6 +5063,30 @@ Business Template is a set of definitions, such as skins, portal types and categ
       """
       return self._getOrderedList('template_tool_id')
 
+    def isKeepObject(self, path):
+      """
+      Return True if path is included in keep object list.
+      """
+      keep_list = self.getTemplateKeepPathList()
+      for keep_path in keep_list:
+        if keep_path.endswith('**') and path.startswith(keep_path[:-2]):
+          return True
+        elif path == keep_path:
+          return True
+      return False
+
+    def isKeepWorkflowObject(self, path):
+      """
+      Return True if path is included in keep workflow object list.
+      """
+      keep_list = self.getTemplateKeepWorkflowPathList()
+      for keep_path in keep_list:
+        if keep_path.endswith('**') and path.startswith(keep_path[:-2]):
+          return True
+        elif path == keep_path:
+          return True
+      return False
+
     security.declareProtected(Permissions.ManagePortal, 'export')
     def export(self, path=None, local=0, **kw):
       """
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getDiffUrl.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getDiffUrl.xml
index 1e83f5b054..81637e8bc6 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getDiffUrl.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getDiffUrl.xml
@@ -54,7 +54,7 @@
 
 from Products.PythonScripts.standard import html_quote\n
 \n
-if brain.object_state == \'Modified\':\n
+if brain.object_state.startswith(\'Modified\'):\n
   target_object = brain.getObject()\n
   parent_absolute_path = target_object.aq_parent.absolute_url()\n
   if hasattr(brain, \'bt1\'):\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getModifiedObject.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getModifiedObject.xml
index 86a816e29d..c3a617ca1b 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getModifiedObject.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_getModifiedObject.xml
@@ -99,12 +99,12 @@ for object_id in keys:\n
   line = newTempBase(context, \'tmp_install_%s\' %(str(i)))\n
   if object_state == \'New\':\n
     choice_item_list=[[install_title, \'install\']]\n
-  elif object_state == \'Modified\':\n
+  elif object_state.startswith(\'Modified\'):\n
     if object_class in no_backup_dict:\n
       choice_item_list=[[upgrade_title, \'install\']]\n
     else:\n
       choice_item_list=[[backup_title, \'backup\']]\n
-  elif object_state in (\'Removed\', \'Removed but used\'):\n
+  elif object_state.startswith(\'Removed\'):\n
     if object_class in no_backup_dict:\n
       choice_item_list=[[remove_title, \'remove\']]\n
     else:\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_path_list.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_path_list.xml
new file mode 100644
index 0000000000..9b39e7a454
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_path_list.xml
@@ -0,0 +1,298 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="LinesField" module="Products.Formulator.StandardFields"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>my_template_keep_path_list</string> </value>
+        </item>
+        <item>
+            <key> <string>message_values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>external_validator_failed</string> </key>
+                    <value> <string>The input failed the external validator.</string> </value>
+                </item>
+                <item>
+                    <key> <string>line_too_long</string> </key>
+                    <value> <string>A line was too long.</string> </value>
+                </item>
+                <item>
+                    <key> <string>required_not_found</string> </key>
+                    <value> <string>Input is required but no input given.</string> </value>
+                </item>
+                <item>
+                    <key> <string>too_long</string> </key>
+                    <value> <string>You entered too many characters.</string> </value>
+                </item>
+                <item>
+                    <key> <string>too_many_lines</string> </key>
+                    <value> <string>You entered too many lines.</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>overrides</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>height</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_length</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_linelength</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_lines</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>view_separator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>width</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>tales</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>height</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_length</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_linelength</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_lines</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>view_separator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>width</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>height</string> </key>
+                    <value> <int>10</int> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>max_length</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_linelength</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_lines</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string>Paths of objects that should be kept</string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>view_separator</string> </key>
+                    <value> <string encoding="cdata"><![CDATA[
+
+<br/>
+
+]]></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>width</string> </key>
+                    <value> <int>80</int> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_workflow_path_list.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_workflow_path_list.xml
new file mode 100644
index 0000000000..8f16d11327
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_view/my_template_keep_workflow_path_list.xml
@@ -0,0 +1,298 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="LinesField" module="Products.Formulator.StandardFields"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>my_template_keep_workflow_path_list</string> </value>
+        </item>
+        <item>
+            <key> <string>message_values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>external_validator_failed</string> </key>
+                    <value> <string>The input failed the external validator.</string> </value>
+                </item>
+                <item>
+                    <key> <string>line_too_long</string> </key>
+                    <value> <string>A line was too long.</string> </value>
+                </item>
+                <item>
+                    <key> <string>required_not_found</string> </key>
+                    <value> <string>Input is required but no input given.</string> </value>
+                </item>
+                <item>
+                    <key> <string>too_long</string> </key>
+                    <value> <string>You entered too many characters.</string> </value>
+                </item>
+                <item>
+                    <key> <string>too_many_lines</string> </key>
+                    <value> <string>You entered too many lines.</string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>overrides</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>height</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_length</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_linelength</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_lines</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>view_separator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>width</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>tales</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>height</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_length</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_linelength</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_lines</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>view_separator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>width</string> </key>
+                    <value> <string></string> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+        <item>
+            <key> <string>values</string> </key>
+            <value>
+              <dictionary>
+                <item>
+                    <key> <string>alternate_name</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>css_class</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>default</string> </key>
+                    <value>
+                      <list/>
+                    </value>
+                </item>
+                <item>
+                    <key> <string>description</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>editable</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>enabled</string> </key>
+                    <value> <int>1</int> </value>
+                </item>
+                <item>
+                    <key> <string>external_validator</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>extra</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>height</string> </key>
+                    <value> <int>10</int> </value>
+                </item>
+                <item>
+                    <key> <string>hidden</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>max_length</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_linelength</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>max_lines</string> </key>
+                    <value> <string></string> </value>
+                </item>
+                <item>
+                    <key> <string>required</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>title</string> </key>
+                    <value> <string>Paths of objects whose workflow histories should be kept</string> </value>
+                </item>
+                <item>
+                    <key> <string>unicode</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>view_separator</string> </key>
+                    <value> <string encoding="cdata"><![CDATA[
+
+<br/>
+
+]]></string> </value>
+                </item>
+                <item>
+                    <key> <string>whitespace_preserve</string> </key>
+                    <value> <int>0</int> </value>
+                </item>
+                <item>
+                    <key> <string>width</string> </key>
+                    <value> <int>80</int> </value>
+                </item>
+              </dictionary>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewInstallationDialog/listbox_choice.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewInstallationDialog/listbox_choice.xml
index ab700506cb..defc46ba94 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewInstallationDialog/listbox_choice.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/BusinessTemplate_viewInstallationDialog/listbox_choice.xml
@@ -253,7 +253,7 @@
       <dictionary>
         <item>
             <key> <string>_text</string> </key>
-            <value> <string>python:(cell.choice_item_list and cell.object_state != \'Removed but used\') and cell.choice_item_list[0][1] or []</string> </value>
+            <value> <string>python:(cell.choice_item_list and \' but \' not in cell.object_state) and cell.choice_item_list[0][1] or []</string> </value>
         </item>
       </dictionary>
     </pickle>
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getDetailedDiff.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getDetailedDiff.xml
index 9bb4adbaad..a8f01dc9f5 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getDetailedDiff.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getDetailedDiff.xml
@@ -88,7 +88,7 @@ for diff_object in context.BusinessTemplate_getDiffObjectList():\n
   if link == 1: \n
     print \'</a>\'\n
   print \'</div>\'\n
-  if diff_object.object_state == "Modified":\n
+  if diff_object.object_state.startswith(\'Modified\'):\n
     request.set(\'bt1\', diff_object.bt1)\n
     request.set(\'bt2\', diff_object.bt2)\n
     request.set(\'object_id\', diff_object.object_id)\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getModifiedObjectList.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getModifiedObjectList.xml
index 3cb0ced476..4982ca8006 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getModifiedObjectList.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_getModifiedObjectList.xml
@@ -104,12 +104,12 @@ for bt in bt_id_list:\n
     object_id = bt+\'|\'+object_id\n
     line = newTempBase(context, \'tmp_install_%s\' % i)\n
 \n
-    if object_state == \'Modified\':\n
+    if object_state.startswith(\'Modified\'):\n
       if object_class in no_backup_dict:\n
         choice_item_list = [[upgrade_title, \'install\']]\n
       else:\n
         choice_item_list = [[backup_title, \'backup\']]\n
-    elif object_state in (\'Removed\', \'Removed but used\'):\n
+    elif object_state.startswith(\'Removed\'):\n
       if object_class in no_backup_dict:\n
         choice_item_list = [[remove_title, \'remove\']]\n
       else:\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_viewMultiInstallationDialog/listbox_choice.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_viewMultiInstallationDialog/listbox_choice.xml
index ab700506cb..defc46ba94 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_viewMultiInstallationDialog/listbox_choice.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/TemplateTool_viewMultiInstallationDialog/listbox_choice.xml
@@ -253,7 +253,7 @@
       <dictionary>
         <item>
             <key> <string>_text</string> </key>
-            <value> <string>python:(cell.choice_item_list and cell.object_state != \'Removed but used\') and cell.choice_item_list[0][1] or []</string> </value>
+            <value> <string>python:(cell.choice_item_list and \' but \' not in cell.object_state) and cell.choice_item_list[0][1] or []</string> </value>
         </item>
       </dictionary>
     </pickle>
diff --git a/product/ERP5/bootstrap/erp5_core/bt/change_log b/product/ERP5/bootstrap/erp5_core/bt/change_log
index cc7fb06f2b..013fb869d5 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/change_log
+++ b/product/ERP5/bootstrap/erp5_core/bt/change_log
@@ -1,3 +1,7 @@
+2011-01-28 Kazuhiko
+* support 'Paths of objects whose workflow history should be kept' and 'Paths of objects that should be kept' in Business Template definition.
+* support more 'Removed but ...' and 'Modified but ...' cases in business template installation dialogue.
+
 2011-01-13 nicolas.dumazet
 * add portal types for Tools bundled in erp5_core: Notification Tool was missing
 
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index e53d028bfd..7d51de9581 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-40857
\ No newline at end of file
+40858
\ No newline at end of file
diff --git a/product/ERP5PropertySheetLegacy/PropertySheet/BusinessTemplate.py b/product/ERP5PropertySheetLegacy/PropertySheet/BusinessTemplate.py
index b010977734..fa51c122f0 100644
--- a/product/ERP5PropertySheetLegacy/PropertySheet/BusinessTemplate.py
+++ b/product/ERP5PropertySheetLegacy/PropertySheet/BusinessTemplate.py
@@ -211,6 +211,16 @@ class BusinessTemplate:
       'type'        : 'lines',
       'mode'        : 'w',
       'default'     : () },
+    { 'id'          : 'template_keep_path',
+      'description' : 'A list of object paths that should be kept in installing this template',
+      'type'        : 'lines',
+      'mode'        : 'w',
+      'default'     : () },
+    { 'id'          : 'template_keep_workflow_path',
+      'description' : 'A list of object paths whose workflow history should be kept in installing this template',
+      'type'        : 'lines',
+      'mode'        : 'w',
+      'default'     : () },
     { 'id'          : 'template_preference',
       'description' : 'A list of preferences used by this template',
       'type'        : 'lines',
-- 
2.30.9