From 7ed83fec7d2d817610d28e75c5d71deee1c70fda Mon Sep 17 00:00:00 2001 From: Kazuhiko Shiozaki <kazuhiko@nexedi.com> Date: Fri, 12 Feb 2010 06:50:59 +0000 Subject: [PATCH] * 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 --- product/ERP5/Document/DeliveryRule.py | 85 ++++++-------------------- product/ERP5/Document/OrderRule.py | 86 ++++++--------------------- 2 files changed, 34 insertions(+), 137 deletions(-) diff --git a/product/ERP5/Document/DeliveryRule.py b/product/ERP5/Document/DeliveryRule.py index 7771252665..f488824e50 100644 --- a/product/ERP5/Document/DeliveryRule.py +++ b/product/ERP5/Document/DeliveryRule.py @@ -61,74 +61,7 @@ class DeliveryRule(Rule): Else if the movement is not in current state, it can be modified. Else, it cannot be modified. """ - if self._isBPM(): - 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) + return Rule._expand(self, applied_rule, **kw) def _getDeliveryRelatedSimulationMovement(self, delivery_movement): """Helper method to get the delivery related simulation movement. @@ -268,3 +201,19 @@ class DeliveryRule(Rule): 'order': 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 diff --git a/product/ERP5/Document/OrderRule.py b/product/ERP5/Document/OrderRule.py index d4270bf220..316606079d 100644 --- a/product/ERP5/Document/OrderRule.py +++ b/product/ERP5/Document/OrderRule.py @@ -62,75 +62,7 @@ class OrderRule(DeliveryRule): delivered child, and is in order, it can be modified. Else, it cannot be modified. """ - if self._isBPM(): - 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) + return Rule._expand(self, applied_rule, force=force, **kw) security.declareProtected(Permissions.AccessContentsInformation, 'isStable') def isStable(self, applied_rule): @@ -185,6 +117,22 @@ class OrderRule(DeliveryRule): ) 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): """Input movement list comes from order""" order = applied_rule.getDefaultCausalityValue() -- 2.30.9