From f8f26a04405d5cdf4722e51c72084938df9e9fdc Mon Sep 17 00:00:00 2001
From: Rafael Monnerat <rafael@nexedi.com>
Date: Sun, 15 Jan 2012 05:12:57 -0200
Subject: [PATCH] Ignore and log if bt is not defined.

---
 .../Document/PortalTypeRolesSpreadsheetConfiguratorItem.py | 3 ++-
 product/ERP5Configurator/mixin/configurator_item.py        | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/product/ERP5Configurator/Document/PortalTypeRolesSpreadsheetConfiguratorItem.py b/product/ERP5Configurator/Document/PortalTypeRolesSpreadsheetConfiguratorItem.py
index 465d7b0734..0f4d4a4d5f 100644
--- a/product/ERP5Configurator/Document/PortalTypeRolesSpreadsheetConfiguratorItem.py
+++ b/product/ERP5Configurator/Document/PortalTypeRolesSpreadsheetConfiguratorItem.py
@@ -83,7 +83,8 @@ class PortalTypeRolesSpreadsheetConfiguratorItem(ConfiguratorItemMixin, XMLObjec
 
     ## Update BT5
     bt5_obj = business_configuration.getSpecialiseValue()
-    bt5_obj.edit(template_portal_type_roles_list=self._spreadsheet_cache.keys())
+    if bt5_obj is not None:
+      bt5_obj.edit(template_portal_type_roles_list=self._spreadsheet_cache.keys())
 
   def checkSpreadSheetConsistency(self):
     """Check that the spread sheet is consistent with categories spreadsheet.
diff --git a/product/ERP5Configurator/mixin/configurator_item.py b/product/ERP5Configurator/mixin/configurator_item.py
index 2b3377c499..1375d49db3 100644
--- a/product/ERP5Configurator/mixin/configurator_item.py
+++ b/product/ERP5Configurator/mixin/configurator_item.py
@@ -36,10 +36,17 @@ class ConfiguratorItemMixin:
   def install(self, document, business_configuration, prefix=''):
     """ Add object to customer customization template. """
     bt5_obj = business_configuration.getSpecialiseValue()
+    if bt5_obj is None:
+      LOG('ConfiguratorItem', INFO, 
+          'Unable to find related business template to %s' % \
+            business_configuration.getRelativeUrl())
+      return
+
     if document.getPortalType() in ['Category', 'Base Category']:
       prefix = "portal_categories/"
     template_path_list = ['%s%s' % (prefix, document.getRelativeUrl()),
                           '%s%s/**' % (prefix, document.getRelativeUrl())]
+
     current_template_path_list = list(bt5_obj.getTemplatePathList())
     current_template_path_list.extend(template_path_list)
     bt5_obj.edit(template_path_list=current_template_path_list)
-- 
2.30.9