From 7fdf58d31a516b2edf1b07bb9d67598ed3e74418 Mon Sep 17 00:00:00 2001 From: Alexandre Boeglin <alex@nexedi.com> Date: Tue, 12 Feb 2008 16:15:40 +0000 Subject: [PATCH] * using a "hard" filter on portal_type was not a good solution, use a better sort method instead. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19280 20353a03-c40f-0410-a6d1-a30d3c3de9de --- ...ovement_getPriceCalculationOperandDict.xml | 65 +++++++++++++++---- product/ERP5/bootstrap/erp5_core/bt/revision | 2 +- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Movement_getPriceCalculationOperandDict.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Movement_getPriceCalculationOperandDict.xml index dc1d0f438a..e7f9740089 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Movement_getPriceCalculationOperandDict.xml +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Movement_getPriceCalculationOperandDict.xml @@ -65,21 +65,56 @@ </item> <item> <key> <string>_body</string> </key> - <value> <string>portal_type_list = None\n + <value> <string>def sourceSortMethod(a, b):\n + if a.getSource():\n + return -1 # a defines a source and wins\n + return 1 # a defines no source ans loses\n \n -explanation = context.getExplanationValue()\n -if explanation is not None:\n - explanation_type = explanation.getPortalType()\n -# XXX FIXME: Hardcoded values\n - if "Purchase" in explanation_type:\n - portal_type_list = ("Purchase Supply Line", "Purchase Supply Cell", "Supply Line", "Supply Cell")\n - elif "Sale" in explanation_type:\n - portal_type_list = ("Sale Supply Line", "Sale Supply Cell", "Supply Line", "Supply Cell")\n +def destinationSortMethod(a, b):\n + if a.getDestination():\n + return -1 # a defines a destination and wins\n + return 1 # a defines no destination ans loses\n +\n +def resourcePurchasePriceSortMethod(a, b):\n + if "Purchase" in a.getPortalType():\n + if "Purchase" in b.getPortalType():\n + return sourceSortMethod(a, b)\n + else:\n + return -1\n + else:\n + if "Purchase" in b.getPortalType():\n + return 1\n + else:\n + return destinationSortMethod(a, b)\n +\n +def resourceSalePriceSortMethod(a, b):\n + if "Sale" in a.getPortalType():\n + if "Sale" in b.getPortalType():\n + return destinationSortMethod(a, b)\n + else:\n + return -1\n + else:\n + if "Sale" in b.getPortalType():\n + return 1\n + else:\n + return sourceSortMethod(a, b)\n +\n +try:\n + explanation = context.getExplanationValue()\n +except:\n + pass\n +else:\n + if explanation is not None:\n + explanation_type = explanation.getPortalType()\n + # XXX FIXME: Hardcoded values\n + if "Purchase" in explanation_type:\n + kw[\'sort_method\'] = resourcePurchasePriceSortMethod\n + elif "Sale" in explanation_type:\n + kw[\'sort_method\'] = resourceSalePriceSortMethod\n \n resource = context.getResourceValue()\n if resource is not None:\n - return resource.getPriceCalculationOperandDict(default=default, context=context,\n - portal_type_list=portal_type_list, **kw)\n + return resource.getPriceCalculationOperandDict(default=default, context=context, **kw)\n else:\n return default\n </string> </value> @@ -132,12 +167,16 @@ else:\n <tuple> <string>default</string> <string>kw</string> - <string>None</string> - <string>portal_type_list</string> + <string>sourceSortMethod</string> + <string>destinationSortMethod</string> + <string>resourcePurchasePriceSortMethod</string> + <string>resourceSalePriceSortMethod</string> <string>_getattr_</string> <string>context</string> <string>explanation</string> + <string>None</string> <string>explanation_type</string> + <string>_write_</string> <string>resource</string> <string>_apply_</string> </tuple> diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision index b775c5e152..5b3e043c52 100644 --- a/product/ERP5/bootstrap/erp5_core/bt/revision +++ b/product/ERP5/bootstrap/erp5_core/bt/revision @@ -1 +1 @@ -699 \ No newline at end of file +703 \ No newline at end of file -- 2.30.9