Commit d58b2364 authored by Xiaowu Zhang's avatar Xiaowu Zhang

SimulationTool: it's necessairy to check delivery line to get correct

builder

A delivery may have several delivery line
like:
Purchase Invoice Transaction has Purchase Invoice Transaction Line and
Invoice Line
parent f588d64e
......@@ -2654,7 +2654,7 @@ class SimulationTool(BaseTool):
return result
def _findBuilderForDelivery(self, delivery):
def _findBuilderForDelivery(self, delivery, movement_portal_type):
"""
Find out the builder corresponding to a delivery by looking at the business process
"""
......@@ -2662,7 +2662,8 @@ class SimulationTool(BaseTool):
portal_type = delivery.getPortalType()
for business_link in delivery.asComposedDocument().objectValues(portal_type="Business Link"):
for business_link_builder in business_link.getDeliveryBuilderValueList():
if business_link_builder.getDeliveryPortalType() == portal_type:
if business_link_builder.getDeliveryPortalType() == portal_type \
and business_link_builder.getDeliveryLinePortalType() == movement_portal_type:
builder = business_link_builder
break
if builder is not None:
......@@ -2688,12 +2689,17 @@ class SimulationTool(BaseTool):
if len(portal_type_set) != 1:
error_list.append(translateString("Please select only deliveries of same type"))
else:
portal_type, = portal_type_set
allowed_state_set = set(portal.getPortalReservedInventoryStateList() + \
portal.getPortalFutureInventoryStateList())
found_state_set = set([x.getSimulationState() for x in delivery_list])
if found_state_set.difference(allowed_state_set):
error_list.append(translateString("Found delivery having unexpected status for merge"))
else:
movement_portal_type_set = set()
for delivery in delivery_list:
movement_portal_type_set.update([x.getPortalType() for x in delivery.getMovementList()])
if len(movement_portal_type_set) != 1:
error_list.append(translateString("Please Select only movement of same type"))
else:
# Allow to call a script to do custom checking conditions before merge
main_delivery = delivery_list[0]
......@@ -2740,7 +2746,8 @@ class SimulationTool(BaseTool):
simulation_movement.expand(expand_policy='immediate')
# activate builder
merged_builder = self._findBuilderForDelivery(main_delivery)
movement_portal_type, = movement_portal_type_set
merged_builder = self._findBuilderForDelivery(main_delivery, movement_portal_type)
if merged_builder is None:
error_list.append(translateString("Unable to find builder"))
else:
......
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