Commit 7ed83fec authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

* simplify Delivery Rule and Order Rule.

* set default matching property list for compatibility.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32472 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 98bf87ca
...@@ -61,74 +61,7 @@ class DeliveryRule(Rule): ...@@ -61,74 +61,7 @@ class DeliveryRule(Rule):
Else if the movement is not in current state, it can be modified. Else if the movement is not in current state, it can be modified.
Else, it cannot be modified. Else, it cannot be modified.
""" """
if self._isBPM(): return Rule._expand(self, applied_rule, **kw)
Rule.expand(self, applied_rule,
delivery_movement_type_list=delivery_movement_type_list, **kw)
return
existing_movement_list = []
immutable_movement_list = []
delivery = applied_rule.getDefaultCausalityValue()
if delivery_movement_type_list is None:
delivery_movement_type_list = self.getPortalDeliveryMovementTypeList()
if delivery is not None:
delivery_movement_list = delivery.getMovementList(
portal_type=delivery_movement_type_list)
# Check existing movements
for movement in applied_rule.contentValues(portal_type=self.movement_type):
if movement.getLastExpandSimulationState() not in \
self.getPortalCurrentInventoryStateList():
# XXX: This condition is quick and dirty hack - knowing if Simulation
# Movement is frozen shall not be ever hardcoded, this is BPM
# configuration
movement_delivery = movement.getDeliveryValue()
if not movement._isTreeDelivered(ignore_first=1) and \
movement_delivery not in delivery_movement_list:
applied_rule._delObject(movement.getId())
else:
existing_movement_list.append(movement)
else:
existing_movement_list.append(movement)
immutable_movement_list.append(movement)
# Create or modify movements
for deliv_mvt in delivery_movement_list:
sim_mvt = self._getDeliveryRelatedSimulationMovement(deliv_mvt)
if sim_mvt is None:
# create a new deliv_mvt
if deliv_mvt.getParentUid() == deliv_mvt.getExplanationUid():
# We are on a line
new_id = deliv_mvt.getId()
else:
# We are on a cell
new_id = "%s_%s" % (deliv_mvt.getParentId(), deliv_mvt.getId())
# Generate the simulation deliv_mvt
property_dict = self._getExpandablePropertyDict(
applied_rule, deliv_mvt)
new_sim_mvt = applied_rule.newContent(
portal_type=self.movement_type,
id=new_id,
order_value=deliv_mvt,
order_ratio=1,
delivery_value=deliv_mvt,
delivery_ratio=1,
**property_dict)
elif sim_mvt in existing_movement_list:
if sim_mvt not in immutable_movement_list:
# modification allowed
property_dict = self._getExpandablePropertyDict(
applied_rule, deliv_mvt)
sim_mvt.edit(
delivery_value=deliv_mvt,
delivery_ratio=1,
**property_dict)
else:
# modification disallowed, must compensate
pass
# Now we can set the last expand simulation state to the current state
applied_rule.setLastExpandSimulationState(delivery.getSimulationState())
# Pass to base class
Rule.expand(self, applied_rule, **kw)
def _getDeliveryRelatedSimulationMovement(self, delivery_movement): def _getDeliveryRelatedSimulationMovement(self, delivery_movement):
"""Helper method to get the delivery related simulation movement. """Helper method to get the delivery related simulation movement.
...@@ -268,3 +201,19 @@ class DeliveryRule(Rule): ...@@ -268,3 +201,19 @@ class DeliveryRule(Rule):
'order': movement.getRelativeUrl(), 'order': movement.getRelativeUrl(),
'delivery': movement.getRelativeUrl(), 'delivery': movement.getRelativeUrl(),
} }
security.declareProtected(Permissions.AccessContentsInformation,
'getMatchingPropertyList')
def getMatchingPropertyList(self, default=None):
"""
Return a list of properties used in expand.
"""
property_list = self._baseGetMatchingPropertyList()
# For backward compatibility, we keep for some time the list
# of hardcoded properties. Theses properties should now be
# defined on the rule itself
if len(property_list) == 0:
LOG("Invoice Transaction Rule , getMatchingPropertyList", WARNING,
"Hardcoded properties set, please define your rule correctly")
property_list=['delivery',]
return property_list
...@@ -62,75 +62,7 @@ class OrderRule(DeliveryRule): ...@@ -62,75 +62,7 @@ class OrderRule(DeliveryRule):
delivered child, and is in order, it can be modified. delivered child, and is in order, it can be modified.
Else, it cannot be modified. Else, it cannot be modified.
""" """
if self._isBPM(): return Rule._expand(self, applied_rule, force=force, **kw)
DeliveryRule.expand(self, applied_rule, force=force, **kw)
return
existing_movement_list = []
immutable_movement_list = []
order = applied_rule.getDefaultCausalityValue()
if order is not None:
order_movement_list = order.getMovementList(
portal_type=order.getPortalOrderMovementTypeList())
# check existing movements
for movement in applied_rule.contentValues(portal_type=self.movement_type):
if (not movement.getLastExpandSimulationState() in
order.getPortalReservedInventoryStateList() and
not movement.getLastExpandSimulationState() in
order.getPortalCurrentInventoryStateList()) and \
not movement._isTreeDelivered():
movement_order = movement.getOrderValue()
if movement_order in order_movement_list:
existing_movement_list.append(movement)
else:
applied_rule._delObject(movement.getId())
else:
existing_movement_list.append(movement)
immutable_movement_list.append(movement)
# this dict simulates getOrderRelatedValue, but it will not work if an
# order was generated from multiple applied rules
order_movement_dict = {}
for s_m in applied_rule.objectValues():
order_movement = s_m.getOrderValue()
if order_movement is not None:
order_movement_dict[order_movement.getPath()] = s_m
# Create or modify movements
for movement in order_movement_list:
related_order = order_movement_dict.get(movement.getPath(), None)
if related_order is None:
related_order = movement.getOrderRelatedValue()
property_dict = self._getExpandablePropertyDict(
applied_rule, movement)
if related_order is None:
# Generate a simulation movement
# Do not try to create meaningfull IDs, as order movement can be
# hierarchicals
applied_rule.newContent(
portal_type=self.movement_type,
order_value=movement,
order_ratio=1,
delivery_ratio=1,
**property_dict )
elif related_order in existing_movement_list:
if related_order not in immutable_movement_list:
# modification allowed
related_order.edit(
order_value=movement,
**property_dict)
#related_order.setLastExpandSimulationState(order.getSimulationState())
else:
# modification disallowed, must compensate
pass
# Now we can set the last expand simulation state to the current state
applied_rule.setLastExpandSimulationState(order.getSimulationState())
# Pass to base class
Rule.expand(self, applied_rule, force=force, **kw)
security.declareProtected(Permissions.AccessContentsInformation, 'isStable') security.declareProtected(Permissions.AccessContentsInformation, 'isStable')
def isStable(self, applied_rule): def isStable(self, applied_rule):
...@@ -185,6 +117,22 @@ class OrderRule(DeliveryRule): ...@@ -185,6 +117,22 @@ class OrderRule(DeliveryRule):
) )
return property_list return property_list
security.declareProtected(Permissions.AccessContentsInformation,
'getMatchingPropertyList')
def getMatchingPropertyList(self, default=None):
"""
Return a list of properties used in expand.
"""
property_list = self._baseGetMatchingPropertyList()
# For backward compatibility, we keep for some time the list
# of hardcoded properties. Theses properties should now be
# defined on the rule itself
if len(property_list) == 0:
LOG("Invoice Transaction Rule , getMatchingPropertyList", WARNING,
"Hardcoded properties set, please define your rule correctly")
property_list=['order',]
return property_list
def _getInputMovementList(self, applied_rule): def _getInputMovementList(self, applied_rule):
"""Input movement list comes from order""" """Input movement list comes from order"""
order = applied_rule.getDefaultCausalityValue() order = applied_rule.getDefaultCausalityValue()
......
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