Commit ff65fe8d authored by Jérome Perrin's avatar Jérome Perrin

make it possible to use another conversion rate that the one proposed by...

make it possible to use another conversion rate that the one proposed by system. This also make possible to use this action when no conversion has been found.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39046 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 91278f18
...@@ -50,21 +50,18 @@ ...@@ -50,21 +50,18 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from Products.ERP5.Document.Document import ConversionError\n <value> <string>"""\n
\n
"""\n
Script to convert the prices used in the transaction to the \n Script to convert the prices used in the transaction to the \n
currency of the destination section\n currency of the destination section\n
form_id : Page that action is called from\n form_id : Page that action is called from\n
\n \n
\n \n
"""\n """\n
\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
#get the precision of the destination\n #get the precision of the destination\n
precision =context.getDestinationSectionValue().getPriceCurrencyValue().getQuantityPrecision()\n precision = context.getDestinationSectionValue().getPriceCurrencyValue().getQuantityPrecision()\n
#Get all transaction lines of the transaction \n #Get all transaction lines of the transaction \n
line_list= context.contentValues(\n line_list = context.contentValues(\n
portal_type=portal.getPortalAccountingMovementTypeList())\n portal_type=portal.getPortalAccountingMovementTypeList())\n
"""\n """\n
For each transaction line, calculate the price of the resource\n For each transaction line, calculate the price of the resource\n
...@@ -74,26 +71,24 @@ and start_date categories \n ...@@ -74,26 +71,24 @@ and start_date categories \n
"""\n """\n
\n \n
for line in line_list:\n for line in line_list:\n
if line.getDestinationSectionValue() is None:\n section = line.getDestinationSectionValue()\n
raise AssertionError\n
else:\n
currency = line.getResourceValue()\n currency = line.getResourceValue()\n
exchange_ratio = currency.getPrice(context=line.asContext(\n if not exchange_rate:\n
categories=[\'resource/%s\' % line.getResource(), \n exchange_rate = currency.getPrice(context=line.asContext(\n
\'price_currency/currency_module/%s\' %\n categories=[line.getResource(base=True),\n
line.getDestinationSectionValue().getPriceCurrencyId()],\n section.getPriceCurrency(base=True)],\n
start_date=line.getStopDate()))\n start_date=line.getStopDate()))\n
\n \n
#redirect to previous page without doing the conversion\n # redirect to previous page without doing the conversion\n
if exchange_ratio is None:\n if exchange_rate is None:\n
return context.Base_redirect(form_id,\n return context.Base_redirect(form_id,\n
keep_items=dict(\n keep_items=dict(\n
portal_status_message=context.Base_translateString(\'No exchange ratio found.\'))) \n portal_status_message=context.Base_translateString(\'No exchange ratio found.\')))\n
#update the corresponding price and round it according to the precision of\n
#the converted currency\n
line.setDestinationTotalAssetPrice(\n
round(exchange_ratio*(line.getQuantity()), precision))\n
\n \n
# update the corresponding price and round it according to the precision of\n
# the converted currency\n
line.setDestinationTotalAssetPrice(\n
round(exchange_rate * (line.getQuantity()), precision))\n
\n \n
msg = context.Base_translateString(\'Price converted.\')\n msg = context.Base_translateString(\'Price converted.\')\n
\n \n
...@@ -109,7 +104,7 @@ return context.Base_redirect(form_id,\n ...@@ -109,7 +104,7 @@ return context.Base_redirect(form_id,\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id=\'view\'</string> </value> <value> <string>exchange_rate=None, form_id=\'view\'</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -129,15 +124,14 @@ return context.Base_redirect(form_id,\n ...@@ -129,15 +124,14 @@ return context.Base_redirect(form_id,\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>1</int> </value> <value> <int>2</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>exchange_rate</string>
<string>form_id</string> <string>form_id</string>
<string>Products.ERP5.Document.Document</string>
<string>ConversionError</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>portal</string> <string>portal</string>
...@@ -145,10 +139,10 @@ return context.Base_redirect(form_id,\n ...@@ -145,10 +139,10 @@ return context.Base_redirect(form_id,\n
<string>line_list</string> <string>line_list</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>line</string> <string>line</string>
<string>None</string> <string>section</string>
<string>AssertionError</string>
<string>currency</string> <string>currency</string>
<string>exchange_ratio</string> <string>True</string>
<string>None</string>
<string>dict</string> <string>dict</string>
<string>round</string> <string>round</string>
<string>msg</string> <string>msg</string>
...@@ -164,6 +158,7 @@ return context.Base_redirect(form_id,\n ...@@ -164,6 +158,7 @@ return context.Base_redirect(form_id,\n
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple> <tuple>
<none/>
<string>view</string> <string>view</string>
</tuple> </tuple>
</value> </value>
......
...@@ -50,16 +50,15 @@ ...@@ -50,16 +50,15 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>from Products.ERP5.Document.Document import ConversionError\n <value> <string>"""\n
"""\n
Script to convert the prices used in the transaction to the \n Script to convert the prices used in the transaction to the \n
currency of the destination section\n currency of the destination section\n
"""\n """\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
#get the precision of the destination\n #get the precision of the destination\n
precision =context.getSourceSectionValue().getPriceCurrencyValue().getQuantityPrecision()\n precision = context.getSourceSectionValue().getPriceCurrencyValue().getQuantityPrecision()\n
#Get all transaction lines of the transaction \n #Get all transaction lines of the transaction \n
line_list= context.contentValues(\n line_list = context.contentValues(\n
portal_type=portal.getPortalAccountingMovementTypeList())\n portal_type=portal.getPortalAccountingMovementTypeList())\n
"""\n """\n
For each transaction line, calculate the price of the resource\n For each transaction line, calculate the price of the resource\n
...@@ -69,27 +68,24 @@ and start_date categories \n ...@@ -69,27 +68,24 @@ and start_date categories \n
"""\n """\n
\n \n
for line in line_list:\n for line in line_list:\n
if line.getSourceSectionValue() is None:\n section = line.getSourceSectionValue()\n
raise AssertionError\n
else:\n
currency = line.getResourceValue()\n currency = line.getResourceValue()\n
exchange_ratio = currency.getPrice(context=line.asContext(\n if not exchange_rate:\n
categories=[\'resource/%s\' % line.getResource(), \n exchange_rate = currency.getPrice(context=line.asContext(\n
\'price_currency/currency_module/%s\' %\n categories=[line.getResource(base=True),\n
line.getSourceSectionValue().getPriceCurrencyId()],\n section.getPriceCurrency(base=True)],\n
start_date=line.getStartDate()))\n start_date=line.getStartDate()))\n
#redirect to previous page without doing the conversion\n # redirect to previous page without doing the conversion\n
if exchange_ratio is None:\n if exchange_rate is None:\n
return context.Base_redirect(form_id,\n return context.Base_redirect(form_id,\n
keep_items=dict(\n keep_items=dict(\n
portal_status_message=context.Base_translateString(\'No exchange ratio found.\'))) \n portal_status_message=context.Base_translateString(\'No exchange ratio found.\')))\n
\n \n
\n \n
#update the corresponding price and round it according to the precision of\n # update the corresponding price and round it according to the precision of\n
#the converted currency\n # the converted currency\n
line.setSourceTotalAssetPrice(\n line.setSourceTotalAssetPrice(\n
round(exchange_ratio * (-line.getQuantity()), precision))\n round(exchange_rate * (-line.getQuantity()), precision))\n
\n
\n \n
msg = context.Base_translateString(\'Price converted.\')\n msg = context.Base_translateString(\'Price converted.\')\n
\n \n
...@@ -105,7 +101,7 @@ return context.Base_redirect(form_id,\n ...@@ -105,7 +101,7 @@ return context.Base_redirect(form_id,\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>form_id=\'view\'</string> </value> <value> <string>exchange_rate=None, form_id=\'view\'</string> </value>
</item> </item>
<item> <item>
<key> <string>errors</string> </key> <key> <string>errors</string> </key>
...@@ -125,15 +121,14 @@ return context.Base_redirect(form_id,\n ...@@ -125,15 +121,14 @@ return context.Base_redirect(form_id,\n
<dictionary> <dictionary>
<item> <item>
<key> <string>co_argcount</string> </key> <key> <string>co_argcount</string> </key>
<value> <int>1</int> </value> <value> <int>2</int> </value>
</item> </item>
<item> <item>
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>exchange_rate</string>
<string>form_id</string> <string>form_id</string>
<string>Products.ERP5.Document.Document</string>
<string>ConversionError</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>portal</string> <string>portal</string>
...@@ -141,10 +136,10 @@ return context.Base_redirect(form_id,\n ...@@ -141,10 +136,10 @@ return context.Base_redirect(form_id,\n
<string>line_list</string> <string>line_list</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>line</string> <string>line</string>
<string>None</string> <string>section</string>
<string>AssertionError</string>
<string>currency</string> <string>currency</string>
<string>exchange_ratio</string> <string>True</string>
<string>None</string>
<string>dict</string> <string>dict</string>
<string>round</string> <string>round</string>
<string>msg</string> <string>msg</string>
...@@ -160,6 +155,7 @@ return context.Base_redirect(form_id,\n ...@@ -160,6 +155,7 @@ return context.Base_redirect(form_id,\n
<key> <string>func_defaults</string> </key> <key> <string>func_defaults</string> </key>
<value> <value>
<tuple> <tuple>
<none/>
<string>view</string> <string>view</string>
</tuple> </tuple>
</value> </value>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
</item> </item>
<item> <item>
<key> <string>enctype</string> </key> <key> <string>enctype</string> </key>
<value> <string>application/x-www-form-urlencoded</string> </value> <value> <string>multipart/form-data</string> </value>
</item> </item>
<item> <item>
<key> <string>group_list</string> </key> <key> <string>group_list</string> </key>
...@@ -143,6 +143,10 @@ ...@@ -143,6 +143,10 @@
<key> <string>update_action</string> </key> <key> <string>update_action</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
......
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
<key> <string>delegated_list</string> </key> <key> <string>delegated_list</string> </key>
<value> <value>
<list> <list>
<string>title</string>
<string>default</string> <string>default</string>
<string>precision</string> <string>precision</string>
<string>editable</string> <string>title</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -84,10 +83,6 @@ ...@@ -84,10 +83,6 @@
<key> <string>default</string> </key> <key> <string>default</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string>my_money_quantity</string> </value> <value> <string>my_money_quantity</string> </value>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
</item> </item>
<item> <item>
<key> <string>enctype</string> </key> <key> <string>enctype</string> </key>
<value> <string>application/x-www-form-urlencoded</string> </value> <value> <string>multipart/form-data</string> </value>
</item> </item>
<item> <item>
<key> <string>group_list</string> </key> <key> <string>group_list</string> </key>
...@@ -143,6 +143,10 @@ ...@@ -143,6 +143,10 @@
<key> <string>update_action</string> </key> <key> <string>update_action</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
......
...@@ -10,10 +10,9 @@ ...@@ -10,10 +10,9 @@
<key> <string>delegated_list</string> </key> <key> <string>delegated_list</string> </key>
<value> <value>
<list> <list>
<string>title</string>
<string>default</string> <string>default</string>
<string>precision</string> <string>precision</string>
<string>editable</string> <string>title</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -84,10 +83,6 @@ ...@@ -84,10 +83,6 @@
<key> <string>default</string> </key> <key> <string>default</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string>my_money_quantity</string> </value> <value> <string>my_money_quantity</string> </value>
......
1367 1368
\ 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