diff --git a/product/ERP5/Document/BusinessProcess.py b/product/ERP5/Document/BusinessProcess.py index 9a66542c282eeb748fd4f1cfb409b7e4198f74c6..e53b8e731cd7ab2b9c01e9bc89cfc0dc13eebd2b 100644 --- a/product/ERP5/Document/BusinessProcess.py +++ b/product/ERP5/Document/BusinessProcess.py @@ -37,6 +37,7 @@ from Products.ERP5.MovementCollectionDiff import _getPropertyAndCategoryList import zope.interface + class BusinessProcess(Path, XMLObject): """The BusinessProcess class is a container class which is used to describe business processes in the area of trade, payroll @@ -190,14 +191,14 @@ class BusinessProcess(Path, XMLObject): explanation_cache = _getExplanationCache(explanation) reference_date = explanation_cache.getReferenceDate(self, trade_date, reference_date_method_id) - # Computer start_date and stop_date (XXX-JPS this could be cached and accelerated) - start_date = reference_date + trade_model_path.getPaymentTerm(0) # XXX-JPS Until better naming + # Computer start_date and stop_date (XXX-JPS this could be cached and accelerated) + start_date = reference_date + trade_model_path.getPaymentTerm(0.0) # XXX-JPS Until better naming if delay_mode == 'min': - delay = trade_model_path.getMinDelay() + delay = trade_model_path.getMinDelay(0.0) elif delay_mode == 'max': - delay = trade_model_path.getMaxDelay() + delay = trade_model_path.getMaxDelay(0.0) else: - delay = (trade_model_path.getMaxDelay() + trade_model_path.getMinDelay()) / 2.0 + delay = (trade_model_path.getMaxDelay(0.0) + trade_model_path.getMinDelay(0.0)) / 2.0 stop_date = start_date + delay return start_date, stop_date @@ -656,7 +657,8 @@ class BusinessProcess(Path, XMLObject): return remaining_trade_phase_list security.declareProtected(Permissions.AccessContentsInformation, 'getTradePhaseMovementList') - def getTradePhaseMovementList(self, explanation, amount, trade_phase=None, delay_mode=None): + def getTradePhaseMovementList(self, explanation, amount, trade_phase=None, delay_mode=None, + update_property_dict=None): """Returns a list of movement with appropriate arrow and dates, based on the Business Link definitions, provided 'amount' and optional trade phases. If no trade_phase is provided, the trade_phase defined @@ -671,6 +673,8 @@ class BusinessProcess(Path, XMLObject): delay_mode -- optional value to specify calculation mode ('min', 'max') if no value specified use average delay + + update_property_method -- """ if trade_phase is None: trade_phase = amount.getTradePhase() @@ -682,10 +686,12 @@ class BusinessProcess(Path, XMLObject): result = [] id_index = 0 base_id = amount.getId() + if update_property_dict is None: update_property_dict = {} for trade_model_path in self.getTradeModelPathValueList(context=amount, trade_phase=trade_phase): id_index += 1 movement = newTempMovement(trade_model_path, '%s_%s' % (base_id, id_index)) kw = self._getPropertyAndCategoryDict(explanation, amount, trade_model_path, delay_mode=delay_mode) + kw.update(update_property_dict) movement._edit(**kw) result.append(movement) @@ -776,6 +782,9 @@ class BusinessProcess(Path, XMLObject): # Set causality to trade model path property_dict['causality'] = trade_model_path.getRelativeUrl() # XXX-JPS Will not work if we do not use real object + # Set trade_phase to the trade phase of trade_model_path + property_dict['trade_phase'] = trade_model_path.getTradePhase() + return property_dict # IBusinessProcess global API diff --git a/product/ERP5/mixin/rule.py b/product/ERP5/mixin/rule.py index 095ef5d4dba296fe13114ddf86b57d4425586e65..ac64139ac0b71f0e169269d0815de87fc81bdbb8 100644 --- a/product/ERP5/mixin/rule.py +++ b/product/ERP5/mixin/rule.py @@ -103,19 +103,18 @@ class MovementGeneratorMixin: folder = self._applied_rule # Build a list of movement and business path for input_movement in self._getInputMovementList(movement_list=movement_list, - rounding=rounding): + rounding=rounding): # Merge movement and business path properties (core implementation) # Lookup Business Process through composition (NOT UNION) business_process = input_movement.asComposedDocument() explanation = self._applied_rule # We use applied rule as local explanation trade_phase = self._getTradePhaseList(input_movement, business_process) # XXX-JPS not convenient to handle + # XXX-JPS trade phase of movement should be provided by movement + update_property_dict = self._getUpdatePropertyDict(input_movement) result.extend(business_process.getTradePhaseMovementList(explanation, input_movement, - trade_phase=trade_phase, delay_mode=None)) + trade_phase=trade_phase, delay_mode=None, + update_property_dict=update_property_dict)) - # Extend movement properties - for movement in result: - movement._edit(**self._getUpdatePropertyDict(movement)) - # And return list of generated movements return result @@ -125,6 +124,9 @@ class MovementGeneratorMixin: } def _getTradePhaseList(self, input_movement, business_process): # XXX-JPS WEIRD + movement_trade_phase = input_movement.getTradePhaseList() + if movement_trade_phase: + return movement_trade_phase if self._trade_phase_list: return self._trade_phase_list if self._rule: