Commit 6688dcf6 authored by Łukasz Nowak's avatar Łukasz Nowak

- _getExpandablePropertyUpdateDict do not need **kw, current_property_dict is more important

 - do BPMInvoiceTransactionRule more like other BPM rules - follow naming, remove hardcoding
 - provide matching_property as rule configuration to compare movements with previsions
 - force using _list for categories (XXX: mixing category and category_list in edit leads to errors)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28171 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 50d417b2
...@@ -56,8 +56,8 @@ class BPMDeliveryRule(BPMRule): ...@@ -56,8 +56,8 @@ class BPMDeliveryRule(BPMRule):
portal_type=delivery.getPortalDeliveryMovementTypeList()) portal_type=delivery.getPortalDeliveryMovementTypeList())
return [] return []
def _getExpandablePropertyUpdateDict(self, applied_rule, movement, business_path, def _getExpandablePropertyUpdateDict(self, applied_rule, movement,
**kw): business_path, current_property_dict):
"""Delivery specific update dict""" """Delivery specific update dict"""
return { return {
'order_value': movement, 'order_value': movement,
......
...@@ -69,21 +69,21 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -69,21 +69,21 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
These previsions are actually returned as dictionaries. These previsions are actually returned as dictionaries.
""" """
prevision_list = [] prevision_list = []
context_movement = applied_rule.getParentValue() input_movement = applied_rule.getParentValue()
business_process = applied_rule.getBusinessProcessValue() business_process = applied_rule.getBusinessProcessValue()
movement_and_path_list = [] movement_and_path_list = []
for business_path in business_process.getPathValueList( for business_path in business_process.getPathValueList(
self.getProperty('trade_phase_list'), self.getProperty('trade_phase_list'),
context_movement): input_movement):
movement_and_path_list.append((context_movement, business_path)) movement_and_path_list.append((input_movement, business_path))
if len(movement_and_path_list) > 1: if len(movement_and_path_list) > 1:
raise NotImplementedError raise NotImplementedError
# Find a matching cell # Find a matching cell
cell = self._getMatchingCell(context_movement) cell = self._getMatchingCell(input_movement)
if cell is not None : # else, we do nothing if cell is not None : # else, we do nothing
for accounting_rule_cell_line in cell.objectValues() : for accounting_rule_cell_line in cell.objectValues() :
...@@ -95,7 +95,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -95,7 +95,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
# * price_currency from the top level simulation movement's # * price_currency from the top level simulation movement's
# orderValue # orderValue
resource = None resource = None
invoice_line = context_movement.getDeliveryValue() invoice_line = input_movement.getDeliveryValue()
if invoice_line is not None : if invoice_line is not None :
invoice = invoice_line.getExplanationValue() invoice = invoice_line.getExplanationValue()
resource = invoice.getProperty('resource', resource = invoice.getProperty('resource',
...@@ -123,33 +123,19 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -123,33 +123,19 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
# last resort : get the resource from the rule # last resort : get the resource from the rule
resource = accounting_rule_cell_line.getResource() \ resource = accounting_rule_cell_line.getResource() \
or cell.getResource() or cell.getResource()
# XXX Harcoded list prevision_line = {}
prevision_line = { prevision_line.update(**self._getExpandablePropertyDict(applied_rule,
'source': accounting_rule_cell_line.getSource(), input_movement, business_path))
'source_section': context_movement.getSourceSection(),
'source_decision': context_movement.getSourceDecision(), prevision_line.update(
'source_administration': context_movement \ source_list = [accounting_rule_cell_line.getSource()],
.getSourceAdministration(), destination_list = [accounting_rule_cell_line.getDestination()],
'source_project': context_movement.getSourceProject(), quantity = (input_movement.getCorrectedQuantity() *
'source_function': context_movement.getSourceFunction(), input_movement.getPrice(0.0)) *
'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(), accounting_rule_cell_line.getQuantity(),
'price': 1, resource_list = [resource],
'causality_value': business_path, price = 1,
} )
from Products.ERP5Type.Document import newTempSimulationMovement from Products.ERP5Type.Document import newTempSimulationMovement
temporary_movement = newTempSimulationMovement(self.getPortalObject(), temporary_movement = newTempSimulationMovement(self.getPortalObject(),
'1', **prevision_line) '1', **prevision_line)
...@@ -158,7 +144,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -158,7 +144,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
if resource is not None: if resource is not None:
currency = self.restrictedTraverse(resource) currency = self.restrictedTraverse(resource)
currency_url = currency.getRelativeUrl() currency_url = currency.getRelativeUrl()
destination_section = prevision_line['destination_section'] destination_section = prevision_line['destination_section_list'][0]
if destination_section is not None: if destination_section is not None:
destination_currency_url = self.restrictedTraverse( destination_currency_url = self.restrictedTraverse(
destination_section).getProperty('price_currency', None) destination_section).getProperty('price_currency', None)
...@@ -178,10 +164,10 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -178,10 +164,10 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
(destination_exchange_ratio* (destination_exchange_ratio*
applied_rule.getParentValue().getTotalPrice()),precision)) 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: if source_section is not None:
source_currency_url = self.restrictedTraverse( source_currency_url = self.restrictedTraverse(
'source_section').getProperty('price_currency', None) source_section).getProperty('price_currency', None)
else: else:
source_currency_url = None source_currency_url = None
if source_currency_url is not None \ if source_currency_url is not None \
...@@ -202,7 +188,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix): ...@@ -202,7 +188,7 @@ class BPMInvoiceTransactionRule(BPMRule, PredicateMatrix):
'generate_prevision_script_id'): 'generate_prevision_script_id'):
generate_prevision_script_id = \ generate_prevision_script_id = \
accounting_rule_cell_line.getGeneratePrevisionScriptId() accounting_rule_cell_line.getGeneratePrevisionScriptId()
prevision_line.update(getattr(context_movement, prevision_line.update(getattr(input_movement,
generate_prevision_script_id)(prevision_line)) generate_prevision_script_id)(prevision_line))
prevision_list.append(prevision_line) prevision_list.append(prevision_line)
return prevision_list return prevision_list
......
...@@ -61,8 +61,8 @@ class BPMInvoicingRule(BPMRule): ...@@ -61,8 +61,8 @@ class BPMInvoicingRule(BPMRule):
return 0 return 0
#### Helper methods for expand #### Helper methods for expand
def _getExpandablePropertyUpdateDict(self, applied_rule, movement, business_path, def _getExpandablePropertyUpdateDict(self, applied_rule, movement,
**kw): business_path, current_property_dict):
return { return {
'deliverable': 1 'deliverable': 1
} }
......
...@@ -55,8 +55,8 @@ class BPMOrderRule(BPMDeliveryRule): ...@@ -55,8 +55,8 @@ class BPMOrderRule(BPMDeliveryRule):
portal_type=order.getPortalOrderMovementTypeList()) portal_type=order.getPortalOrderMovementTypeList())
return [] return []
def _getExpandablePropertyUpdateDict(self, applied_rule, movement, business_path, def _getExpandablePropertyUpdateDict(self, applied_rule, movement,
**kw): business_path, current_property_dict):
"""Order rule specific update dictionary""" """Order rule specific update dictionary"""
return { return {
'order_value': movement, 'order_value': movement,
......
...@@ -73,6 +73,7 @@ class BPMRule(Predicate, XMLObject): ...@@ -73,6 +73,7 @@ class BPMRule(Predicate, XMLObject):
, PropertySheet.Reference , PropertySheet.Reference
, PropertySheet.Version , PropertySheet.Version
, PropertySheet.AppliedRule , PropertySheet.AppliedRule
, PropertySheet.BPMAppliedRule
) )
movement_type = 'Simulation Movement' movement_type = 'Simulation Movement'
...@@ -161,7 +162,8 @@ class BPMRule(Predicate, XMLObject): ...@@ -161,7 +162,8 @@ class BPMRule(Predicate, XMLObject):
return 1 return 1
#### Helpers to overload #### 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 """Rule specific dictionary used to update _getExpandablePropertyDict
This method might be overloaded. This method might be overloaded.
""" """
...@@ -231,11 +233,7 @@ class BPMRule(Predicate, XMLObject): ...@@ -231,11 +233,7 @@ class BPMRule(Predicate, XMLObject):
return (immutable_movement_list, mutable_movement_list, return (immutable_movement_list, mutable_movement_list,
deletable_movement_list) deletable_movement_list)
def _getCompensatedMovementList(self, applied_rule, def _getCompensatedMovementList(self, applied_rule, **kw):
matching_property_list=(
'resource_list',
'variation_category_list',
'variation_property_dict',), **kw):
""" """
Compute the difference between prevision and existing movements Compute the difference between prevision and existing movements
...@@ -259,7 +257,7 @@ class BPMRule(Predicate, XMLObject): ...@@ -259,7 +257,7 @@ class BPMRule(Predicate, XMLObject):
for prevision in prevision_list: for prevision in prevision_list:
p_matched_list = [] p_matched_list = []
for movement in non_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): if prevision.get(prop) != movement.getProperty(prop):
break break
else: else:
...@@ -345,9 +343,13 @@ class BPMRule(Predicate, XMLObject): ...@@ -345,9 +343,13 @@ class BPMRule(Predicate, XMLObject):
for base_category in \ for base_category in \
business_path.getSourceBaseCategoryList() +\ business_path.getSourceBaseCategoryList() +\
business_path.getDestinationBaseCategoryList(): business_path.getDestinationBaseCategoryList():
property_dict[base_category] = business_path\ # XXX: we need to use _list for categories *always*
.getDefaultAcquiredCategoryMembership(base_category, category_url = business_path.getDefaultAcquiredCategoryMembership(
context=movement) 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 # Amount
if business_path.getQuantity(): if business_path.getQuantity():
property_dict['quantity'] = business_path.getQuantity() property_dict['quantity'] = business_path.getQuantity()
...@@ -371,7 +373,7 @@ class BPMRule(Predicate, XMLObject): ...@@ -371,7 +373,7 @@ class BPMRule(Predicate, XMLObject):
# rule specific # rule specific
property_dict.update(**self._getExpandablePropertyUpdateDict(applied_rule, property_dict.update(**self._getExpandablePropertyUpdateDict(applied_rule,
movement, business_path, **kw)) movement, business_path, property_dict))
return property_dict return property_dict
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment