Commit 7d222073 authored by Jérome Perrin's avatar Jérome Perrin

improve scripts to guess the best trade condition:

- applicable trade conditions are sorted to apply preferably trade conditions that define more properties
- categories are only taken into account if they are actually set on the trade condition

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25171 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d6da6454
...@@ -65,10 +65,12 @@ trade_condition_portal_type = \'Purchase Trade Condition\'\n ...@@ -65,10 +65,12 @@ trade_condition_portal_type = \'Purchase Trade Condition\'\n
trade_condition_list = order.getSpecialiseValueList(\n trade_condition_list = order.getSpecialiseValueList(\n
portal_type=trade_condition_portal_type)\n portal_type=trade_condition_portal_type)\n
\n \n
tested_base_category_list = [\n tested_base_category_list = [ ]\n
\'source_section\', \'destination_section\',\n for base_category in (\'destination_section\', \'destination\',\n
\'source\', \'destination\',\n \'source_section\', \'source\', ):\n
]\n if context.getProperty(base_category):\n
tested_base_category_list.append(base_category)\n
\n
count = len(tested_base_category_list)\n count = len(tested_base_category_list)\n
\n \n
# if no date is defined, use today\'s date to retrieve predicate that define start_date_range_min/max\n # if no date is defined, use today\'s date to retrieve predicate that define start_date_range_min/max\n
...@@ -77,27 +79,42 @@ if order.getStartDate() is None:\n ...@@ -77,27 +79,42 @@ if order.getStartDate() is None:\n
else:\n else:\n
predicate_context = order\n predicate_context = order\n
\n \n
def rank_method(trade_condition):\n
rank = 0\n
if trade_condition.getSourceSection():\n
rank += 10\n
if trade_condition.getSource():\n
rank += 10\n
if trade_condition.getDestinationSection():\n
rank += 1\n
if trade_condition.getDestination():\n
rank += 1\n
rank += len(trade_condition.getSpecialiseList())\n
return rank\n
\n
def sort_method(a, b):\n
return -cmp(rank_method(a), rank_method(b))\n
\n
while count > 0 and len(trade_condition_list) == 0:\n while count > 0 and len(trade_condition_list) == 0:\n
trade_condition_list = context.portal_domains.searchPredicateList(\n trade_condition_list = context.portal_domains.searchPredicateList(\n
predicate_context, portal_type=trade_condition_portal_type,\n predicate_context, portal_type=trade_condition_portal_type,\n
tested_base_category_list=tested_base_category_list[:count])\n tested_base_category_list=tested_base_category_list[:count],\n
sort_method=sort_method)\n
count -= 1\n count -= 1\n
\n \n
if len(trade_condition_list ) == 0 :\n if len(trade_condition_list ) == 0 :\n
redirect_url = \'%s/%s?%s\' % ( context.absolute_url(), form_id,\n message = Base_translateString(\'No trade condition.\')\n
\'portal_status_message=\' + Base_translateString(\'No trade condition.\'))\n
else :\n else :\n
# if more than one trade condition is found, simply apply the first one\n # if more than one trade condition is found, simply apply the first one\n
trade_condition=trade_condition_list[0].getObject()\n trade_condition=trade_condition_list[0].getObject()\n
\n \n
order.Order_applyTradeCondition(trade_condition, force=force)\n order.Order_applyTradeCondition(trade_condition, force=force)\n
\n \n
redirect_url = \'%s/%s?%s\' % (context.absolute_url(), form_id,\n message = Base_translateString(\'Order updated.\')\n
\'portal_status_message=\' + Base_translateString(\'Order updated.\'))\n
\n \n
if batch_mode:\n if not batch_mode:\n
return\n return context.Base_redirect(form_id,\n
context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n keep_items=dict(portal_status_message=message))\n
]]></string> </value> ]]></string> </value>
...@@ -110,7 +127,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n ...@@ -110,7 +127,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id, batch_mode=0, force=1</string> </value> <value> <string>form_id=\'view\', batch_mode=0, force=1</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -146,15 +163,20 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n ...@@ -146,15 +163,20 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n
<string>trade_condition_portal_type</string> <string>trade_condition_portal_type</string>
<string>trade_condition_list</string> <string>trade_condition_list</string>
<string>tested_base_category_list</string> <string>tested_base_category_list</string>
<string>_getiter_</string>
<string>base_category</string>
<string>len</string> <string>len</string>
<string>count</string> <string>count</string>
<string>None</string> <string>None</string>
<string>DateTime</string> <string>DateTime</string>
<string>predicate_context</string> <string>predicate_context</string>
<string>rank_method</string>
<string>sort_method</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>_inplacevar_</string> <string>_inplacevar_</string>
<string>redirect_url</string> <string>message</string>
<string>trade_condition</string> <string>trade_condition</string>
<string>dict</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -167,6 +189,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n ...@@ -167,6 +189,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple> <tuple>
<string>view</string>
<int>0</int> <int>0</int>
<int>1</int> <int>1</int>
</tuple> </tuple>
......
...@@ -65,10 +65,12 @@ trade_condition_portal_type = \'Sale Trade Condition\'\n ...@@ -65,10 +65,12 @@ trade_condition_portal_type = \'Sale Trade Condition\'\n
trade_condition_list = order.getSpecialiseValueList(\n trade_condition_list = order.getSpecialiseValueList(\n
portal_type=trade_condition_portal_type)\n portal_type=trade_condition_portal_type)\n
\n \n
tested_base_category_list = [\n tested_base_category_list = [ ]\n
\'destination_section\', \'source_section\',\n for base_category in (\'source_section\', \'source\',\n
\'destination\', \'source\',\n \'destination_section\', \'destination\', ):\n
]\n if context.getProperty(base_category):\n
tested_base_category_list.append(base_category)\n
\n
count = len(tested_base_category_list)\n count = len(tested_base_category_list)\n
\n \n
# if no date is defined, use today\'s date to retrieve predicate that define start_date_range_min/max\n # if no date is defined, use today\'s date to retrieve predicate that define start_date_range_min/max\n
...@@ -77,15 +79,31 @@ if order.getStartDate() is None:\n ...@@ -77,15 +79,31 @@ if order.getStartDate() is None:\n
else:\n else:\n
predicate_context = order\n predicate_context = order\n
\n \n
def rank_method(trade_condition):\n
rank = 0\n
if trade_condition.getDestinationSection():\n
rank += 10\n
if trade_condition.getDestination():\n
rank += 10\n
if trade_condition.getSourceSection():\n
rank += 1\n
if trade_condition.getSource():\n
rank += 1\n
rank += len(trade_condition.getSpecialiseList())\n
return rank\n
\n
def sort_method(a, b):\n
return -cmp(rank_method(a), rank_method(b))\n
\n
while count > 0 and len(trade_condition_list) == 0:\n while count > 0 and len(trade_condition_list) == 0:\n
trade_condition_list = context.portal_domains.searchPredicateList(\n trade_condition_list = context.portal_domains.searchPredicateList(\n
predicate_context, portal_type=trade_condition_portal_type,\n predicate_context, portal_type=trade_condition_portal_type,\n
tested_base_category_list=tested_base_category_list[:count])\n tested_base_category_list=tested_base_category_list[:count],\n
sort_method=sort_method)\n
count -= 1\n count -= 1\n
\n \n
if len(trade_condition_list ) == 0 :\n if len(trade_condition_list ) == 0:\n
redirect_url = \'%s/%s?%s\' % ( context.absolute_url(), form_id,\n message = Base_translateString(\'No trade condition.\')\n
\'portal_status_message=\' + Base_translateString(\'No trade condition.\'))\n
else :\n else :\n
# if more than one trade condition is found, simply apply the first one\n # if more than one trade condition is found, simply apply the first one\n
trade_condition=trade_condition_list[0].getObject()\n trade_condition=trade_condition_list[0].getObject()\n
...@@ -95,12 +113,11 @@ else :\n ...@@ -95,12 +113,11 @@ else :\n
if hasattr(order, \'getReceivedDate\') and order.getReceivedDate() is None:\n if hasattr(order, \'getReceivedDate\') and order.getReceivedDate() is None:\n
context.setReceivedDate(DateTime())\n context.setReceivedDate(DateTime())\n
\n \n
redirect_url = \'%s/%s?%s\' % (context.absolute_url(), form_id,\n message = Base_translateString(\'Order updated.\')\n
\'portal_status_message=\' + Base_translateString(\'Order updated.\'))\n
\n \n
if batch_mode:\n if not batch_mode:\n
return\n return context.Base_redirect(form_id,\n
context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n keep_items=dict(portal_status_message=message))\n
]]></string> </value> ]]></string> </value>
...@@ -113,7 +130,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n ...@@ -113,7 +130,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id, batch_mode=0, force=1</string> </value> <value> <string>form_id=\'view\', batch_mode=0, force=1</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -149,16 +166,21 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n ...@@ -149,16 +166,21 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n
<string>trade_condition_portal_type</string> <string>trade_condition_portal_type</string>
<string>trade_condition_list</string> <string>trade_condition_list</string>
<string>tested_base_category_list</string> <string>tested_base_category_list</string>
<string>_getiter_</string>
<string>base_category</string>
<string>len</string> <string>len</string>
<string>count</string> <string>count</string>
<string>None</string> <string>None</string>
<string>DateTime</string> <string>DateTime</string>
<string>predicate_context</string> <string>predicate_context</string>
<string>rank_method</string>
<string>sort_method</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>_inplacevar_</string> <string>_inplacevar_</string>
<string>redirect_url</string> <string>message</string>
<string>trade_condition</string> <string>trade_condition</string>
<string>hasattr</string> <string>hasattr</string>
<string>dict</string>
</tuple> </tuple>
</value> </value>
</item> </item>
...@@ -171,6 +193,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n ...@@ -171,6 +193,7 @@ context.REQUEST[ \'RESPONSE\' ].redirect( redirect_url.replace(\' \', \'+\') )\n
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple> <tuple>
<string>view</string>
<int>0</int> <int>0</int>
<int>1</int> <int>1</int>
</tuple> </tuple>
......
564 566
\ No newline at end of file \ No newline at end of file
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