From f520862729884523ca3aeec304e524b4961e73df Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayush.tiwari@nexedi.com>
Date: Mon, 7 Aug 2017 09:32:03 +0000
Subject: [PATCH] bt5_config: constructTemplatePath should return None in case
 the path doesn't exist yet. Needed for cases where we are creating a new
 path_item object

---
 product/ERP5/Document/BusinessManager.py | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/product/ERP5/Document/BusinessManager.py b/product/ERP5/Document/BusinessManager.py
index f6b105deea..def2a8cf89 100644
--- a/product/ERP5/Document/BusinessManager.py
+++ b/product/ERP5/Document/BusinessManager.py
@@ -706,7 +706,8 @@ class BusinessItem(XMLObject):
       new_template_path_list = list(template_path_list)
       # Remove the old path and append it with new path in template_path_list
       # for the parent Business Manager
-      new_template_path_list.remove(old_path)
+      if old_path:
+        new_template_path_list.remove(old_path)
       new_template_path_list.append(new_path)
       manager.setProperty('template_path_list', new_template_path_list)
     return edited
@@ -719,7 +720,14 @@ class BusinessItem(XMLObject):
     item_path = self.getProperty('item_path')
     item_sign = self.getProperty('item_sign')
     item_layer = self.getProperty('item_layer')
-    return (' | ').join([item_path, str(item_sign), str(item_layer)])
+    # Try creating template path from the item path,layer and sign
+    try:
+      path =  (' | ').join([item_path, str(item_sign), str(item_layer)])
+    except TypeError:
+      # In case any of item_sign, item_path or item_layer are NoneType or empty,
+      # just return None
+      path = None
+    return path
 
   def build(self, context, **kw):
     """
@@ -1059,7 +1067,8 @@ class BusinessPropertyItem(XMLObject):
       new_template_path_list = list(template_path_list)
       # Remove the old path and append it with new path in template_path_list
       # for the parent Business Manager
-      new_template_path_list.remove(old_path)
+      if old_path:
+        new_template_path_list.remove(old_path)
       new_template_path_list.append(new_path)
       manager.setProperty('template_path_list', new_template_path_list)
     return edited
@@ -1072,7 +1081,14 @@ class BusinessPropertyItem(XMLObject):
     item_path = self.getProperty('item_path')
     item_sign = self.getProperty('item_sign')
     item_layer = self.getProperty('item_layer')
-    return (' | ').join([item_path, str(item_sign), str(item_layer)])
+    # Try creating template path from the item path,layer and sign
+    try:
+      path =  (' | ').join([item_path, str(item_sign), str(item_layer)])
+    except TypeError:
+      # In case any of item_sign, item_path or item_layer are NoneType or empty,
+      # just return None
+      path = None
+    return path
 
   def build(self, context, **kw):
     p = context.getPortalObject()
-- 
2.30.9