[Erp5-report] r43545 jerome - in /erp5/trunk/bt5/erp5_base: SkinTemplateItem/portal_skins/e...

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Feb 22 10:58:32 CET 2011


Author: jerome
Date: Tue Feb 22 10:58:32 2011
New Revision: 43545

URL: http://svn.erp5.org?rev=43545&view=rev
Log:
in currency conversions, give priority to currency exchange lines that have the shortest duration.
Simplifiy this script that was looking up predicates twice

Modified:
    erp5/trunk/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Currency_getPriceCalculationOperandDict.xml
    erp5/trunk/bt5/erp5_base/bt/revision

Modified: erp5/trunk/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Currency_getPriceCalculationOperandDict.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Currency_getPriceCalculationOperandDict.xml?rev=43545&r1=43544&r2=43545&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Currency_getPriceCalculationOperandDict.xml [utf8] (original)
+++ erp5/trunk/bt5/erp5_base/SkinTemplateItem/portal_skins/erp5_base/Currency_getPriceCalculationOperandDict.xml [utf8] Tue Feb 22 10:58:32 2011
@@ -50,9 +50,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string encoding="cdata"><![CDATA[
-
-"""\n
+            <value> <string>"""\n
 Search for all predicates that corresponds to this particular context\n
 and returns the base price of the resource\n
 This script derives form getPriceCalculationOperandDict and is invoked by getPrice.\n
@@ -63,36 +61,37 @@ This script derives form getPriceCalcula
 \n
 """\n
 \n
-def sort_by_date(a, b):\n
-  if a.getStartDateRangeMin() > b.getStartDateRangeMin() :\n
-    return -1\n
-  return 1\n
+def sort_key(exchange_line):\n
+  if exchange_line.getPortalType() == \'Currency Exchange Cell\':\n
+    exchange_line = exchange_line.getParentValue()\n
+  start_date_range_min = exchange_line.getStartDate()\n
+  start_date_range_max = exchange_line.getStopDate()\n
+  if start_date_range_min and start_date_range_max:\n
+    return start_date_range_max - start_date_range_min\n
+  return 2**16\n
 \n
-#If getPrice is directly called on a resource, call directly\n
-#Resource_getPriceCalculationOperandDict on the resource\n
+# If getPrice is directly called on a resource, call directly\n
+# Resource_getPriceCalculationOperandDict on the resource\n
 if movement is None:\n
   return context.Resource_getPriceCalculationOperandDict(**kw)\n
 else:\n
-  # sort_method can already exist in kw.\n
-  kw[\'sort_method\'] = sort_by_date\n
   if validation_state is None:\n
-    validation_state=\'validated\'\n
+    validation_state = \'validated\'\n
   kw.setdefault(\'portal_type\', \'Currency Exchange Line\')\n
   predicate_list = context.portal_domains.searchPredicateList(\n
       context=movement,\n
       validation_state=validation_state,\n
-      test=1,\n
+      test=True,\n
       **kw)\n
 \n
+  predicate_list.sort(key=sort_key)\n
   # For each predicate(i.e: Currency Exchange Line) found, get the exchange rate\n
   # with the reference currency\n
   for predicate in predicate_list:\n
-    operand_dict = predicate.Resource_getPriceCalculationOperandDict(movement=predicate, **kw)\n
-    if operand_dict is not None and operand_dict.get(\'price\'):\n
-      return operand_dict\n
-
-
-]]></string> </value>
+    price = predicate.getPrice() or predicate.getBasePrice()\n
+    if price:\n
+      return dict(price=price)\n
+</string> </value>
         </item>
         <item>
             <key> <string>_params</string> </key>

Modified: erp5/trunk/bt5/erp5_base/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_base/bt/revision?rev=43545&r1=43544&r2=43545&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_base/bt/revision [utf8] (original)
+++ erp5/trunk/bt5/erp5_base/bt/revision [utf8] Tue Feb 22 10:58:32 2011
@@ -1 +1 @@
-943
\ No newline at end of file
+950
\ No newline at end of file



More information about the Erp5-report mailing list