Commit 16565c7e authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Jérome Perrin

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 ff754bce
<?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>_body</string> </key>
<value> <string>portal_type = context.getDeliveryPortalType()\n
# make sure that the result of the simulation state is update to date, so check getSimulationState manually\n
return [x.getObject() for x in context.portal_catalog(portal_type=portal_type,simulation_state=\'confirmed\') \n
if x.getObject().getSimulationState()==\'planned\']\n
</string> </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>
<?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>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
if REQUEST is not None and 0:\n
from zExceptions import Unauthorized\n
raise Unauthorized(script.id)\n
from Products.ERP5Type.Message import translateString\n
\n
if context.getSimulationState() == "draft":\n
context.plan(comment=translateString(\'Initialised by Delivery Builder.\'))\n
if context.getSimulationState() == "planned":\n
# Make sure that we are not going to receive more lines later, this could\n
# happen if global builder took only partially the movement of an applied\n
# rule.\n
# We assume here that a Delivery is not going to receive movements from\n
# different applied rules.\n
# To check if we are not going to receive more simulation movement, we check\n
# for all simulation movement of the same level as the simulation movement\n
# used to construct this current delivery have all a delivery link.\n
# If there is more than one packing list, do not confirm because it might mean\n
# that we are in a split, so if the user splits again we want to also recieve\n
# the movements of further splits.\n
movement_list = context.getMovementList()\n
assert len(movement_list) > 0\n
simulation_movement = movement_list[0].getDeliveryRelatedValue(portal_type="Simulation Movement")\n
getSpecialise = simulation_movement.getParentValue().getSpecialise()\n
root_applied_rule = simulation_movement.getRootAppliedRule()\n
\n
def getSimilarSimulationMovementList(simulation_object):\n
current_list = []\n
if simulation_object.getPortalType() == "Applied Rule" and \\\n
simulation_object.getSpecialise() == getSpecialise:\n
current_list.extend([x for x in simulation_object.objectValues()])\n
else:\n
for sub_simulation_object in simulation_object.objectValues():\n
current_list.extend(getSimilarSimulationMovementList(sub_simulation_object))\n
return current_list\n
\n
is_complete = True\n
packing_list_set = set()\n
for simulation_movement in getSimilarSimulationMovementList(root_applied_rule):\n
delivery = simulation_movement.getDeliveryValue()\n
if delivery is None:\n
is_complete = False\n
break\n
packing_list_set.add(delivery.getRootDeliveryValue())\n
if is_complete and len(packing_list_set) == 1:\n
context.confirm(comment=translateString(\'Initialised by Delivery Builder.\'))\n
]]></string> </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>
......@@ -51,7 +51,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>context.PackingList_copyOrderProperties()\n
context.Delivery_confirm()\n
context.Delivery_confirmIfCompleteOrPlan()\n
</string> </value>
</item>
<item>
......
......@@ -51,7 +51,7 @@
<item>
<key> <string>_body</string> </key>
<value> <string>context.PackingList_copyOrderProperties()\n
context.Delivery_confirm()\n
context.Delivery_confirmIfCompleteOrPlan()\n
</string> </value>
</item>
<item>
......
......@@ -34,6 +34,7 @@
<string>confirm_action</string>
<string>delete</string>
<string>delete_action</string>
<string>plan</string>
</tuple>
</value>
</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