Commit c3fb98cd authored by Yusei Tahara's avatar Yusei Tahara

Optimize query for calculation of debit and credit.

Fix sorting bug of operation accounting date column.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19107 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f42303a3
...@@ -71,8 +71,18 @@ ...@@ -71,8 +71,18 @@
kw[\'omit_input\'] = 0\n kw[\'omit_input\'] = 0\n
kw[\'omit_output\'] = 0\n kw[\'omit_output\'] = 0\n
\n \n
if kw.get(\'delivery_start_date\'):\n from Products.ZSQLCatalog.SQLCatalog import Query\n
kw[\'delivery.start_date\'] = kw[\'delivery_start_date\']\n if kw.get(\'operation_date\', {}).get(\'query\'):\n
operation_date_dict = kw[\'operation_date\']\n
ss_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.start_date\':operation_date_dict[\'query\']})\n
kw[\'source_section_where_expression\'] = ss_q()[\'where_expression\']\n
ds_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.stop_date\':operation_date_dict[\'query\']})\n
kw[\'destination_section_where_expression\'] = ds_q()[\'where_expression\']\n
del kw[\'operation_date\']\n
\n \n
return context.AccountingTransactionModule_zGetAccountingTransactionList( selection=None,\n return context.AccountingTransactionModule_zGetAccountingTransactionList( selection=None,\n
selection_params=kw,\n selection_params=kw,\n
...@@ -126,8 +136,13 @@ return context.AccountingTransactionModule_zGetAccountingTransactionList( select ...@@ -126,8 +136,13 @@ return context.AccountingTransactionModule_zGetAccountingTransactionList( select
<string>kw</string> <string>kw</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>_write_</string> <string>_write_</string>
<string>Products.ZSQLCatalog.SQLCatalog</string>
<string>Query</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>operation_date_dict</string>
<string>_apply_</string> <string>_apply_</string>
<string>ss_q</string>
<string>ds_q</string>
<string>context</string> <string>context</string>
<string>None</string> <string>None</string>
</tuple> </tuple>
......
...@@ -70,6 +70,9 @@ ...@@ -70,6 +70,9 @@
# XXX workarounds for DTML limitation\n # XXX workarounds for DTML limitation\n
# Because DTML cannot do <dtml-if node or resource or...>\n # Because DTML cannot do <dtml-if node or resource or...>\n
# If Python is used, it does not check the existence of a variable automatically\n # If Python is used, it does not check the existence of a variable automatically\n
\n
from Products.ZSQLCatalog.SQLCatalog import Query\n
\n
if \'node\' not in params:\n if \'node\' not in params:\n
params[\'node\'] = []\n params[\'node\'] = []\n
if \'resource\' not in params:\n if \'resource\' not in params:\n
...@@ -88,9 +91,17 @@ if params.get(\'count\', 0):\n ...@@ -88,9 +91,17 @@ if params.get(\'count\', 0):\n
params[\'omit_input\'] = 0\n params[\'omit_input\'] = 0\n
params[\'omit_output\'] = 0\n params[\'omit_output\'] = 0\n
\n \n
# XXX this workaround is probably no longer needed\n if params.get(\'operation_date\', {}).get(\'query\'):\n
if params.get(\'delivery_start_date\'):\n operation_date_dict = params[\'operation_date\']\n
params[\'delivery.start_date\'] = params[\'delivery_start_date\']\n ss_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.start_date\':operation_date_dict[\'query\']})\n
params[\'source_section_where_expression\'] = ss_q()[\'where_expression\']\n
ds_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.stop_date\':operation_date_dict[\'query\']})\n
params[\'destination_section_where_expression\'] = ds_q()[\'where_expression\']\n
del params[\'operation_date\']\n
\n \n
# this method can be used to build another complex query, for example\n # this method can be used to build another complex query, for example\n
# as a catalog.parent_uid filter with SimulationTool.getMovementList.\n # as a catalog.parent_uid filter with SimulationTool.getMovementList.\n
...@@ -150,15 +161,20 @@ return context.AccountingTransactionModule_zGetAccountingTransactionList( \n ...@@ -150,15 +161,20 @@ return context.AccountingTransactionModule_zGetAccountingTransactionList( \n
<value> <value>
<tuple> <tuple>
<string>params</string> <string>params</string>
<string>Products.ZSQLCatalog.SQLCatalog</string>
<string>Query</string>
<string>_write_</string> <string>_write_</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>operation_date_dict</string>
<string>_apply_</string>
<string>ss_q</string>
<string>ds_q</string>
<string>context</string> <string>context</string>
<string>src__</string> <string>src__</string>
<string>no_limit</string> <string>no_limit</string>
<string>None</string> <string>None</string>
<string>search_result_keys</string> <string>search_result_keys</string>
<string>_apply_</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -70,8 +70,20 @@ ...@@ -70,8 +70,20 @@
params[\'stat\'] = 1\n params[\'stat\'] = 1\n
params[\'omit_input\'] = 1\n params[\'omit_input\'] = 1\n
params[\'omit_output\'] = 0\n params[\'omit_output\'] = 0\n
if params.get(\'delivery_start_date\'):\n \n
params[\'delivery.start_date\'] = params[\'delivery_start_date\']\n from Products.ZSQLCatalog.SQLCatalog import Query\n
\n
if params.get(\'operation_date\', {}).get(\'query\'):\n
operation_date_dict = params[\'operation_date\']\n
ss_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.start_date\':operation_date_dict[\'query\']})\n
params[\'source_section_where_expression\'] = ss_q()[\'where_expression\']\n
ds_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.stop_date\':operation_date_dict[\'query\']})\n
params[\'destination_section_where_expression\'] = ds_q()[\'where_expression\']\n
del params[\'operation_date\']\n
\n \n
result = context.AccountingTransactionModule_zGetAccountingTransactionList(\n result = context.AccountingTransactionModule_zGetAccountingTransactionList(\n
selection=selection,\n selection=selection,\n
...@@ -128,8 +140,13 @@ return float(\'%.02f\' % (row.total_price and - row.total_price or 0.0))\n ...@@ -128,8 +140,13 @@ return float(\'%.02f\' % (row.total_price and - row.total_price or 0.0))\n
<string>context</string> <string>context</string>
<string>params</string> <string>params</string>
<string>_write_</string> <string>_write_</string>
<string>Products.ZSQLCatalog.SQLCatalog</string>
<string>Query</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>operation_date_dict</string>
<string>_apply_</string> <string>_apply_</string>
<string>ss_q</string>
<string>ds_q</string>
<string>result</string> <string>result</string>
<string>row</string> <string>row</string>
<string>float</string> <string>float</string>
......
...@@ -70,8 +70,20 @@ ...@@ -70,8 +70,20 @@
params[\'stat\'] = 1\n params[\'stat\'] = 1\n
params[\'omit_output\'] = 1\n params[\'omit_output\'] = 1\n
params[\'omit_input\'] = 0\n params[\'omit_input\'] = 0\n
if params.get(\'delivery_start_date\'):\n \n
params[\'delivery.start_date\'] = params[\'delivery_start_date\']\n from Products.ZSQLCatalog.SQLCatalog import Query\n
\n
if params.get(\'operation_date\', {}).get(\'query\'):\n
operation_date_dict = params[\'operation_date\']\n
ss_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.start_date\':operation_date_dict[\'query\']})\n
params[\'source_section_where_expression\'] = ss_q()[\'where_expression\']\n
ds_q = Query(format=operation_date_dict[\'format\'],\n
type=operation_date_dict[\'type\'],\n
**{\'delivery.stop_date\':operation_date_dict[\'query\']})\n
params[\'destination_section_where_expression\'] = ds_q()[\'where_expression\']\n
del params[\'operation_date\']\n
\n \n
result = context.AccountingTransactionModule_zGetAccountingTransactionList(\n result = context.AccountingTransactionModule_zGetAccountingTransactionList(\n
selection=selection, selection_params = params, **params)\n selection=selection, selection_params = params, **params)\n
...@@ -127,8 +139,13 @@ return float(\'%.02f\' % (row.total_price or 0.0))\n ...@@ -127,8 +139,13 @@ return float(\'%.02f\' % (row.total_price or 0.0))\n
<string>context</string> <string>context</string>
<string>params</string> <string>params</string>
<string>_write_</string> <string>_write_</string>
<string>Products.ZSQLCatalog.SQLCatalog</string>
<string>Query</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>operation_date_dict</string>
<string>_apply_</string> <string>_apply_</string>
<string>ss_q</string>
<string>ds_q</string>
<string>result</string> <string>result</string>
<string>row</string> <string>row</string>
<string>float</string> <string>float</string>
......
...@@ -9,12 +9,6 @@ ...@@ -9,12 +9,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>
...@@ -261,18 +255,15 @@ ...@@ -261,18 +255,15 @@
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle> <pickle>
<tuple> <tuple>
<tuple> <global name="TALESMethod" module="Products.Formulator.TALESField"/>
<string>Products.Formulator.TALESField</string> <tuple/>
<string>TALESMethod</string>
</tuple>
<none/>
</tuple> </tuple>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>cell/AccountingTransactionModule_getSourceCredit</string> </value> <value> <string>cell/credit|cell/AccountingTransactionModule_getSourceCredit</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
...@@ -280,11 +271,8 @@ ...@@ -280,11 +271,8 @@
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<tuple> <tuple>
<tuple> <global name="TALESMethod" module="Products.Formulator.TALESField"/>
<string>Products.Formulator.TALESField</string> <tuple/>
<string>TALESMethod</string>
</tuple>
<none/>
</tuple> </tuple>
</pickle> </pickle>
<pickle> <pickle>
......
...@@ -9,12 +9,6 @@ ...@@ -9,12 +9,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>
...@@ -261,18 +255,15 @@ ...@@ -261,18 +255,15 @@
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle> <pickle>
<tuple> <tuple>
<tuple> <global name="TALESMethod" module="Products.Formulator.TALESField"/>
<string>Products.Formulator.TALESField</string> <tuple/>
<string>TALESMethod</string>
</tuple>
<none/>
</tuple> </tuple>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>cell/AccountingTransactionModule_getSourceDebit</string> </value> <value> <string>cell/debit|cell/AccountingTransactionModule_getSourceDebit</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
...@@ -280,11 +271,8 @@ ...@@ -280,11 +271,8 @@
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<tuple> <tuple>
<tuple> <global name="TALESMethod" module="Products.Formulator.TALESField"/>
<string>Products.Formulator.TALESField</string> <tuple/>
<string>TALESMethod</string>
</tuple>
<none/>
</tuple> </tuple>
</pickle> </pickle>
<pickle> <pickle>
......
...@@ -9,12 +9,6 @@ ...@@ -9,12 +9,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_operation_date</string> </value> <value> <string>listbox_operation_date</string> </value>
......
...@@ -125,6 +125,12 @@ ...@@ -125,6 +125,12 @@
</dictionary> </dictionary>
</value> </value>
</item> </item>
<item>
<key> <string>destination_section_where_expression</string> </key>
<value>
<dictionary/>
</value>
</item>
<item> <item>
<key> <string>entity</string> </key> <key> <string>entity</string> </key>
<value> <value>
...@@ -265,6 +271,12 @@ ...@@ -265,6 +271,12 @@
<dictionary/> <dictionary/>
</value> </value>
</item> </item>
<item>
<key> <string>source_section_where_expression</string> </key>
<value>
<dictionary/>
</value>
</item>
<item> <item>
<key> <string>specific_reference</string> </key> <key> <string>specific_reference</string> </key>
<value> <value>
...@@ -338,6 +350,8 @@ ...@@ -338,6 +350,8 @@
<string>no_limit</string> <string>no_limit</string>
<string>search_result_keys</string> <string>search_result_keys</string>
<string>delivery_mirror_section_title</string> <string>delivery_mirror_section_title</string>
<string>source_section_where_expression</string>
<string>destination_section_where_expression</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -380,7 +394,9 @@ transaction_uid=""\r\n ...@@ -380,7 +394,9 @@ transaction_uid=""\r\n
specific_reference\r\n specific_reference\r\n
no_limit\r\n no_limit\r\n
search_result_keys=\'\'\r\n search_result_keys=\'\'\r\n
delivery_mirror_section_title=""</string> </value> delivery_mirror_section_title=""\r\n
source_section_where_expression\r\n
destination_section_where_expression</string> </value>
</item> </item>
<item> <item>
<key> <string>cache_time_</string> </key> <key> <string>cache_time_</string> </key>
...@@ -618,10 +634,14 @@ delivery_mirror_section_title=""</string> </value> ...@@ -618,10 +634,14 @@ delivery_mirror_section_title=""</string> </value>
<dtml-elif count>\n <dtml-elif count>\n
SELECT COUNT(DISTINCT uid) AS count FROM (\n SELECT COUNT(DISTINCT uid) AS count FROM (\n
<dtml-else>\n <dtml-else>\n
SELECT * from (\n SELECT catalog.*,\n
<dtml-let accounting_movement_list="portal_url.getPortalObject().getPortalAccountingMovementTypeList()">\n
( SELECT SUM(stock.total_price) FROM stock, catalog AS child WHERE child.uid = stock.uid AND child.parent_uid = catalog.uid AND stock.total_price > 0 AND <dtml-sqltest accounting_movement_list type=string column=child.portal_type op=eq multiple>) AS debit,\n
( SELECT -SUM(stock.total_price) FROM stock, catalog AS child WHERE child.uid = stock.uid AND child.parent_uid = catalog.uid AND stock.total_price < 0 AND <dtml-sqltest accounting_movement_list type=string column=child.portal_type op=eq multiple>) AS credit\n
FROM (\n
</dtml-let>\n
</dtml-if>\n </dtml-if>\n
\n \n
\n
<dtml-comment>\n <dtml-comment>\n
##################\n ##################\n
# #\n # #\n
...@@ -681,6 +701,9 @@ delivery_mirror_section_title=""</string> </value> ...@@ -681,6 +701,9 @@ delivery_mirror_section_title=""</string> </value>
<dtml-if "query[\'where_expression\']">\n <dtml-if "query[\'where_expression\']">\n
AND <dtml-var "query[\'where_expression\']">\n AND <dtml-var "query[\'where_expression\']">\n
</dtml-if>\n </dtml-if>\n
<dtml-if source_section_where_expression>\n
AND <dtml-var source_section_where_expression>\n
</dtml-if>\n
<dtml-if selection_domain>\n <dtml-if selection_domain>\n
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
</dtml-if>\n </dtml-if>\n
...@@ -860,6 +883,9 @@ UNION\n ...@@ -860,6 +883,9 @@ UNION\n
<dtml-if "query[\'where_expression\']">\n <dtml-if "query[\'where_expression\']">\n
AND <dtml-var "query[\'where_expression\']">\n AND <dtml-var "query[\'where_expression\']">\n
</dtml-if>\n </dtml-if>\n
<dtml-if destination_section_where_expression>\n
AND <dtml-var destination_section_where_expression>\n
</dtml-if>\n
<dtml-if selection_domain>\n <dtml-if selection_domain>\n
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
</dtml-if>\n </dtml-if>\n
...@@ -1250,10 +1276,14 @@ UNION\n ...@@ -1250,10 +1276,14 @@ UNION\n
<dtml-elif count>\n <dtml-elif count>\n
SELECT COUNT(DISTINCT uid) AS count FROM (\n SELECT COUNT(DISTINCT uid) AS count FROM (\n
<dtml-else>\n <dtml-else>\n
SELECT * from (\n SELECT catalog.*,\n
<dtml-let accounting_movement_list="portal_url.getPortalObject().getPortalAccountingMovementTypeList()">\n
( SELECT SUM(stock.total_price) FROM stock, catalog AS child WHERE child.uid = stock.uid AND child.parent_uid = catalog.uid AND stock.total_price > 0 AND <dtml-sqltest accounting_movement_list type=string column=child.portal_type op=eq multiple>) AS debit,\n
( SELECT -SUM(stock.total_price) FROM stock, catalog AS child WHERE child.uid = stock.uid AND child.parent_uid = catalog.uid AND stock.total_price < 0 AND <dtml-sqltest accounting_movement_list type=string column=child.portal_type op=eq multiple>) AS credit\n
FROM (\n
</dtml-let>\n
</dtml-if>\n </dtml-if>\n
\n \n
\n
<dtml-comment>\n <dtml-comment>\n
##################\n ##################\n
# #\n # #\n
...@@ -1313,6 +1343,9 @@ UNION\n ...@@ -1313,6 +1343,9 @@ UNION\n
<dtml-if "query[\'where_expression\']">\n <dtml-if "query[\'where_expression\']">\n
AND <dtml-var "query[\'where_expression\']">\n AND <dtml-var "query[\'where_expression\']">\n
</dtml-if>\n </dtml-if>\n
<dtml-if source_section_where_expression>\n
AND <dtml-var source_section_where_expression>\n
</dtml-if>\n
<dtml-if selection_domain>\n <dtml-if selection_domain>\n
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
</dtml-if>\n </dtml-if>\n
...@@ -1492,6 +1525,9 @@ UNION\n ...@@ -1492,6 +1525,9 @@ UNION\n
<dtml-if "query[\'where_expression\']">\n <dtml-if "query[\'where_expression\']">\n
AND <dtml-var "query[\'where_expression\']">\n AND <dtml-var "query[\'where_expression\']">\n
</dtml-if>\n </dtml-if>\n
<dtml-if destination_section_where_expression>\n
AND <dtml-var destination_section_where_expression>\n
</dtml-if>\n
<dtml-if selection_domain>\n <dtml-if selection_domain>\n
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
</dtml-if>\n </dtml-if>\n
......
585 588
\ 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