Commit 01ed5d3d authored by Arnaud Fontaine's avatar Arnaud Fontaine

Folder: Allow to create temp_objects anywhere, without checking if it's in...

Folder: Allow to create temp_objects anywhere, without checking if it's in allowed types for that Portal Type.

Until now, creating a temp_object with newContent() required for the temp_object
to be in allowed types. However, this was inconsistent with (now deprecated)
newTemp*() functions (calling directly constructInstance()) not having such
limitations.

Besides lifting such limitation being needed to properly replace newTemp*() calls,
portal_trash.newContent() pattern is already commonly used used here meaning there
is a real use case.

This also fixes testBanking* failures: newTempCashDeliveryLine() created objects
on 'Cash Inventory' and latter call Delivery.isAccountable() which does not exist on
portal_trash.

See also 04b49859.

/reviewed-on !1025
parent accf13dd
...@@ -63,7 +63,7 @@ class CashInventory(Inventory, BankingOperation): ...@@ -63,7 +63,7 @@ class CashInventory(Inventory, BankingOperation):
setting another kind of temp delivery line. setting another kind of temp delivery line.
""" """
def newTempCashDeliveryLine(self, inventory_id): def newTempCashDeliveryLine(self, inventory_id):
return self.getPortalObject().portal_trash.newContent( return self.newContent(
portal_type='Cash Delivery Line', portal_type='Cash Delivery Line',
temp_object=True, temp_object=True,
id=inventory_id) id=inventory_id)
......
...@@ -201,7 +201,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -201,7 +201,7 @@ class FolderMixIn(ExtensionClass.Base):
portal_type = allowed_content_type_list[0].id portal_type = allowed_content_type_list[0].id
else: else:
raise ValueError('Creation disallowed') raise ValueError('Creation disallowed')
else: elif not temp_object:
type_info = pt.getTypeInfo(container) type_info = pt.getTypeInfo(container)
if type_info is not None and not type_info.allowType(portal_type) and \ if type_info is not None and not type_info.allowType(portal_type) and \
'portal_trash' not in container.getPhysicalPath(): 'portal_trash' not in container.getPhysicalPath():
......
...@@ -211,6 +211,8 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor): ...@@ -211,6 +211,8 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
def test_03_NewTempObject(self): def test_03_NewTempObject(self):
portal = self.portal portal = self.portal
# WARNING: `newTemp<PortalType>(self, ID)` is deprecated in favor of
# `self.newContent(portal_type=<PortalType>, temp_object=True, id=ID)`
from Products.ERP5Type.Document import newTempPerson from Products.ERP5Type.Document import newTempPerson
o = newTempPerson(portal, 1.2) o = newTempPerson(portal, 1.2)
o.setTitle('toto') o.setTitle('toto')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment