From 48a8f05493d8527a0e182b20fe0688319f9d0234 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Thu, 28 Oct 2010 15:45:03 +0000
Subject: [PATCH] Fix initialization of portal types that are defined outside
 Types Tool

This fixes TestSolvingPackingList

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39623 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/tests/testPackingList.py         |  2 +-
 product/ERP5Type/dynamic/portal_type_class.py | 16 +++++++---------
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/product/ERP5/tests/testPackingList.py b/product/ERP5/tests/testPackingList.py
index 6984e07bc1..3ce528c962 100644
--- a/product/ERP5/tests/testPackingList.py
+++ b/product/ERP5/tests/testPackingList.py
@@ -1797,7 +1797,7 @@ class TestSolvingPackingList(TestPackingListMixin, ERP5TypeTestCase):
       id=solver_id,
       tested_property_list=tested_property_list,
       automatic_solver=1,
-      type_factory_method_id='add%s' % solver_class,
+      type_class=solver_class,
       type_group_list=('target_solver',),
     )
     solver.setCriterion(property='portal_type',
diff --git a/product/ERP5Type/dynamic/portal_type_class.py b/product/ERP5Type/dynamic/portal_type_class.py
index cc031bafa5..92b9e47fe0 100644
--- a/product/ERP5Type/dynamic/portal_type_class.py
+++ b/product/ERP5Type/dynamic/portal_type_class.py
@@ -104,23 +104,21 @@ def generatePortalTypeClass(portal_type_name):
   from Products.ERP5.ERP5Site import getSite
   site = getSite()
 
-  types_tool = site.portal_types
-  portal_type = None
-  mixin_list = []
-  interface_list = []
   accessor_holder_list = []
 
-  try:
-    portal_type = types_tool[portal_type_name]
-  except KeyError:
+  # Do not use __getitem__ (or _getOb) because portal_type may exist in a
+  # type provider other than Types Tool.
+  portal_type = getattr(site.portal_types, portal_type_name, None)
+  if portal_type is None:
     # Try to figure out a coresponding document class from the document side.
     # This can happen when calling newTempAmount for instance:
     #  Amount has no corresponding Base Type and will never have one
     #  But the semantic of newTempXXX requires us to create an
     #  object using the Amount Document, so we promptly do it:
     type_class = portal_type_name.replace(' ', '')
-
-  if portal_type is not None:
+    mixin_list = []
+    interface_list = []
+  else:
     # type_class has a compatibility getter that should return
     # something even if the field is not set (i.e. Base Type object
     # was not migrated yet)
-- 
2.30.9