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