From 7c06e986ae3a597e97585d11890ee7edc0807608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com> Date: Wed, 9 Sep 2009 13:39:37 +0000 Subject: [PATCH] - reuse all what possible from Rule class - TODOs are done - remove duplicated properties (add_permission, isPortalContent, isRADContent) - use _list as canonical reference for categories git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28877 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/TradeModelRule.py | 76 ++++--------------------- 1 file changed, 11 insertions(+), 65 deletions(-) diff --git a/product/ERP5/Document/TradeModelRule.py b/product/ERP5/Document/TradeModelRule.py index d5aedd1fb2..c94609f050 100644 --- a/product/ERP5/Document/TradeModelRule.py +++ b/product/ERP5/Document/TradeModelRule.py @@ -36,16 +36,9 @@ class TradeModelRule(Rule): """ Rule for Trade Model """ - # TODO: - # * override overrideable helpers - # * more usage of Business Process (remove 'if 0' conditions) - # CMF Type Definition meta_type = 'ERP5 Trade Model Rule' portal_type = 'Trade Model Rule' - add_permission = Permissions.AddPortalContent - isPortalContent = 1 - isRADContent = 1 # Declarative security security = ClassSecurityInfo() @@ -54,58 +47,6 @@ class TradeModelRule(Rule): def _isBPM(self): return True - def _getMovementDictByBusinessPath(self, movement, business_path_list): - """Sets Business Path's provided values""" - if len(business_path_list) > 1: - raise NotImplementedError('Only one path supported') - - business_path = business_path_list[0] - movement_dict = {} - - if 0: # XXX use arrow from path (not working currently) - for base_category in \ - business_path.getSourceArrowBaseCategoryList() +\ - business_path.getDestinationArrowBaseCategoryList(): - movement_dict[base_category] = business_path\ - .getDefaultAcquiredCategoryMembership(base_category, - context=movement) - print base_category, movement_dict[base_category] - else: - movement_dict['source'] = movement.getSource() - movement_dict['source_section'] = movement.getSourceSection() - movement_dict['source_administration'] = \ - movement.getSourceAdministration() - movement_dict['destination'] = movement.getDestination() - movement_dict['destination_section'] = movement.getDestinationSection() - movement_dict['destination_administration'] = \ - movement.getDestinationAdministration() - - if business_path.getQuantity(): - movement_dict['quantity'] = business_path.getQuantity() - elif business_path.getEfficiency(): - movement_dict['quantity'] = movement.getQuantity() * \ - business_path.getEfficiency() - else: - movement_dict['quantity'] = movement.getQuantity() - - if 0: # XXX use path date calculation system - movement_dict['start_date'] = business_path \ - .getExpectedStartDate(movement) - movement_dict['stop_date'] = business_path.getExpectedStopDate(movement) - else: - movement_dict['start_date'] = movement.getStartDate() - movement_dict['stop_date'] = movement.getStopDate() - - movement_dict['causality_value'] = business_path - - return movement_dict - - def _getStaticPropertyDict(self, context_movement): - movement_kw = {} - for prop in self.getExpandablePropertyList(): - movement_kw[prop] = context_movement.getProperty(prop) - return movement_kw - def _generatePrevisionList(self, applied_rule, **kw): """Generates list of movements (as dicts), and let parent class to decide which is to add, modify or delete""" @@ -118,18 +59,23 @@ class TradeModelRule(Rule): context_movement = applied_rule.getParentValue() for amount in trade_condition.getAggregatedAmountList(context_movement): - # everything static - movement_kw = self._getStaticPropertyDict(context_movement) - # business path specific business_path_list = business_process.getPathValueList( trade_phase=amount.getTradePhaseList()) - movement_kw.update(**self._getMovementDictByBusinessPath( - context_movement, business_path_list)) + if len(business_path_list) == 0: + raise ValueError('Cannot find Business Path') + + if len(business_path_list) != 1: + raise NotImplementedError('Only one Business Path is supported') + + business_path = business_path_list[0] + + movement_kw = self._getExpandablePropertyDict(applied_rule, + context_movement, business_path) # rule specific movement_kw['price'] = amount.getProperty('price') - movement_kw['resource'] = amount.getProperty('resource') + movement_kw['resource_list'] = amount.getProperty('resource_list') movement_kw['reference'] = amount.getProperty('reference') movement_kw['quantity'] = amount.getProperty('quantity') movement_kw['base_application_list'] = amount.getProperty( -- 2.30.9