@@ -130,41 +130,36 @@ def create(container, portal_type, *args, **kwargs):
130
130
:returns: The new created object
131
131
"""
132
132
from bika .lims .utils import tmpID
133
- if kwargs .get ("title" ) is None :
134
- kwargs ["title" ] = "New {}" .format (portal_type )
135
133
136
- # generate a temporary ID
137
- tmp_id = tmpID ( )
134
+ id = kwargs . pop ( "id" , tmpID ())
135
+ title = kwargs . pop ( "title" , "New {}" . format ( portal_type ) )
138
136
139
137
# get the fti
140
138
types_tool = get_tool ("portal_types" )
141
139
fti = types_tool .getTypeInfo (portal_type )
142
140
143
141
if fti .product :
144
- obj = _createObjectByType (portal_type , container , tmp_id )
142
+ obj = _createObjectByType (portal_type , container , id )
143
+ obj .processForm ()
144
+ obj .edit (title = title , ** kwargs )
145
+ modified (obj )
145
146
else :
146
147
# newstyle factory
147
148
factory = getUtility (IFactory , fti .factory )
148
- obj = factory (tmp_id , * args , ** kwargs )
149
+ obj = factory (id , * args , ** kwargs )
149
150
if hasattr (obj , '_setPortalTypeName' ):
150
151
obj ._setPortalTypeName (fti .getId ())
152
+ # set the title
153
+ obj .title = safe_unicode (title )
154
+ # notify that the object was created
151
155
notify (ObjectCreatedEvent (obj ))
152
156
# notifies ObjectWillBeAddedEvent, ObjectAddedEvent and
153
157
# ContainerModifiedEvent
154
- container ._setObject (tmp_id , obj )
158
+ container ._setObject (id , obj )
155
159
# we get the object here with the current object id, as it might be
156
160
# renamed already by an event handler
157
161
obj = container ._getOb (obj .getId ())
158
162
159
- # handle AT Content
160
- if is_at_content (obj ):
161
- obj .processForm ()
162
-
163
- # Edit after processForm; processForm does AT unmarkCreationFlag.
164
- obj .edit (** kwargs )
165
-
166
- # explicit notification
167
- modified (obj )
168
163
return obj
169
164
170
165
0 commit comments