Commit 3fd2df41 authored by Jérome Perrin's avatar Jérome Perrin

in currency conversions, give priority to currency exchange lines that have the shortest duration.

Simplifiy this script that was looking up predicates twice

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43545 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 42f753d1
...@@ -50,9 +50,7 @@ ...@@ -50,9 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>"""\n
"""\n
Search for all predicates that corresponds to this particular context\n Search for all predicates that corresponds to this particular context\n
and returns the base price of the resource\n and returns the base price of the resource\n
This script derives form getPriceCalculationOperandDict and is invoked by getPrice.\n This script derives form getPriceCalculationOperandDict and is invoked by getPrice.\n
...@@ -63,36 +61,37 @@ This script derives form getPriceCalculationOperandDict and is invoked by getPri ...@@ -63,36 +61,37 @@ This script derives form getPriceCalculationOperandDict and is invoked by getPri
\n \n
"""\n """\n
\n \n
def sort_by_date(a, b):\n def sort_key(exchange_line):\n
if a.getStartDateRangeMin() > b.getStartDateRangeMin() :\n if exchange_line.getPortalType() == \'Currency Exchange Cell\':\n
return -1\n exchange_line = exchange_line.getParentValue()\n
return 1\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 \n
#If getPrice is directly called on a resource, call directly\n # If getPrice is directly called on a resource, call directly\n
#Resource_getPriceCalculationOperandDict on the resource\n # Resource_getPriceCalculationOperandDict on the resource\n
if movement is None:\n if movement is None:\n
return context.Resource_getPriceCalculationOperandDict(**kw)\n return context.Resource_getPriceCalculationOperandDict(**kw)\n
else:\n else:\n
# sort_method can already exist in kw.\n
kw[\'sort_method\'] = sort_by_date\n
if validation_state is None:\n if validation_state is None:\n
validation_state=\'validated\'\n validation_state = \'validated\'\n
kw.setdefault(\'portal_type\', \'Currency Exchange Line\')\n kw.setdefault(\'portal_type\', \'Currency Exchange Line\')\n
predicate_list = context.portal_domains.searchPredicateList(\n predicate_list = context.portal_domains.searchPredicateList(\n
context=movement,\n context=movement,\n
validation_state=validation_state,\n validation_state=validation_state,\n
test=1,\n test=True,\n
**kw)\n **kw)\n
\n \n
predicate_list.sort(key=sort_key)\n
# For each predicate(i.e: Currency Exchange Line) found, get the exchange rate\n # For each predicate(i.e: Currency Exchange Line) found, get the exchange rate\n
# with the reference currency\n # with the reference currency\n
for predicate in predicate_list:\n for predicate in predicate_list:\n
operand_dict = predicate.Resource_getPriceCalculationOperandDict(movement=predicate, **kw)\n price = predicate.getPrice() or predicate.getBasePrice()\n
if operand_dict is not None and operand_dict.get(\'price\'):\n if price:\n
return operand_dict\n return dict(price=price)\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
......
943 950
\ 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