diff --git a/product/ERP5/Document/BPMDeliveryRule.py b/product/ERP5/Document/BPMDeliveryRule.py index 88f5820d28afbe5c72a3e9377b99e241a9ee7763..183d1334b8f9e7ac68f3eb35953bde1b26accc35 100644 --- a/product/ERP5/Document/BPMDeliveryRule.py +++ b/product/ERP5/Document/BPMDeliveryRule.py @@ -56,8 +56,8 @@ class BPMDeliveryRule(BPMRule): portal_type=delivery.getPortalDeliveryMovementTypeList()) return [] - def _getExpandablePropertyUpdateDict(self, applied_rule, movement, business_path, - **kw): + def _getExpandablePropertyUpdateDict(self, applied_rule, movement, + business_path, current_property_dict): """Delivery specific update dict""" return { 'order_value': movement, diff --git a/product/ERP5/Document/BPMInvoiceTransactionRule.py b/product/ERP5/Document/BPMInvoiceTransactionRule.py index d2d4e3d255b7a1e9bf76de71defe68bc5fb5f6b6..5842bc00cae4df9be7cb8568f9fe99e61dc101ff 100644 --- a/product/ERP5/Document/BPMInvoiceTransactionRule.py +++ b/product/ERP5/Document/BPMInvoiceTransactionRule.py @@ -69,21 +69,21 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): These previsions are actually returned as dictionaries. """ prevision_list = [] - context_movement = applied_rule.getParentValue() + input_movement = applied_rule.getParentValue() business_process = applied_rule.getBusinessProcessValue() movement_and_path_list = [] for business_path in business_process.getPathValueList( self.getProperty('trade_phase_list'), - context_movement): - movement_and_path_list.append((context_movement, business_path)) + input_movement): + movement_and_path_list.append((input_movement, business_path)) if len(movement_and_path_list) > 1: raise NotImplementedError # Find a matching cell - cell = self._getMatchingCell(context_movement) + cell = self._getMatchingCell(input_movement) if cell is not None : # else, we do nothing for accounting_rule_cell_line in cell.objectValues() : @@ -95,7 +95,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): # * price_currency from the top level simulation movement's # orderValue resource = None - invoice_line = context_movement.getDeliveryValue() + invoice_line = input_movement.getDeliveryValue() if invoice_line is not None : invoice = invoice_line.getExplanationValue() resource = invoice.getProperty('resource', @@ -123,33 +123,19 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): # last resort : get the resource from the rule resource = accounting_rule_cell_line.getResource() \ or cell.getResource() - # XXX Harcoded list - prevision_line = { - 'source': accounting_rule_cell_line.getSource(), - 'source_section': context_movement.getSourceSection(), - 'source_decision': context_movement.getSourceDecision(), - 'source_administration': context_movement \ - .getSourceAdministration(), - 'source_project': context_movement.getSourceProject(), - 'source_function': context_movement.getSourceFunction(), - 'source_payment': context_movement.getSourcePayment(), - 'destination': accounting_rule_cell_line.getDestination(), - 'destination_section': context_movement.getDestinationSection(), - 'destination_decision': context_movement.getDestinationDecision(), - 'destination_administration': context_movement \ - .getDestinationAdministration(), - 'destination_project': context_movement.getDestinationProject(), - 'destination_function': context_movement.getDestinationFunction(), - 'destination_payment': context_movement.getDestinationPayment(), - 'start_date': context_movement.getStartDate(), - 'stop_date': context_movement.getStopDate(), - 'resource': resource, - 'quantity': (context_movement.getCorrectedQuantity() * - context_movement.getPrice(0.0)) * - accounting_rule_cell_line.getQuantity(), - 'price': 1, - 'causality_value': business_path, - } + prevision_line = {} + prevision_line.update(**self._getExpandablePropertyDict(applied_rule, + input_movement, business_path)) + + prevision_line.update( + source_list = [accounting_rule_cell_line.getSource()], + destination_list = [accounting_rule_cell_line.getDestination()], + quantity = (input_movement.getCorrectedQuantity() * + input_movement.getPrice(0.0)) * + accounting_rule_cell_line.getQuantity(), + resource_list = [resource], + price = 1, + ) from Products.ERP5Type.Document import newTempSimulationMovement temporary_movement = newTempSimulationMovement(self.getPortalObject(), '1', **prevision_line) @@ -158,7 +144,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): if resource is not None: currency = self.restrictedTraverse(resource) currency_url = currency.getRelativeUrl() - destination_section = prevision_line['destination_section'] + destination_section = prevision_line['destination_section_list'][0] if destination_section is not None: destination_currency_url = self.restrictedTraverse( destination_section).getProperty('price_currency', None) @@ -178,10 +164,10 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): (destination_exchange_ratio* applied_rule.getParentValue().getTotalPrice()),precision)) - source_section = prevision_line['source_section'] + source_section = prevision_line['source_section_list'][0] if source_section is not None: source_currency_url = self.restrictedTraverse( - 'source_section').getProperty('price_currency', None) + source_section).getProperty('price_currency', None) else: source_currency_url = None if source_currency_url is not None \ @@ -202,7 +188,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): 'generate_prevision_script_id'): generate_prevision_script_id = \ accounting_rule_cell_line.getGeneratePrevisionScriptId() - prevision_line.update(getattr(context_movement, + prevision_line.update(getattr(input_movement, generate_prevision_script_id)(prevision_line)) prevision_list.append(prevision_line) return prevision_list diff --git a/product/ERP5/Document/BPMInvoicingRule.py b/product/ERP5/Document/BPMInvoicingRule.py index 60082970e45e1c333026a4a3c0bdfc7c091f6986..0c9329d729b4d30ca976ab4b7de71fe587a9a385 100644 --- a/product/ERP5/Document/BPMInvoicingRule.py +++ b/product/ERP5/Document/BPMInvoicingRule.py @@ -61,8 +61,8 @@ class BPMInvoicingRule(BPMRule): return 0 #### Helper methods for expand - def _getExpandablePropertyUpdateDict(self, applied_rule, movement, business_path, - **kw): + def _getExpandablePropertyUpdateDict(self, applied_rule, movement, + business_path, current_property_dict): return { 'deliverable': 1 } diff --git a/product/ERP5/Document/BPMOrderRule.py b/product/ERP5/Document/BPMOrderRule.py index 644a86694197a1ac1216eb487160c9f659972b06..6f0d054fb3b21ea50333ecc5e14b69bf2796fcbb 100644 --- a/product/ERP5/Document/BPMOrderRule.py +++ b/product/ERP5/Document/BPMOrderRule.py @@ -55,8 +55,8 @@ class BPMOrderRule(BPMDeliveryRule): portal_type=order.getPortalOrderMovementTypeList()) return [] - def _getExpandablePropertyUpdateDict(self, applied_rule, movement, business_path, - **kw): + def _getExpandablePropertyUpdateDict(self, applied_rule, movement, + business_path, current_property_dict): """Order rule specific update dictionary""" return { 'order_value': movement, diff --git a/product/ERP5/Document/BPMRule.py b/product/ERP5/Document/BPMRule.py index e50f4560ac08691d3971947eb7eaf6abb8af6f09..52205179ffba7fec2d1fd2343ff80c27bea4f93a 100644 --- a/product/ERP5/Document/BPMRule.py +++ b/product/ERP5/Document/BPMRule.py @@ -73,6 +73,7 @@ class BPMRule(Predicate, XMLObject): , PropertySheet.Reference , PropertySheet.Version , PropertySheet.AppliedRule + , PropertySheet.BPMAppliedRule ) movement_type = 'Simulation Movement' @@ -161,7 +162,8 @@ class BPMRule(Predicate, XMLObject): return 1 #### Helpers to overload - def _getExpandablePropertyUpdateDict(self, applied_rule, movement, business_path, **kw): + def _getExpandablePropertyUpdateDict(self, applied_rule, movement, + business_path, current_property_dict): """Rule specific dictionary used to update _getExpandablePropertyDict This method might be overloaded. """ @@ -231,11 +233,7 @@ class BPMRule(Predicate, XMLObject): return (immutable_movement_list, mutable_movement_list, deletable_movement_list) - def _getCompensatedMovementList(self, applied_rule, - matching_property_list=( - 'resource_list', - 'variation_category_list', - 'variation_property_dict',), **kw): + def _getCompensatedMovementList(self, applied_rule, **kw): """ Compute the difference between prevision and existing movements @@ -259,7 +257,7 @@ class BPMRule(Predicate, XMLObject): for prevision in prevision_list: p_matched_list = [] for movement in non_matched_list: - for prop in matching_property_list: + for prop in self.getMatchingPropertyList(): if prevision.get(prop) != movement.getProperty(prop): break else: @@ -345,9 +343,13 @@ class BPMRule(Predicate, XMLObject): for base_category in \ business_path.getSourceBaseCategoryList() +\ business_path.getDestinationBaseCategoryList(): - property_dict[base_category] = business_path\ - .getDefaultAcquiredCategoryMembership(base_category, - context=movement) + # XXX: we need to use _list for categories *always* + category_url = business_path.getDefaultAcquiredCategoryMembership( + base_category, context=movement) + if category_url not in ['', None]: + property_dict['%s_list' % base_category] = [category_url] + else: + property_dict['%s_list' % base_category] = [] # Amount if business_path.getQuantity(): property_dict['quantity'] = business_path.getQuantity() @@ -371,7 +373,7 @@ class BPMRule(Predicate, XMLObject): # rule specific property_dict.update(**self._getExpandablePropertyUpdateDict(applied_rule, - movement, business_path, **kw)) + movement, business_path, property_dict)) return property_dict security.declareProtected(Permissions.ModifyPortalContent, 'expand')