Commit 00dee399 authored by Jérome Perrin's avatar Jérome Perrin

Optimisations on AccountingTransactionModule_getM9AccountingTransactionReport:

 * prefer calculating brain attributes than using TALES expression on editable fields
 * reuse accounting transactions module's selection SQL query as a subquery in getMovementHistoryList instead of getting all objects
 * use Object rather than asSource|DestinationBrain methods that will likely never exist



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11452 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7ba6cf98
...@@ -68,44 +68,65 @@ ...@@ -68,44 +68,65 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>line_list = []\n <value> <string>from Products.PythonScripts.standard import Object\n
line_list = []\n
cache_storage = context.REQUEST.other\n cache_storage = context.REQUEST.other\n
selection_name = \'accounting_selection\'\n selection_name = \'accounting_selection\'\n
accounting_movement_type_list = context.getPortalAccountingMovementTypeList()\n accounting_movement_type_list = context.getPortalAccountingMovementTypeList()\n
\n \n
stool = context.getPortalObject().portal_selections\n stool = context.getPortalObject().portal_selections\n
selection = stool.getSelectionFor(selection_name)\n
per_account_and_origin_cache = cache_storage.setdefault(\n per_account_and_origin_cache = cache_storage.setdefault(\n
\'m9_report_per_account_and_origin_summary\', {})\n \'m9_report_per_account_and_origin_summary\', {})\n
per_origin_and_sheet_cache = cache_storage.setdefault(\n per_origin_and_sheet_cache = cache_storage.setdefault(\n
\'m9_report_per_origin_and_sheet_summary\', {})\n \'m9_report_per_origin_and_sheet_summary\', {})\n
\n \n
for transaction in stool.callSelectionFor(selection_name):\n simtool = context.portal_simulation\n
transaction = transaction.getObject()\n # FIXME: how to pass pass parameter in the selection without\n
is_source = transaction.AccountingTransaction_isSourceView()\n # making them persistent ?\n
origin = transaction.getOriginId()\n context.REQUEST.other[\'src__\'] = 1\n
try:\n context.REQUEST.other[\'no_limit\'] = 1\n
sheet = transaction.getAggregateTitle(\n context.REQUEST.other[\'search_result_keys\'] = [\'catalog.uid\']\n
portal_type=\'Invoice Transmission Sheet\')\n
except AttributeError:\n
sheet = \'\'\n
for line in transaction.getMovementList(\n
portal_type=accounting_movement_type_list):\n
if is_source:\n
line = line.asSourceBrain()\n
else:\n
line = line.asDestinationBrain()\n
line_list.append(line)\n
\n \n
if line.node_relative_url:\n # call getMovementHistory by building a subquery with accounting module\n
# selection\'s query, using the src__=1 trick from above\n
for brain in simtool.getMovementHistoryList(\n
where_expression="catalog.parent_uid IN (%s)" %\n
stool.callSelectionFor(selection_name),\n
section_category=selection.getParams().get(\'section_category\')):\n
\n
movement = brain.getObject()\n
transaction = movement.getParentValue()\n
origin = transaction.getProperty(\'origin_id\')\n
sheet = transaction.getProperty(\'aggregate_title\')\n
obj = Object(\n
parent_portal_type=transaction.getTranslatedPortalType(),\n
parent_int_index="%05d" % transaction.getIntIndex(0),\n
parent_aggregate_title=sheet,\n
parent_origin_id=origin,\n
\n
mirror_section_uid=brain.mirror_section_uid,\n
section_uid=brain.section_uid,\n
node_relative_url=brain.node_relative_url,\n
getObject=brain.getObject,\n
asContext=movement.asContext,\n
# Movement_getExplanationUrl=movement.Movement_getExplanationUrl,\n
\n
date=brain.date,\n
debit=max(brain.total_price, 0),\n
credit=max(-brain.total_price, 0), )\n
line_list.append(obj)\n
\n
if brain.node_relative_url:\n
# per account and origin\n # per account and origin\n
account = per_account_and_origin_cache.setdefault(\n account = per_account_and_origin_cache.setdefault(\n
line.node_relative_url, {})\n brain.node_relative_url, {})\n
total = account.setdefault(origin, 0)\n total = account.setdefault(origin, 0)\n
account[origin] = total + (line.total_price or 0)\n account[origin] = total + (brain.total_price or 0)\n
# per origin and sheet \n # per origin and sheet\n
origin_cache = per_origin_and_sheet_cache.setdefault(origin, {})\n origin_cache = per_origin_and_sheet_cache.setdefault(origin, {})\n
total = origin_cache.setdefault((line.node_relative_url, sheet), 0)\n total = origin_cache.setdefault((brain.node_relative_url, sheet), 0)\n
origin_cache[(line.node_relative_url, sheet)] = total + (line.total_price or 0)\n origin_cache[(brain.node_relative_url, sheet)] = total + (brain.total_price or 0)\n
\n \n
return line_list\n return line_list\n
</string> </value> </string> </value>
...@@ -122,12 +143,6 @@ return line_list\n ...@@ -122,12 +143,6 @@ return line_list\n
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>**kw</string> </value>
...@@ -157,6 +172,8 @@ return line_list\n ...@@ -157,6 +172,8 @@ return line_list\n
<value> <value>
<tuple> <tuple>
<string>kw</string> <string>kw</string>
<string>Products.PythonScripts.standard</string>
<string>Object</string>
<string>line_list</string> <string>line_list</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
...@@ -164,18 +181,21 @@ return line_list\n ...@@ -164,18 +181,21 @@ return line_list\n
<string>selection_name</string> <string>selection_name</string>
<string>accounting_movement_type_list</string> <string>accounting_movement_type_list</string>
<string>stool</string> <string>stool</string>
<string>selection</string>
<string>per_account_and_origin_cache</string> <string>per_account_and_origin_cache</string>
<string>per_origin_and_sheet_cache</string> <string>per_origin_and_sheet_cache</string>
<string>simtool</string>
<string>_write_</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>brain</string>
<string>movement</string>
<string>transaction</string> <string>transaction</string>
<string>is_source</string>
<string>origin</string> <string>origin</string>
<string>sheet</string> <string>sheet</string>
<string>AttributeError</string> <string>max</string>
<string>line</string> <string>obj</string>
<string>account</string> <string>account</string>
<string>total</string> <string>total</string>
<string>_write_</string>
<string>origin_cache</string> <string>origin_cache</string>
</tuple> </tuple>
</value> </value>
......
...@@ -45,12 +45,6 @@ ...@@ -45,12 +45,6 @@
<tuple/> <tuple/>
</value> </value>
</item> </item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>action</string> </key> <key> <string>action</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -88,10 +82,6 @@ ...@@ -88,10 +82,6 @@
<key> <string>hidden</string> </key> <key> <string>hidden</string> </key>
<value> <value>
<list> <list>
<string>listbox_parent_int_index</string>
<string>listbox_parent_portal_type</string>
<string>listbox_parent_origin_id</string>
<string>listbox_parent_aggregate_title</string>
<string>listbox_credit</string> <string>listbox_credit</string>
<string>listbox_debit</string> <string>listbox_debit</string>
<string>listbox_date</string> <string>listbox_date</string>
......
...@@ -455,7 +455,7 @@ ...@@ -455,7 +455,7 @@
</item> </item>
<item> <item>
<key> <string>lines</string> </key> <key> <string>lines</string> </key>
<value> <int>20</int> </value> <value> <int>0</int> </value>
</item> </item>
<item> <item>
<key> <string>list_action</string> </key> <key> <string>list_action</string> </key>
......
...@@ -12,12 +12,6 @@ ...@@ -12,12 +12,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>listbox_credit</string> </value> <value> <string>listbox_credit</string> </value>
...@@ -126,9 +120,7 @@ ...@@ -126,9 +120,7 @@
</item> </item>
<item> <item>
<key> <string>default</string> </key> <key> <string>default</string> </key>
<value> <value> <string></string> </value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -259,23 +251,4 @@ ...@@ -259,23 +251,4 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>Products.Formulator.TALESField</string>
<string>TALESMethod</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: -min(cell.total_price, 0)</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData> </ZopeData>
...@@ -12,12 +12,6 @@ ...@@ -12,12 +12,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>listbox_date</string> </value> <value> <string>listbox_date</string> </value>
......
...@@ -12,12 +12,6 @@ ...@@ -12,12 +12,6 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>listbox_debit</string> </value> <value> <string>listbox_debit</string> </value>
...@@ -126,9 +120,7 @@ ...@@ -126,9 +120,7 @@
</item> </item>
<item> <item>
<key> <string>default</string> </key> <key> <string>default</string> </key>
<value> <value> <string></string> </value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item> </item>
<item> <item>
<key> <string>description</string> </key> <key> <string>description</string> </key>
...@@ -259,23 +251,4 @@ ...@@ -259,23 +251,4 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<tuple>
<string>Products.Formulator.TALESField</string>
<string>TALESMethod</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: max(cell.total_price, 0)</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData> </ZopeData>
43 44
\ 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