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
master allow_login_change allow_login_change_wip arnau arnau-RD-Components-CacheTool arnau-RD-Components-Products-import-compat arnau-RD-Components-astroid_cache_per_component_reset arnau-RD-Components-erp5_crm arnau-RD-Components-erp5_trade-TODO-Interactor arnau-TM-Components-Migrate-PortalTransforms arnau-TM-Components-ModuleSecurityInfo arnau-TM-Components-PortalTransforms arnau-TM-FEC-output arnau-TM-isBuildable-with-multiple-BusinessLinks arnau-TM-jabber-client-desktop-notifications arnau-TM-newContent-temp_object arnau-TM-runUnitTest-clear-previous-execution-catalog arnau-TM-wkhtmltopdf arnau-WIP arnau-kns arnau-kns-without-property-mapping arnau-merge arnau-poc arnau-real-time-inventory-accounting auto_extend_select_list autoflake backup_erp5_workflow bk_erp5ish_actions_tool bk_sqlcatalog boc-interaction-drop bt5_config cache callable-jupyter-storage catalog_filter catalog_fulltext catalog_fulltext_old cedric cedriclen cedriclen-eos certificate_authority cherry-pick-4a8e045d cleanJSByJSLint clean_up_upgrader cleanup_acquisition_base_category cmf_upgrade_versions credential_update_action datetimefield deferred_listbox delivery_item_barcode douglas_forum dream_distributor dsn-phase3 enhance_scalability_testing eos-dev erp5-component erp5-forum erp5-imt erp5-messenger erp5-preference erp5-release erp5-slapos-upgrade erp5-util-testing erp5-vifib erp5-vifib-cleanup erp5_calendar erp5_catalog erp5_catalog_final erp5_corporate_identity erp5_free_subscription erp5_hal_json_style_fix_restricted_access_with_traverse erp5_payslip_migration erp5_workflow erp5testnode_max_timeout feat/ERP5JS_google_login feat/accept-multiple-portal-types-as-external-login feat/coding_style_form_naming feat/configurator_bt_categories feat/dms_implicit_predecessor_successor_fields feat/erp5_ide feat/inventory_api_group_by_time_interval_list feat/no_update_button feat/olapy feat/python_language_support feat/stock_browser_navigation feat/validated_currency feature/renderjs-ui-no-header fix/advance_ecommerce_coding_crimes fix/base_call_dialog_method_log fix/configurator_workflow_cleanups fix/login_validate_check_consistency fix/support-request-app-empty fix/test_result_after_mep fix/workflow_method_security for_testrunner_1 for_testrunner_2 for_testrunner_3 for_testrunner_4 gabriel gadget-json-value hotfix/rjs-formfields-padding improve_default_caching_policy_manager initsite interaction-drop isDeletable ivan jerome-bt-reference-doc jerome_graph_editor_renderjs jerome_user_preference_time_zone jio jm/form-action-guard js-ui kns lazy_simulation_causality lignan lingnan listbox_url macros_fix mame-test-stock-indexation master-erp5-test-result-scalability master-erp5-test-result-scalability-rebase master-test-fix-additionalbt5path mic_wind monitoring-graph mrp new-render-presentation no_longer_simulated_state officejs officejs_slideshow_editor pere portal_callables portal_solver_process_security_configuration presentation publish_recursiveReindexObject rebased_mrp refactor/base_edit reindex_calendar_after_change_calendar_exception reveal_editor reveal_editor_bak revert-38554dbe scalability-master scalability-master2 scalability-master2-rebase scalability-roque scalability-roque-2 scalability-run-command shop-box shop-box-rebase streaming_fix streaming_fix-0 syncml taskdistribution-xmlrpc-binary test_page testnode_software_link timezones tristan tristan-merge tristan-performance trustable-x-forwarded-for ttrm valentin_translation_fix view-aggregated-amounts vivekpab_renderjs_interfaces wenjie wenjie_branch wsgi wsgi-gevent wsgi_backport_setbody_lock wsgi_medusa_stream_fix yryr yryr-components-cp yryr-inventory-cache yryr-test yryr-with-components yusei 0.4.59.1 0.4.59 test-ui test-rjsacc test-rjs renderjs-test erp5.util-0.4.68 erp5.util-0.4.67 erp5.util-0.4.66 erp5.util-0.4.65 erp5.util-0.4.64 erp5.util-0.4.63 erp5.util-0.4.62 erp5.util-0.4.61 erp5.util-0.4.60 erp5.util-0.4.59.1 erp5.util-0.4.59 erp5.util-0.4.58 erp5.util-0.4.57 erp5.util-0.4.56 erp5.util-0.4.55 erp5.util-0.4.54 erp5.util-0.4.53 erp5.util-0.4.52 erp5.util-0.4.49 erp5.util-0.4.46 erp5.util-0.4.44 erp5.util-0.4.43 erp5.util-0.4.41 erp5.util-0.4.40 erp5.util-0.4.37 erp5.util-0.4.1 erp5.util-0.4 erp5.util-0.3 erp5.util-0.2 erp5.util-0.1
No related merge requests found
# -*- 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):
"""
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()
source = input_movement.getSourceAdministration() or \
root_simulation_movement.getSource()
destination = input_movement.getDestinationAdministration() or \
root_simulation_movement.getDestination()
kw.update({'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): def _getUpdatePropertyDict(self, input_movement):
return [context.getParentValue(),] root_simulation_movement = input_movement.getRootSimulationMovement()
source = input_movement.getSourceAdministration() or \
root_simulation_movement.getSource()
destination = input_movement.getDestinationAdministration() or \
root_simulation_movement.getDestination()
return {'portal_type': RuleMixin.movement_type,
'order':None, 'delivery':None,
'source':source, 'destination':destination})
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. # 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