Commit b42090ba authored by Julien Muchembled's avatar Julien Muchembled

Fix trade module simulation rule

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37448 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b78a14da
......@@ -92,19 +92,12 @@ class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predic
class TradeModelRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, movement_list=None, rounding=False):
"""
Generates list of movements
XXX-JPS This could become a good default implementation
but I do not understand why input system not used here
(I will rewrite this)
"""
result = []
def _getInputMovementList(self, movement_list=None, rounding=False):
simulation_movement = self._applied_rule.getParentValue()
trade_model = simulation_movement.asComposedDocument()
if trade_model is None:
return result
return
rule = self._applied_rule.getSpecialiseValue()
for amount in simulation_movement.getAggregatedAmountList(
......@@ -112,38 +105,6 @@ class TradeModelRuleMovementGenerator(MovementGeneratorMixin):
amount_generator_type_list=('Purchase Trade Condition',
'Sale Trade Condition',
'Trade Model Line')):
# business path specific
business_path_list = trade_model.getPathValueList(
trade_phase=amount.getTradePhaseList()) # Why a list of trade phases ? XXX-JPS
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]
kw = self._getPropertyAndCategoryList(simulation_movement, business_path,
rule)
# rule specific
kw['price'] = amount.getPrice() or amount.getEfficiency()
kw['resource'] = amount.getProperty('resource_list') # Inconsistent... list and not list XXX-JPS
kw['reference'] = amount.getProperty('reference')
kw['quantity'] = amount.getProperty('quantity')
kw['base_application'] = amount.getProperty(
'base_application_list')
kw['base_contribution'] = amount.getProperty(
'base_contribution_list')
kw['order'] = None
kw['delivery'] = None # Where does this come from ??? XXX-JPS - Why not None ?
# XXX-JPS Way too many properties are copied
simulation_movement = self._applied_rule.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
**kw)
result.append(simulation_movement)
return movement_list
yield self._applied_rule.newContent(
portal_type=RuleMixin.movement_type, temp_object=True,
**dict((k, v) for k, v in amount.__dict__.iteritems() if k[0] != '_'))
......@@ -131,7 +131,7 @@ class BusinessProcess(Path, XMLObject):
**kw -- same arguments as those passed to searchValues / contentValues
"""
if trade_phase is not None:
if not isinstance(trade_phase, (list, tuple)):
if isinstance(trade_phase, basestring):
trade_phase = (trade_phase,)
trade_phase = set([x.split('trade_phase/', 1)[-1] \
for x in trade_phase])
......@@ -693,10 +693,10 @@ class BusinessProcess(Path, XMLObject):
update_property_method --
"""
if trade_phase is None:
if not trade_phase:
trade_phase = amount.getTradePhase()
if trade_phase is None: raise ValueError("A trade_phase must be defined on the Amount or provided to getTradePhaseMovementList")
if not trade_phase:
raise ValueError("A trade_phase must be defined on the Amount or provided to getTradePhaseMovementList")
# Build a list of temp movements
from Products.ERP5Type.Document import newTempMovement
......
......@@ -130,8 +130,10 @@ class MovementGeneratorMixin:
return movement_trade_phase
if self._trade_phase_list:
return self._trade_phase_list
if self._rule:
return self._rule.getTradePhaseList()
if self._rule is not None:
trade_phase_list = self._rule.getTradePhaseList()
if trade_phase_list:
return trade_phase_list
return business_process.getTradePhaseList()
def _getInputMovementList(self, movement_list=None, rounding=None): #XXX-JPS should it be amount or movement ?
......
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