Commit cf30150a authored by Jean-Paul Smets's avatar Jean-Paul Smets

Remove context from API, try to remove some duplicate code

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@34983 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 98996d07
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
...@@ -71,11 +72,11 @@ class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Pred ...@@ -71,11 +72,11 @@ class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Pred
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return DeliveryRuleMovementGenerator() return DeliveryRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -83,7 +84,7 @@ class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Pred ...@@ -83,7 +84,7 @@ class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Pred
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -95,41 +96,22 @@ class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Pred ...@@ -95,41 +96,22 @@ class DeliveryRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Pred
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class DeliveryRuleMovementGenerator(MovementGeneratorMixin): class DeliveryRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None,
rounding=False):
"""
Input movement list comes from delivery
"""
ret = []
rule = context.getSpecialiseValue()
for input_movement, business_path in self \
._getInputMovementAndPathTupleList(context):
kw = self._getPropertyAndCategoryList(input_movement, business_path,
rule)
input_movement_url = input_movement.getRelativeUrl()
kw.update({'delivery':input_movement_url})
simulation_movement = context.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
**kw)
ret.append(simulation_movement)
return ret
def _getInputMovementList(self, context): def _getInputMovementList(self, movement_list=None, rounding=None):
"""Input movement list comes from delivery""" """Input movement list comes from delivery"""
delivery = context.getDefaultCausalityValue() delivery = self._applied_rule.getDefaultCausalityValue()
if delivery is None: if delivery is None:
return [] return []
else: else:
ret = [] result = []
existing_movement_list = context.objectValues() existing_movement_list = self._applied_rule.objectValues()
for movement in delivery.getMovementList( for movement in delivery.getMovementList(
portal_type=delivery.getPortalDeliveryMovementTypeList()): portal_type=delivery.getPortalDeliveryMovementTypeList()):
simulation_movement = self._getDeliveryRelatedSimulationMovement(movement) simulation_movement = self._getDeliveryRelatedSimulationMovement(movement)
if simulation_movement is None or \ if simulation_movement is None or \
simulation_movement in existing_movement_list: simulation_movement in existing_movement_list:
ret.append(movement) result.append(movement)
return ret return result
def _getDeliveryRelatedSimulationMovement(self, delivery_movement): def _getDeliveryRelatedSimulationMovement(self, delivery_movement):
"""Helper method to get the delivery related simulation movement. """Helper method to get the delivery related simulation movement.
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
...@@ -71,11 +72,11 @@ class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicat ...@@ -71,11 +72,11 @@ class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicat
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return DeliveryRuleMovementGenerator() return DeliveryRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -83,7 +84,7 @@ class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicat ...@@ -83,7 +84,7 @@ class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicat
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -95,24 +96,12 @@ class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicat ...@@ -95,24 +96,12 @@ class DeliverySimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicat
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class DeliveryRuleMovementGenerator(MovementGeneratorMixin): class DeliveryRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None,
rounding=False):
"""
Input movement list comes from the parent
"""
ret = []
rule = context.getSpecialiseValue()
for input_movement, business_path in self \
._getInputMovementAndPathTupleList(context):
kw = self._getPropertyAndCategoryList(input_movement, business_path,
rule)
kw.update({'order':None,'delivery':None})
simulation_movement = context.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
**kw)
ret.append(simulation_movement)
return ret
def _getInputMovementList(self, context): def _getUpdatePropertyDict(self, input_movement):
return [context.getParentValue(),] # Override default mixin implementation
return {'order': None,
'delivery': None,
'portal_type': RuleMixin.movement_type}
def _getInputMovementList(self, movement_list=None, rounding=None):
return [self._applied_rule.getParentValue(),]
...@@ -70,11 +70,11 @@ class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predi ...@@ -70,11 +70,11 @@ class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predi
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return InvoiceRuleMovementGenerator() return InvoiceRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -82,7 +82,7 @@ class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predi ...@@ -82,7 +82,7 @@ class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predi
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -94,34 +94,15 @@ class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predi ...@@ -94,34 +94,15 @@ class InvoiceRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predi
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class InvoiceRuleMovementGenerator(MovementGeneratorMixin): class InvoiceRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None,
rounding=False):
"""
Input movement list comes from delivery
"""
ret = []
rule = context.getSpecialiseValue()
for input_movement, business_path in self \
._getInputMovementAndPathTupleList(context):
kw = self._getPropertyAndCategoryList(input_movement, business_path,
rule)
input_movement_url = input_movement.getRelativeUrl()
kw.update({'delivery':input_movement_url})
simulation_movement = context.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
**kw)
ret.append(simulation_movement)
return ret
def _getInputMovementList(self, context): def _getInputMovementList(self, movement_list=None, rounding=None):
"""Input movement list comes from delivery""" """Input movement list comes from delivery"""
delivery = context.getDefaultCausalityValue() delivery = self._applied_rule.getDefaultCausalityValue()
if delivery is None: if delivery is None:
return [] return []
else: else:
ret = [] ret = []
existing_movement_list = context.objectValues() existing_movement_list = self._applied_rule.objectValues()
for movement in delivery.getMovementList( for movement in delivery.getMovementList(
portal_type=(delivery.getPortalInvoiceMovementTypeList() + \ portal_type=(delivery.getPortalInvoiceMovementTypeList() + \
delivery.getPortalTaxMovementTypeList())): # This is bad XXX-JPS - use use delivery.getPortalTaxMovementTypeList())): # This is bad XXX-JPS - use use
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -68,11 +69,11 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate ...@@ -68,11 +69,11 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return InvoicingRuleMovementGenerator() return InvoicingRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -80,7 +81,7 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate ...@@ -80,7 +81,7 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context, movement_list=None, rounding=None):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -92,31 +93,16 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate ...@@ -92,31 +93,16 @@ class InvoiceSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class InvoicingRuleMovementGenerator(MovementGeneratorMixin): class InvoicingRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None,
rounding=False): def _getUpdatePropertyDict(self, input_movement):
"""
In Invoice Simulation Rule, source should be source_administration
of the input movement or its order's source. Same for destination.
"""
ret = []
rule = context.getSpecialiseValue()
for input_movement, business_path in self \
._getInputMovementAndPathTupleList(context):
kw = self._getPropertyAndCategoryList(input_movement, business_path,
rule)
root_simulation_movement = input_movement.getRootSimulationMovement() root_simulation_movement = input_movement.getRootSimulationMovement()
source = input_movement.getSourceAdministration() or \ source = input_movement.getSourceAdministration() or \
root_simulation_movement.getSource() root_simulation_movement.getSource()
destination = input_movement.getDestinationAdministration() or \ destination = input_movement.getDestinationAdministration() or \
root_simulation_movement.getDestination() root_simulation_movement.getDestination()
kw.update({'order':None, 'delivery':None, return {'portal_type': RuleMixin.movement_type,
'order':None, 'delivery':None,
'source':source, 'destination':destination}) 'source':source, 'destination':destination})
simulation_movement = context.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
**kw)
ret.append(simulation_movement)
return ret
def _getInputMovementList(self, context): def _getInputMovementList(self, movement_list=None, rounding=None):
return [context.getParentValue(),] return [self._applied_rule.getParentValue(),]
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -72,11 +73,11 @@ class InvoiceTransactionSimulationRule(RuleMixin, MovementCollectionUpdaterMixin ...@@ -72,11 +73,11 @@ class InvoiceTransactionSimulationRule(RuleMixin, MovementCollectionUpdaterMixin
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return InvoiceTransactionRuleMovementGenerator() return InvoiceTransactionRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -84,7 +85,7 @@ class InvoiceTransactionSimulationRule(RuleMixin, MovementCollectionUpdaterMixin ...@@ -84,7 +85,7 @@ class InvoiceTransactionSimulationRule(RuleMixin, MovementCollectionUpdaterMixin
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -96,8 +97,7 @@ class InvoiceTransactionSimulationRule(RuleMixin, MovementCollectionUpdaterMixin ...@@ -96,8 +97,7 @@ class InvoiceTransactionSimulationRule(RuleMixin, MovementCollectionUpdaterMixin
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None, def getGeneratedMovementList(self, movement_list=None, rounding=False):
rounding=False):
""" """
Input movement list comes from order Input movement list comes from order
...@@ -106,11 +106,11 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): ...@@ -106,11 +106,11 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
""" """
ret = [] ret = []
rule = context.getSpecialiseValue() rule = self._rule
# input_movement, business_path = rule._getInputMovementAndPathTupleList( # input_movement, business_path = rule._getInputMovementAndPathTupleList(
# applied_rule)[0] # applied_rule)[0]
input_movement = context.getParentValue() input_movement = self._applied_rule.getParentValue()
parent_movement = context.getParentValue() parent_movement = self._applied_rule.getParentValue()
# Find a matching cell # Find a matching cell
cell = rule._getMatchingCell(input_movement) cell = rule._getMatchingCell(input_movement)
...@@ -133,7 +133,7 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): ...@@ -133,7 +133,7 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
if resource is None : if resource is None :
# search the resource on parents simulation movement's deliveries # search the resource on parents simulation movement's deliveries
simulation_movement = parent_movement simulation_movement = parent_movement
portal_simulation = context.getPortalObject().portal_simulation portal_simulation = self._applied_rule.getPortalObject().portal_simulation
while resource is None and \ while resource is None and \
simulation_movement != portal_simulation : simulation_movement != portal_simulation :
delivery = simulation_movement.getDeliveryValue() delivery = simulation_movement.getDeliveryValue()
...@@ -191,7 +191,7 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin): ...@@ -191,7 +191,7 @@ class InvoiceTransactionRuleMovementGenerator(MovementGeneratorMixin):
accounting_rule_cell_line.getGeneratePrevisionScriptId() accounting_rule_cell_line.getGeneratePrevisionScriptId()
kw.update(getattr(input_movement, kw.update(getattr(input_movement,
generate_prevision_script_id)(kw)) generate_prevision_script_id)(kw))
simulation_movement = context.newContent( simulation_movement = self._applied_rule.newContent(
portal_type=RuleMixin.movement_type, portal_type=RuleMixin.movement_type,
temp_object=True, temp_object=True,
**kw) **kw)
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
...@@ -71,11 +72,11 @@ class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predica ...@@ -71,11 +72,11 @@ class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predica
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return OrderRuleMovementGenerator() return OrderRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -83,7 +84,7 @@ class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predica ...@@ -83,7 +84,7 @@ class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predica
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -95,29 +96,10 @@ class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predica ...@@ -95,29 +96,10 @@ class OrderRootSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predica
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class OrderRuleMovementGenerator(MovementGeneratorMixin): class OrderRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None,
rounding=False):
"""
Input movement list comes from order
"""
ret = []
rule = context.getSpecialiseValue()
for input_movement, business_path in self \
._getInputMovementAndPathTupleList(context):
kw = self._getPropertyAndCategoryList(input_movement, business_path,
rule)
input_movement_url = input_movement.getRelativeUrl()
kw.update({'delivery':input_movement_url})
simulation_movement = context.newContent(
portal_type=RuleMixin.movement_type,
temp_object=True,
**kw)
ret.append(simulation_movement)
return ret
def _getInputMovementList(self, context): def _getInputMovementList(self, movement_list=None, rounding=None):
"""Input movement list comes from order""" """Input movement list comes from order"""
order = context.getDefaultCausalityValue() order = self._applied_rule.getDefaultCausalityValue()
if order is None: if order is None:
return [] return []
else: else:
......
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -69,11 +70,11 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate ...@@ -69,11 +70,11 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return PaymentRuleMovementGenerator() return PaymentRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -81,7 +82,7 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate ...@@ -81,7 +82,7 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -93,17 +94,16 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate ...@@ -93,17 +94,16 @@ class PaymentSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predicate
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class PaymentRuleMovementGenerator(MovementGeneratorMixin): class PaymentRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None, def getGeneratedMovementList(self, movement_list=None, rounding=False):
rounding=False):
""" """
Input movement list comes from parent. Input movement list comes from parent.
XXX This implementation using Business Path, not Payment Condition. XXX This implementation using Business Path, not Payment Condition.
""" """
ret = [] ret = []
rule = context.getSpecialiseValue() rule = self._rule
for input_movement, business_path in self \ for input_movement, business_path in self \
._getInputMovementAndPathTupleList(context): ._getInputMovementAndPathTupleList(movement_list=movement_list, rounding=rounding):
# Payment Rule does not work with Business Path # Payment Rule does not work with Business Path
if business_path is None: if business_path is None:
continue continue
...@@ -122,7 +122,7 @@ class PaymentRuleMovementGenerator(MovementGeneratorMixin): ...@@ -122,7 +122,7 @@ class PaymentRuleMovementGenerator(MovementGeneratorMixin):
if stop_date is not None: if stop_date is not None:
kw.update({'stop_date':stop_date}) kw.update({'stop_date':stop_date})
# one for payable # one for payable
simulation_movement = context.newContent( simulation_movement = self._applied_rule.newContent(
portal_type=RuleMixin.movement_type, portal_type=RuleMixin.movement_type,
temp_object=True, temp_object=True,
quantity=-quantity, quantity=-quantity,
...@@ -131,7 +131,7 @@ class PaymentRuleMovementGenerator(MovementGeneratorMixin): ...@@ -131,7 +131,7 @@ class PaymentRuleMovementGenerator(MovementGeneratorMixin):
# one for bank # one for bank
kw.update({'source':business_path.getSource(), kw.update({'source':business_path.getSource(),
'destination':business_path.getDestination(),}) 'destination':business_path.getDestination(),})
simulation_movement = context.newContent( simulation_movement = self._applied_rule.newContent(
portal_type=RuleMixin.movement_type, portal_type=RuleMixin.movement_type,
temp_object=True, temp_object=True,
quantity=quantity, quantity=quantity,
...@@ -139,5 +139,5 @@ class PaymentRuleMovementGenerator(MovementGeneratorMixin): ...@@ -139,5 +139,5 @@ class PaymentRuleMovementGenerator(MovementGeneratorMixin):
ret.append(simulation_movement) ret.append(simulation_movement)
return ret return ret
def _getInputMovementList(self, context): def _getInputMovementList(self, movement_list=None, rounding=None):
return [context.getParentValue(),] return [self._applied_rule.getParentValue(),]
...@@ -68,11 +68,11 @@ class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predic ...@@ -68,11 +68,11 @@ class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predic
PropertySheet.Rule PropertySheet.Rule
) )
def _getMovementGenerator(self): def _getMovementGenerator(self, context):
""" """
Return the movement generator to use in the expand process Return the movement generator to use in the expand process
""" """
return TradeModelRuleMovementGenerator() return TradeModelRuleMovementGenerator(applied_rule=context, rule=self)
def _getMovementGeneratorContext(self, context): def _getMovementGeneratorContext(self, context):
""" """
...@@ -80,7 +80,7 @@ class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predic ...@@ -80,7 +80,7 @@ class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predic
""" """
return context return context
def _getMovementGeneratorMovementList(self): def _getMovementGeneratorMovementList(self, context):
""" """
Return the movement lists to provide to the movement generator Return the movement lists to provide to the movement generator
""" """
...@@ -92,16 +92,20 @@ class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predic ...@@ -92,16 +92,20 @@ class TradeModelSimulationRule(RuleMixin, MovementCollectionUpdaterMixin, Predic
return (movement.getSource() is None or movement.getDestination() is None) return (movement.getSource() is None or movement.getDestination() is None)
class TradeModelRuleMovementGenerator(MovementGeneratorMixin): class TradeModelRuleMovementGenerator(MovementGeneratorMixin):
def getGeneratedMovementList(self, context, movement_list=None,
rounding=False): def getGeneratedMovementList(self, movement_list=None, rounding=False):
""" """
Generates list of movements 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)
""" """
movement_list = [] result = []
business_process = context.getBusinessProcessValue() simulation_movement = self._applied_rule.getParentValue()
trade_model = simulation_movement.asComposedDocument()
if business_process is None: if trade_model is None:
return movement_list return result
context_movement = context.getParentValue() context_movement = context.getParentValue()
rule = context.getSpecialiseValue() rule = context.getSpecialiseValue()
...@@ -111,7 +115,7 @@ class TradeModelRuleMovementGenerator(MovementGeneratorMixin): ...@@ -111,7 +115,7 @@ class TradeModelRuleMovementGenerator(MovementGeneratorMixin):
'Sale Trade Condition', 'Sale Trade Condition',
'Trade Model Line')): 'Trade Model Line')):
# business path specific # business path specific
business_path_list = business_process.getPathValueList( business_path_list = trade_model.getPathValueList(
trade_phase=amount.getTradePhaseList()) # Why a list of trade phases ? XXX-JPS trade_phase=amount.getTradePhaseList()) # Why a list of trade phases ? XXX-JPS
if len(business_path_list) == 0: if len(business_path_list) == 0:
raise ValueError('Cannot find Business Path') raise ValueError('Cannot find Business Path')
...@@ -142,6 +146,6 @@ class TradeModelRuleMovementGenerator(MovementGeneratorMixin): ...@@ -142,6 +146,6 @@ class TradeModelRuleMovementGenerator(MovementGeneratorMixin):
portal_type=RuleMixin.movement_type, portal_type=RuleMixin.movement_type,
temp_object=True, temp_object=True,
**kw) **kw)
movement_list.append(simulation_movement) result.append(simulation_movement)
return movement_list return movement_list
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