Commit 25b1fe19 authored by Jérome Perrin's avatar Jérome Perrin

new Base_getCurrencyForSectionCategory script

This script is intended to replace Base_getCurrencyForSection and support
properly the case where there are more than one currency.
Start using it in accounting module view and grouping reference dialog.
parent bcf9a10b
......@@ -57,9 +57,12 @@ section_category = params.pop(\'section_category\', None)\n
section_category_strict = params.pop(\'section_category_strict\', None)\n
params[\'accounting_transaction.section_uid\'] = \'\'\n
if section_category:\n
params[\'accounting_transaction.section_uid\'] = context.Base_getSectionUidListForSectionCategory(\n
params[\'accounting_transaction.section_uid\'] = portal.Base_getSectionUidListForSectionCategory(\n
section_category, strict_membership=section_category_strict)\n
\n
currency = portal.Base_getCurrencyForSectionCategory(section_category, section_category_strict)\n
precision = portal.account_module.getQuantityPrecisionFromResource(currency)\n
portal.REQUEST.set(\'precision\', precision)\n
\n
# rewrite payment_mode_relative_url to uid\n
payment_mode_relative_url = params.pop(\'payment_mode_relative_url\', None)\n
if payment_mode_relative_url:\n
......
......@@ -76,10 +76,14 @@ for sort_column, sort_order in orig_sort_on:\n
elif sort_column == \'Movement_getMirrorSectionTitle\':\n
sort_on += [(\'stock.mirror_section_uid\', sort_order)]\n
\n
extra_query_keys = {}\n
section_category = portal.portal_preferences.getPreferredAccountingTransactionSectionCategory()\n
section_category_strict = portal.portal_preferences.getPreferredAccountingSectionCategoryStrict()\n
section_uid = portal.Base_getSectionUidListForSectionCategory(\n
portal.portal_preferences.getPreferredAccountingTransactionSectionCategory(),\n
strict_membership=portal.portal_preferences.getPreferredAccountingSectionCategoryStrict())\n
section_category, section_category_strict)\n
\n
currency = portal.Base_getCurrencyForSectionCategory(section_category, section_category_strict)\n
precision = portal.account_module.getQuantityPrecisionFromResource(currency)\n
request.set(\'precision\', precision)\n
\n
grouping = dialog_selection_params.get(\'grouping\', \'grouping\')\n
\n
......
......@@ -55,6 +55,9 @@
If the section is an organisation, returns this organisation\'s accounting\n
currency.\n
If the section is a category, find the most suitable currency.\n
\n
XXX consider using Base_getCurrencyForSectionCategory instead, because it supports\n
section_category_strict parameter and checks for duplicate currency used.\n
"""\n
\n
def getCurrencyForSection(section_url):\n
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </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 currency that is used for this section category.\n
Returns None if no currency defined or if mixed currency are used.\n
\'\'\'\n
\n
from Products.ERP5Type.Cache import CachingMethod\n
\n
def getCurrencyForSectionCategory(section_category, section_category_strict):\n
portal = context.getPortalObject()\n
currency_set = set()\n
for section_uid in portal.Base_getSectionUidListForSectionCategory(\n
section_category, section_category_strict):\n
if section_uid != -1:\n
section = portal.portal_catalog.getObject(section_uid)\n
currency = section.getPriceCurrency()\n
if currency:\n
currency_set.add(currency)\n
if len(currency_set) == 1:\n
return currency_set.pop()\n
\n
getCurrencyForSectionCategory = CachingMethod(\n
getCurrencyForSectionCategory,\n
id=script.getId(), cache_factory=\'erp5_content_long\')\n
\n
return getCurrencyForSectionCategory(section_category, section_category_strict)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>section_category, section_category_strict</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getCurrencyForSectionCategory</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
1564
\ No newline at end of file
1565
\ 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