diff --git a/product/ERP5Type/Document/Folder.py b/product/ERP5Type/Document/Folder.py index 2bd8952393366de2877ef81cd0591a7c5d840269..f56eb4a96642239a32cf5f6c41e7a6d27b51dcb1 100644 --- a/product/ERP5Type/Document/Folder.py +++ b/product/ERP5Type/Document/Folder.py @@ -70,7 +70,7 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer): def newContent(self, id=None, portal_type=None, id_group=None, default=None, method=None, immediate_reindex=0, container=None, created_by_builder=0, activate_kw=None, - is_indexable=None, **kw): + is_indexable=None, temp_object=0, **kw): """Creates a new content. This method is public, since TypeInformation.constructInstance will perform the security check. @@ -86,6 +86,17 @@ class FolderMixIn(ExtensionClass.Base, CopyContainer): # XXX This feature is very confusing # And made the code more difficult to update portal_type = container.allowedContentTypes()[0].id + + if temp_object: + from Products.ERP5Type import Document + # we get an object from factory only for first temp container object + # otherwise we get an id so we can use the classic way + if not hasattr(container, 'isTempObject') or \ + (hasattr(container, 'isTempObject') and not container.isTempObject()): + factory_name = 'newTemp%s' %(portal_type.replace(' ', '')) + m = getattr(Document, factory_name) + return m(container, new_id) + self.portal_types.constructContent(type_name=portal_type, container=container, id=new_id, diff --git a/product/ERP5Type/tests/testERP5Type.py b/product/ERP5Type/tests/testERP5Type.py index d3f527b78a03697d4bb6453b11ee958eb7393357..739223d845351863b5e05351f4612713de24924b 100644 --- a/product/ERP5Type/tests/testERP5Type.py +++ b/product/ERP5Type/tests/testERP5Type.py @@ -225,9 +225,23 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor): self.assertEquals(o.isTempObject(), 1) # Create a subobject and make sure it is a Temp Object - a = o.newContent(portal_type = 'Telephone') + a = o.newContent(portal_type = 'Telephone') self.assertEquals(a.isTempObject(), 1) + # Test newContent with the temp_object parameter + o = portal.person_module.newContent(id=987, portal_type="Person", temp_object=1) + o.setTitle('bar') + self.assertEquals(o.getTitle(), 'bar') + self.assertEquals(str(o.getId()), str(987)) + self.assertEquals(o.isTempObject(), 1) + a = o.newContent(id=1, portal_type="Telephone", temp_object=1) + self.assertEquals(str(a.getId()), str(1)) + self.assertEquals(a.isTempObject(), 1) + b = o.newContent(id=2, portal_type="Telephone") + self.assertEquals(b.isTempObject(), 1) + self.assertEquals(b.getId(), str(2)) + + def test_04_CategoryAccessors(self, quiet=quiet, run=run_all_test): """ This test provides basic testing of category