From b40688b7b87353b0dd2fe27935e03fd87c3e01e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Fri, 10 Dec 2010 14:52:43 +0000
Subject: [PATCH] give priority to trade conditions where both source and
 destintion section are from the same group

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41336 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_trade/InternalOrder_applyTradeCondition.xml     | 9 +++++++++
 bt5/erp5_trade/bt/revision                               | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/InternalOrder_applyTradeCondition.xml b/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/InternalOrder_applyTradeCondition.xml
index 283ae79470..beb666c930 100644
--- a/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/InternalOrder_applyTradeCondition.xml
+++ b/bt5/erp5_trade/SkinTemplateItem/portal_skins/erp5_trade/InternalOrder_applyTradeCondition.xml
@@ -78,8 +78,10 @@ else:\n
 \n
 def rank_method(trade_condition):\n
   rank = 0\n
+  destination_section_group = None\n
   destination_section = trade_condition.getDestinationSection()\n
   if destination_section:\n
+    destination_section_group = trade_condition.getDestinationSectionValue().getGroup()\n
     if destination_section == context.getDestinationSection():\n
       rank += 10\n
     else:\n
@@ -92,6 +94,13 @@ def rank_method(trade_condition):\n
       rank -= 2\n
   if trade_condition.getSourceSection():\n
     rank += 1\n
+    if destination_section_group:\n
+      source_section_group = trade_condition.getSourceSectionValue().getGroup()\n
+      if source_section_group:\n
+        if source_section_group.startswith(destination_section_group) \\\n
+             or destination_section_group.startswith(source_section_group):\n
+          # trade conditions where both sections are in the same group must have high priority\n
+          rank += 20\n
   if trade_condition.getSource():\n
     rank += 1\n
   rank += len(trade_condition.getSpecialiseList())\n
diff --git a/bt5/erp5_trade/bt/revision b/bt5/erp5_trade/bt/revision
index 1143d3eeb2..0a678c620d 100644
--- a/bt5/erp5_trade/bt/revision
+++ b/bt5/erp5_trade/bt/revision
@@ -1 +1 @@
-1080
\ No newline at end of file
+1081
\ No newline at end of file
-- 
2.30.9