diff --git a/product/ERP5/Document/BusinessProcess.py b/product/ERP5/Document/BusinessProcess.py index e0d4d93a4f2b52f3c7d206fa60f49c8c14357999..3cec00aeff871748f5f82efc9cd14a1c187175c8 100644 --- a/product/ERP5/Document/BusinessProcess.py +++ b/product/ERP5/Document/BusinessProcess.py @@ -203,3 +203,53 @@ class BusinessProcess(Path, XMLObject): path_list = self.objectValues(portal_type=self.getPortalBusinessPathTypeList()) return filter(None, [path.getTradePhase() for path in path_list]) + + def getRootExplanationPathValue(self): + """ + Returns a root path of this business process + """ + path_list = self.objectValues(portal_type=self.getPortalBusinessPathTypeList()) + path_list = filter(lambda x: x.isDeliverable(), path_list) + + if len(path_list) > 1: + raise Exception, "this business process has multi root paths" + + if len(path_list) == 1: + return path_list[0] + + def getHeadPathValueList(self, trade_phase_list=None): + """ + Returns a list of head path(s) of this business process + + trade_phase_list -- used to filterring, means that discovering + a list of head path with the trade_phase_list + """ + head_path_list = list() + for state in self.getStateValueList(): + if len(state.getSuccessorRelatedValueList()) == 0: + head_path_list += state.getPredecessorRelatedValueList() + + if trade_phase_list is not None: + _set = set(trade_phase_list) + _list = list() + # start to discover a head path with the trade_phase_list from head path(s) of whole + for path in head_path_list: + _list += self._getHeadPathValueList(path, _set) + head_path_list = map(lambda t: t[0], filter(lambda t: t != (None, None), _list)) + + return head_path_list + + def _getHeadPathValueList(self, path, trade_phase_set): + # if the path has target trade_phase, it is a head path. + _set = set(path.getTradePhaseList()) + if _set & trade_phase_set: + return [(path, _set & trade_phase_set)] + + node = path.getSuccessorValue() + if node is None: + return [(None, None)] + + _list = list() + for next_path in node.getPredecessorRelatedValueList(): + _list += self._getHeadPathValueList(next_path, trade_phase_set) + return _list diff --git a/product/ERP5/tests/testMRP.py b/product/ERP5/tests/testMRP.py index d111730d872490701036affef20d7fd2c034e654..727ab1872e2f2a092e0cdbba850f0315cee7f35e 100644 --- a/product/ERP5/tests/testMRP.py +++ b/product/ERP5/tests/testMRP.py @@ -254,7 +254,7 @@ class TestMRPMixin(TestBPMMixin): class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase): """the test for implementation""" def test_TransformationRule_getHeadProductionPathList(self): - rule = self.portal.portal_rules.default_transformation_rule + rule = self.portal.portal_rules.default_transformation_model_rule transformation = self.createDefaultTransformation() @@ -303,7 +303,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase): # test mock applied_rule = movement.newContent(potal_type='Applied Rule') - rule = self.portal.portal_rules.default_transformation_rule + rule = self.portal.portal_rules.default_transformation_model_rule rule.expand(applied_rule) # assertion @@ -367,7 +367,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase): # test mock applied_rule = movement.newContent(potal_type='Applied Rule') - rule = self.portal.portal_rules.default_transformation_rule + rule = self.portal.portal_rules.default_transformation_model_rule rule.expand(applied_rule) # assertion @@ -428,7 +428,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase): movement._baseSetFrozen(1) # re-expand - rule = self.portal.portal_rules.default_transformation_rule + rule = self.portal.portal_rules.default_transformation_model_rule rule.expand(applied_rule) # assertion @@ -506,7 +506,7 @@ class TestMRPImplementation(TestMRPMixin, ERP5TypeTestCase): # test mock applied_rule = movement.newContent(potal_type='Applied Rule') - rule = self.portal.portal_rules.default_transformation_sourcing_rule + rule = self.portal.portal_rules.default_transformation_sourcing_model_rule rule.expand(applied_rule) # assertion