Commit 91861bd8 authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Xiaowu Zhang

simulation: handle partial building and split with same dates

Add "planned" state to Purchase/Sale Packing Lists so that builders first build planned deliveries.
Then if there is no expected additional movement, the delivery is automatically moved to "confirmed".
This allows to support partial build that could come with global builders. Now builders will complete
only "planned" deliveries. This also solve the split of packing list when the same date was used,
the builder was updating current delivery. Now we can change packing list only in confirmed state
(not in planned state), therefore the builder will never add movement to the delivery the user is
changing.

This was adapted from seb commit to project repo. The difference is that here we do not confirm if
related movements belong to more then one root delivery value (packing list). This way we try to
handle the case of multiple split on the same date where the user first splits a packing list and
then splits again. In this case we want these splitted movements end up in the same packing list,
so the created packing list still has to be able to receive new movements, it is thus kept in
planned state. The user then hast to confirm this packing list manually.
parent 9933cc4a
portal_type = context.getDeliveryPortalType()
# make sure that the result of the simulation state is update to date, so check getSimulationState manually
return [x.getObject() for x in context.portal_catalog(portal_type=portal_type,simulation_state='planned')
if x.getObject().getSimulationState()=='planned']
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>DeliveryBuilder_selectPlannedDeliveryList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
if REQUEST is not None and 0:
from zExceptions import Unauthorized
raise Unauthorized(script.id)
from Products.ERP5Type.Message import translateString
if context.getSimulationState() == "draft":
context.plan(comment=translateString('Initialised by Delivery Builder.'))
if context.getSimulationState() == "planned":
# Make sure that we are not going to receive more lines later, this could
# happen if global builder took only partially the movement of an applied
# rule.
# We assume here that a Delivery is not going to receive movements from
# different applied rules.
# To check if we are not going to receive more simulation movement, we check
# for all simulation movement of the same level as the simulation movement
# used to construct this current delivery have all a delivery link.
# If there is more than one packing list, do not confirm because it might mean
# that we are in a split, so if the user splits again we want to also recieve
# the movements of further splits.
movement_list = context.getMovementList()
assert len(movement_list) > 0
simulation_movement = movement_list[0].getDeliveryRelatedValue(portal_type="Simulation Movement")
getSpecialise = simulation_movement.getParentValue().getSpecialise()
root_applied_rule = simulation_movement.getRootAppliedRule()
def getSimilarSimulationMovementList(simulation_object):
current_list = []
if simulation_object.getPortalType() == "Applied Rule" and \
simulation_object.getSpecialise() == getSpecialise:
current_list.extend([x for x in simulation_object.objectValues()])
else:
for sub_simulation_object in simulation_object.objectValues():
current_list.extend(getSimilarSimulationMovementList(sub_simulation_object))
return current_list
is_complete = True
packing_list_set = set()
for simulation_movement in getSimilarSimulationMovementList(root_applied_rule):
delivery = simulation_movement.getDeliveryValue()
if delivery is None:
is_complete = False
break
packing_list_set.add(delivery.getRootDeliveryValue())
if is_complete and len(packing_list_set) == 1:
context.confirm(comment=translateString('Initialised by Delivery Builder.'))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Delivery_confirmIfCompleteOrPlan</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
<string>confirm_action</string> <string>confirm_action</string>
<string>delete</string> <string>delete</string>
<string>delete_action</string> <string>delete_action</string>
<string>plan</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="StateDefinition" module="Products.DCWorkflow.States"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>description</string> </key>
<value> <string>Packing List is being planned by simulation. It can not be edited by human in this state.</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>planned</string> </value>
</item>
<item>
<key> <string>permission_roles</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Planned</string> </value>
</item>
<item>
<key> <string>transitions</string> </key>
<value>
<tuple>
<string>cancel</string>
<string>cancel_action</string>
<string>confirm</string>
<string>confirm_action</string>
<string>set_ready</string>
<string>set_ready_action</string>
<string>start</string>
<string>start_action</string>
<string>stop</string>
<string>stop_action</string>
</tuple>
</value>
</item>
<item>
<key> <string>type_list</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>Access contents information</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>Add portal content</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>Delete objects</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>Modify portal content</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>View</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Plan Packing List</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>plan</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string>planned</string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Plan</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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