Commit 93f1d37a authored by Łukasz Nowak's avatar Łukasz Nowak

- provide a method to get first specialise value matching portal type list criteria for delivery

 - implement getBusinessProcessValue and getTradeConditionValue by searching up in simulation tree to find proper document


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26733 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3145fd28
......@@ -206,28 +206,54 @@ class AppliedRule(XMLObject):
return self
return self.getParentValue().getRootAppliedRule()
def _getExplanationSpecialiseValue(self, portal_type_list):
"""Returns first found specialise value of delivery or order
In case if self is root Applied Rule uses causality
Otherwise uses delivery, than order of parent movements
Recurses to parents"""
def findSpecialiseValueBySimulation(movement):
specialise_value = None
if movement.getPortalType() != 'Simulation Movement':
return None
delivery, order = movement.getDeliveryValue(), movement.getOrderValue()
if delivery is not None:
specialise_value = delivery.getExplanationValue() \
.getRootSpecialiseValue(portal_type_list)
if specialise_value is not None:
return specialise_value
if order is not None:
specialise_value = order.getExplanationValue() \
.getRootSpecialiseValue(portal_type_list)
if specialise_value is not None:
return specialise_value
return findSpecialiseValueBySimulation(movement.getParentValue() \
.getParentValue())
if self.getRootAppliedRule() == self:
return self.getCausalityValue() \
.getRootSpecialiseValue(portal_type_list)
movement = self.getParentValue()
return findSpecialiseValueBySimulation(movement)
security.declareProtected(Permissions.AccessContentsInformation,
'getTradeConditionValue')
def getTradeConditionValue(self):
"""Return the trade condition that has been used in this
simulation, or None if none has been used.
"""
return self._getExplanationSpecialiseValue(
('Purchase Trade Condition', 'Sale Trade Condition'))
security.declareProtected(Permissions.AccessContentsInformation,
'getBusinessProcessValue')
def getBusinessProcessValue(self):
"""Return the business process model that has been used in this
simulation, or None if no business process has been used.
simulation, or None if none has been used.
"""
root = self.getRootAppliedRule()
causality = root.getCausalityValue()
def findBusinessProcessModel(context):
if context.getPortalType() == 'Business Process':
return context
for specialise in context.getSpecialiseValueList():
business_process = findBusinessProcessModel(specialise)
if business_process is not None:
return business_process
if causality is not None and getattr(causality, 'getSpecialiseValueList',
None) is not None:
return findBusinessProcessModel(causality)
return None
return self._getExplanationSpecialiseValue(
('Business Process',))
security.declareProtected(Permissions.ModifyPortalContent,
'notifySimulationChange')
......
......@@ -884,3 +884,19 @@ class Delivery(XMLObject, ImmobilisationDelivery):
else:
raise 'SimulationError', '%s_getRuleReference script is missing.' \
% self.getPortalType()
security.declareProtected( Permissions.AccessContentsInformation,
'getRootSpecialiseValue')
def getRootSpecialiseValue(self, portal_type_list):
"""Returns first specialise value matching portal type"""
def findSpecialiseValue(context):
if context.getPortalType() in portal_type_list:
return context
if getattr(context, 'getSpecialiseValueList', None) is not None:
for specialise in context.getSpecialiseValueList():
specialise_value = findSpecialiseValue(specialise)
if specialise_value is not None:
return specialise_value
return None
return findSpecialiseValue(self)
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