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

Guess the applicable currency and use this currency precision to round values

and set 'precision' on float fields.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12420 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 70c3e5ca
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""Returns the most suitable currency for a section.\n
\n
If the section is an organisation, returns this organisation\'s accounting\n
currency.\n
If the section is a category, if the category have a mapping organisation,\n
return this organisation\'s currency.\n
"""\n
\n
def getCurrencyForSection(section_url):\n
portal = context.getPortalObject()\n
section = portal.portal_categories.restrictedTraverse(section_url)\n
\n
if section.getPortalType() == \'Organisation\':\n
return section.getPriceCurrency()\n
\n
if section.getPortalType() == \'Category\':\n
member_list = section.getGroupRelatedValueList(portal_type=\'Organisation\')\n
if len(member_list) == 1:\n
return member_list[0].getPriceCurrency()\n
mapping = section.getMappingValue(portal_type=\'Organisation\')\n
if mapping is not None:\n
return mapping.getPriceCurrency()\n
\n
# nothing found ... returns the currency from preferences.\n
return portal.portal_preferences.getPreferredAccountingTransactionCurrency()\n
\n
from Products.ERP5Type.Cache import CachingMethod\n
getCurrencyForSection = CachingMethod(getCurrencyForSection,\n
id=script.getId())\n
return getCurrencyForSection(section_url)\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>section_url</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>section_url</string>
<string>getCurrencyForSection</string>
<string>Products.ERP5Type.Cache</string>
<string>CachingMethod</string>
<string>_getattr_</string>
<string>script</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getCurrencyForSection</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -80,11 +80,11 @@ caveats:\n
"""\n
\n
# do we have a cache already?\n
# XXX take selection into account ?\n
if not ignore_cache:\n
params_cache = context.REQUEST.other.get(\n
\'ERP5Accounting_getParams\', None)\n
if params_cache is not None:\n
# return a copy\n
return dict(params_cache)\n
\n
params = {}\n
......@@ -108,12 +108,19 @@ section_category = selection_params.get(\'section_category\',\n
preference.getPreferredAccountingTransactionSectionCategory())\n
if section_category:\n
params[\'section_category\'] = section_category\n
currency = context.Base_getCurrencyForSection(section_category)\n
# getQuantityPrecisionFromResource is defined on Base, but the portal is not \n
# an instance of Base, so we call it on account_module.\n
params[\'precision\'] = context.account_module\\\n
.getQuantityPrecisionFromResource(currency)\n
\n
\n
simulation_state = selection_params.get(\'simulation_state\',\n
preference.getPreferredAccountingTransactionSimulationStateList())\n
if simulation_state:\n
params[\'simulation_state\'] = simulation_state\n
\n
\n
if not ignore_cache:\n
context.REQUEST.other[\'ERP5Accounting_getParams\'] = params\n
return dict(params)\n
......@@ -174,6 +181,7 @@ return dict(params)\n
<string>_write_</string>
<string>at_date</string>
<string>section_category</string>
<string>currency</string>
<string>simulation_state</string>
</tuple>
</value>
......
......@@ -75,6 +75,10 @@ portal = context.getPortalObject()\n
params = portal.ERP5Accounting_getParams(selection)\n
N_ = lambda msg: Message(\'erp5_ui\', msg)\n
\n
if params.get(\'precision\', None) is not None:\n
# listbox editable float fields uses request/precision to format the value.\n
context.REQUEST.set(\'precision\', params[\'precision\'])\n
\n
if not from_date:\n
from_date = portal.portal_preferences\\\n
.getPreferredAccountingTransactionFromDate()\n
......
161
\ No newline at end of file
165
\ 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