Commit 66fad102 authored by Rafael Monnerat's avatar Rafael Monnerat Committed by Xiaowu Zhang

Make Builder able to generate Temp Objects

 Introduce temp_object parameter on builder.build() and propagate it
 over until the newContent() calls. This change allow use create
 Temporary Documents intestead real ones, like a "preview".

(cherry picked from commit 959776ce50c2e7ee2b8f9945ec91a2e0fbe08619)

Conflicts:
	product/ERP5/Document/SimulatedDeliveryBuilder.py
parent c0b8e03e
...@@ -341,7 +341,8 @@ class SimulatedDeliveryBuilder(BuilderMixin): ...@@ -341,7 +341,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
'solveDivergence') 'solveDivergence')
solveDivergence = UnrestrictedMethod(_solveDivergence) solveDivergence = UnrestrictedMethod(_solveDivergence)
def _createDelivery(self, delivery_module, movement_list, activate_kw): def _createDelivery(self, delivery_module, movement_list, activate_kw,
temp_object):
""" """
Refer to the docstring in GeneratedDeliveryBuilder. Refer to the docstring in GeneratedDeliveryBuilder.
Unlike GeneratedDeliveryBuilder, SimulatedDeliveryBuilder needs to respect Unlike GeneratedDeliveryBuilder, SimulatedDeliveryBuilder needs to respect
...@@ -356,7 +357,7 @@ class SimulatedDeliveryBuilder(BuilderMixin): ...@@ -356,7 +357,7 @@ class SimulatedDeliveryBuilder(BuilderMixin):
if old_delivery is None: if old_delivery is None:
# from scratch # from scratch
delivery = super(SimulatedDeliveryBuilder, self)._createDelivery( delivery = super(SimulatedDeliveryBuilder, self)._createDelivery(
delivery_module, movement_list, activate_kw) delivery_module, movement_list, activate_kw, temp_object)
# Interactions will usually trigger reindexing of related SM when # Interactions will usually trigger reindexing of related SM when
# simulation state changes. Disable them for this transaction # simulation state changes. Disable them for this transaction
# because we already do this in _setDeliveryMovementProperties # because we already do this in _setDeliveryMovementProperties
...@@ -377,7 +378,8 @@ class SimulatedDeliveryBuilder(BuilderMixin): ...@@ -377,7 +378,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
return delivery return delivery
def _createDeliveryLine(self, delivery, movement_list, activate_kw): def _createDeliveryLine(self, delivery, movement_list, activate_kw,
temp_object):
""" """
Refer to the docstring in GeneratedDeliveryBuilder. Refer to the docstring in GeneratedDeliveryBuilder.
Unlike GeneratedDeliveryBuilder, SimulatedDeliveryBuilder needs to respect Unlike GeneratedDeliveryBuilder, SimulatedDeliveryBuilder needs to respect
...@@ -394,6 +396,7 @@ class SimulatedDeliveryBuilder(BuilderMixin): ...@@ -394,6 +396,7 @@ class SimulatedDeliveryBuilder(BuilderMixin):
delivery_line = delivery.newContent( delivery_line = delivery.newContent(
portal_type=self.getDeliveryLinePortalType(), portal_type=self.getDeliveryLinePortalType(),
variation_category_list=[], variation_category_list=[],
temp_object=temp_object,
activate_kw=activate_kw) activate_kw=activate_kw)
else: else:
# from duplicated original line # from duplicated original line
...@@ -414,7 +417,7 @@ class SimulatedDeliveryBuilder(BuilderMixin): ...@@ -414,7 +417,7 @@ class SimulatedDeliveryBuilder(BuilderMixin):
return delivery_line return delivery_line
def _createDeliveryCell(self, delivery_line, movement, activate_kw, def _createDeliveryCell(self, delivery_line, movement, activate_kw,
base_id, cell_key): base_id, cell_key, temp_object):
""" """
Refer to the docstring in GeneratedDeliveryBuilder. Refer to the docstring in GeneratedDeliveryBuilder.
Unlike GeneratedDeliveryBuilder, SimulatedDeliveryBuilder needs to respect Unlike GeneratedDeliveryBuilder, SimulatedDeliveryBuilder needs to respect
...@@ -428,7 +431,7 @@ class SimulatedDeliveryBuilder(BuilderMixin): ...@@ -428,7 +431,7 @@ class SimulatedDeliveryBuilder(BuilderMixin):
# from scratch # from scratch
cell = delivery_line.newCell(base_id=base_id, \ cell = delivery_line.newCell(base_id=base_id, \
portal_type=self.getDeliveryCellPortalType(), portal_type=self.getDeliveryCellPortalType(),
activate_kw=activate_kw,*cell_key) activate_kw=activate_kw,temp_object=temp_object, *cell_key)
else: else:
# from duplicated original line # from duplicated original line
cp = tryMethodCallWithTemporaryPermission( cp = tryMethodCallWithTemporaryPermission(
......
...@@ -102,7 +102,7 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -102,7 +102,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
def build(self, applied_rule_uid=None, movement_relative_url_list=None, def build(self, applied_rule_uid=None, movement_relative_url_list=None,
delivery_relative_url_list=None, movement_list=None, delivery_relative_url_list=None, movement_list=None,
explanation=None, business_link=None, activate_kw=None, explanation=None, business_link=None, activate_kw=None,
merge_delivery=None, **kw): merge_delivery=None, temp_object=0, **kw):
""" """
Build deliveries from a list of movements Build deliveries from a list of movements
...@@ -143,7 +143,7 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -143,7 +143,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
root_group_node, root_group_node,
delivery_relative_url_list=delivery_relative_url_list, delivery_relative_url_list=delivery_relative_url_list,
movement_list=movement_list, activate_kw=activate_kw, movement_list=movement_list, activate_kw=activate_kw,
merge_delivery=merge_delivery, **kw) merge_delivery=merge_delivery, temp_object=temp_object, **kw)
# Call a script after building # Call a script after building
self.callAfterBuildingScript(delivery_list, movement_list, **kw) self.callAfterBuildingScript(delivery_list, movement_list, **kw)
return delivery_list return delivery_list
...@@ -386,7 +386,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -386,7 +386,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
@UnrestrictedMethod @UnrestrictedMethod
def buildDeliveryList(self, movement_group_node, def buildDeliveryList(self, movement_group_node,
delivery_relative_url_list=None, delivery_relative_url_list=None,
movement_list=None, update=True, **kw): movement_list=None, update=True,
temp_object=0, **kw):
""" """
Build deliveries from a list of movements Build deliveries from a list of movements
""" """
...@@ -421,10 +422,12 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -421,10 +422,12 @@ class BuilderMixin(XMLObject, Amount, Predicate):
movement_group_node, movement_group_node,
self.getDeliveryMovementGroupList(), self.getDeliveryMovementGroupList(),
delivery_to_update_list=delivery_to_update_list, delivery_to_update_list=delivery_to_update_list,
temp_object=temp_object,
**kw) **kw)
return delivery_list return delivery_list
def _createDelivery(self, delivery_module, movement_list, activate_kw): def _createDelivery(self, delivery_module, movement_list, activate_kw,
temp_object):
""" """
Create a new delivery in case where a builder may not update Create a new delivery in case where a builder may not update
an existing one. an existing one.
...@@ -432,14 +435,15 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -432,14 +435,15 @@ class BuilderMixin(XMLObject, Amount, Predicate):
return delivery_module.newContent( return delivery_module.newContent(
portal_type=self.getDeliveryPortalType(), portal_type=self.getDeliveryPortalType(),
created_by_builder=1, created_by_builder=1,
activate_kw=activate_kw) activate_kw=activate_kw,
temp_object=temp_object)
def _processDeliveryGroup(self, delivery_module, movement_group_node, def _processDeliveryGroup(self, delivery_module, movement_group_node,
collect_order_list, movement_group_node_list=None, collect_order_list, movement_group_node_list=None,
delivery_to_update_list=None, delivery_to_update_list=None,
divergence_list=None, divergence_list=None,
activate_kw=None, force_update=0, activate_kw=None, force_update=0,
merge_delivery=None, **kw): merge_delivery=None, temp_object=0, **kw):
""" """
Build delivery from a list of movement Build delivery from a list of movement
""" """
...@@ -466,7 +470,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -466,7 +470,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
divergence_list=divergence_list, divergence_list=divergence_list,
activate_kw=activate_kw, activate_kw=activate_kw,
force_update=force_update, force_update=force_update,
merge_delivery=merge_delivery) merge_delivery=merge_delivery,
temp_object=temp_object)
delivery_list.extend(new_delivery_list) delivery_list.extend(new_delivery_list)
force_update = 0 force_update = 0
else: else:
...@@ -497,7 +502,7 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -497,7 +502,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
delivery = self._createDelivery(delivery_module, delivery = self._createDelivery(delivery_module,
movement_group_node.getMovementList(), movement_group_node.getMovementList(),
activate_kw) activate_kw, temp_object)
# Put properties on delivery # Put properties on delivery
self._setUpdated(delivery, 'delivery') self._setUpdated(delivery, 'delivery')
if property_dict: if property_dict:
...@@ -512,11 +517,13 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -512,11 +517,13 @@ class BuilderMixin(XMLObject, Amount, Predicate):
self.getDeliveryLineMovementGroupList()[1:], self.getDeliveryLineMovementGroupList()[1:],
divergence_list=divergence_list, divergence_list=divergence_list,
activate_kw=activate_kw, activate_kw=activate_kw,
force_update=force_update) force_update=force_update,
temp_object=temp_object)
delivery_list.append(delivery) delivery_list.append(delivery)
return delivery_list return delivery_list
def _createDeliveryLine(self, delivery, movement_list, activate_kw): def _createDeliveryLine(self, delivery, movement_list, activate_kw,
temp_object):
""" """
Create a new delivery line in case where a builder may not update Create a new delivery line in case where a builder may not update
an existing one. an existing one.
...@@ -524,12 +531,14 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -524,12 +531,14 @@ class BuilderMixin(XMLObject, Amount, Predicate):
return delivery.newContent( return delivery.newContent(
portal_type=self.getDeliveryLinePortalType(), portal_type=self.getDeliveryLinePortalType(),
created_by_builder=1, created_by_builder=1,
activate_kw=activate_kw) activate_kw=activate_kw,
temp_object=temp_object)
def _processDeliveryLineGroup(self, delivery, movement_group_node, def _processDeliveryLineGroup(self, delivery, movement_group_node,
collect_order_list, movement_group_node_list=None, collect_order_list, movement_group_node_list=None,
divergence_list=None, divergence_list=None,
activate_kw=None, force_update=0, **kw): activate_kw=None, force_update=0,
temp_object=0, **kw):
""" """
Build delivery line from a list of movement on a delivery Build delivery line from a list of movement on a delivery
""" """
...@@ -550,7 +559,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -550,7 +559,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
movement_group_node_list=movement_group_node_list, movement_group_node_list=movement_group_node_list,
divergence_list=divergence_list, divergence_list=divergence_list,
activate_kw=activate_kw, activate_kw=activate_kw,
force_update=force_update) force_update=force_update,
temp_object=temp_object)
else: else:
# Test if we can update an existing line, or if we need to create a new # Test if we can update an existing line, or if we need to create a new
# one # one
...@@ -568,7 +578,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -568,7 +578,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
delivery_line = self._createDeliveryLine( delivery_line = self._createDeliveryLine(
delivery, delivery,
movement_group_node.getMovementList(), movement_group_node.getMovementList(),
activate_kw) activate_kw,
temp_object)
# Put properties on delivery line # Put properties on delivery line
self._setUpdated(delivery_line, 'line') self._setUpdated(delivery_line, 'line')
if property_dict: if property_dict:
...@@ -584,7 +595,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -584,7 +595,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
movement_group_node_list=movement_group_node_list, movement_group_node_list=movement_group_node_list,
divergence_list=divergence_list, divergence_list=divergence_list,
activate_kw=activate_kw, activate_kw=activate_kw,
force_update=force_update) force_update=force_update,
temp_object=temp_object)
return return
# Update variation category list on line # Update variation category list on line
...@@ -606,7 +618,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -606,7 +618,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
update_existing_line=update_existing_line, update_existing_line=update_existing_line,
divergence_list=divergence_list, divergence_list=divergence_list,
activate_kw=activate_kw, activate_kw=activate_kw,
force_update=force_update) force_update=force_update,
temp_object=temp_object)
else: else:
self._processDeliveryCellGroup( self._processDeliveryCellGroup(
delivery_line, delivery_line,
...@@ -615,10 +628,11 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -615,10 +628,11 @@ class BuilderMixin(XMLObject, Amount, Predicate):
update_existing_line=update_existing_line, update_existing_line=update_existing_line,
divergence_list=divergence_list, divergence_list=divergence_list,
activate_kw=activate_kw, activate_kw=activate_kw,
force_update=force_update) force_update=force_update,
temp_object=temp_object)
def _createDeliveryCell(self, delivery_line, movement, activate_kw, def _createDeliveryCell(self, delivery_line, movement, activate_kw,
base_id, cell_key): base_id, cell_key, temp_object):
""" """
Create a new delivery cell in case where a builder may not update Create a new delivery cell in case where a builder may not update
an existing one. an existing one.
...@@ -626,6 +640,7 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -626,6 +640,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
cell = delivery_line.newCell(base_id=base_id, cell = delivery_line.newCell(base_id=base_id,
portal_type=self.getDeliveryCellPortalType(), portal_type=self.getDeliveryCellPortalType(),
activate_kw=activate_kw, activate_kw=activate_kw,
temp_object=temp_object,
*cell_key) *cell_key)
return cell return cell
...@@ -633,7 +648,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -633,7 +648,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
collect_order_list, movement_group_node_list=None, collect_order_list, movement_group_node_list=None,
update_existing_line=0, update_existing_line=0,
divergence_list=None, divergence_list=None,
activate_kw=None, force_update=0): activate_kw=None, force_update=0,
temp_object=0):
""" """
Build delivery cell from a list of movement on a delivery line Build delivery cell from a list of movement on a delivery line
or complete delivery line or complete delivery line
...@@ -656,7 +672,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -656,7 +672,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
update_existing_line=update_existing_line, update_existing_line=update_existing_line,
divergence_list=divergence_list, divergence_list=divergence_list,
activate_kw=activate_kw, activate_kw=activate_kw,
force_update=force_update) force_update=force_update,
temp_object=temp_object)
else: else:
movement_list = movement_group_node.getMovementList() movement_list = movement_group_node.getMovementList()
if len(movement_list) != 1: if len(movement_list) != 1:
...@@ -710,7 +727,8 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -710,7 +727,8 @@ class BuilderMixin(XMLObject, Amount, Predicate):
omit_optional_variation=1) omit_optional_variation=1)
if not delivery_line.hasCell(base_id=base_id, *cell_key): if not delivery_line.hasCell(base_id=base_id, *cell_key):
cell = self._createDeliveryCell(delivery_line, movement, cell = self._createDeliveryCell(delivery_line, movement,
activate_kw, base_id, cell_key) activate_kw, base_id, cell_key,
temp_object)
vcl = movement.getVariationCategoryList() vcl = movement.getVariationCategoryList()
cell._edit(category_list=vcl, cell._edit(category_list=vcl,
# XXX hardcoded value # XXX hardcoded value
......
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