Commit 64fa4e22 authored by Vincent Pelletier's avatar Vincent Pelletier

erp5_accounting: Factorise grouping query generation.

Allows overriding it on instances where the invariant
  grouping_reference IS NULL == grouping_date IS NULL
is applicable, allowing simpler query execution plans.
parent d3c820fd
"""Get the report sections for general ledger
"""
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
from Products.ERP5Form.Report import ReportSection
portal = context.portal_url.getPortalObject()
request = portal.REQUEST
......@@ -98,10 +98,7 @@ default_selection_params['no_mirror_section_uid_cache'] = 1
# if user request report without grouping reference, don't show accounts that only have grouped lines in the period.
if request.get('omit_grouping_reference', False):
if at_date:
params['grouping_query'] = ComplexQuery(
SimpleQuery(grouping_reference=None),
SimpleQuery(grouping_date=at_date, comparison_operator=">="),
logical_operator="OR")
params['grouping_query'] = portal.ERP5Site_getIsNotGrouppedAtQuery(at_date)
else:
params['grouping_reference'] = None
......
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
from Products.PythonScripts.standard import Object
portal = context.getPortalObject()
params = portal.ERP5Site_getAccountingSelectionParameterDict(selection_name)
......@@ -14,10 +13,7 @@ total_credit_price = 0
at_date = (from_date - 1).latestTime()
inventory_query = {
'at_date': at_date, # this is not to_date
'grouping_query': ComplexQuery(
SimpleQuery(grouping_reference=None),
SimpleQuery(grouping_date=at_date, comparison_operator=">="),
logical_operator="OR"),
'grouping_query': portal.ERP5Site_getIsNotGrouppedAtQuery(at_date),
'simulation_state': params['simulation_state'],
'node_uid': kw['node_uid'],
'portal_type': portal.getPortalAccountingMovementTypeList(),
......
......@@ -38,7 +38,6 @@ reportCallback ((line_list) -> list of dict)
line_list.
"""
from collections import defaultdict
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
from Products.PythonScripts.standard import Object
if reportCallback is None:
reportCallback = lambda x: x
......@@ -86,11 +85,7 @@ for brain in portal.portal_simulation.getMovementHistoryList(
section_category,
section_category_strict,
),
grouping_query=ComplexQuery(
SimpleQuery(grouping_reference=None),
SimpleQuery(grouping_date=at_date, comparison_operator=">="),
logical_operator="OR",
),
grouping_query=portal.ERP5Site_getIsNotGrouppedAtQuery(at_date),
**extra_kw
):
total_price = brain.total_price or 0
......
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
return ComplexQuery(
SimpleQuery(grouping_reference=None),
SimpleQuery(grouping_date=grouping_date, comparison_operator=">="),
logical_operator="OR",
)
<?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>_params</string> </key>
<value> <string>grouping_date</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getIsNotGrouppedAtQuery</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.ERP5Type.Document import newTempBase
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
from Products.ERP5Type.Message import translateString
from Products.ERP5Type.Log import log
portal = context.getPortalObject()
......@@ -89,10 +89,7 @@ if is_pl_account and not from_date:
if portal.portal_selections.getSelectionParamsFor(selection_name).get('omit_grouping_reference'):
if params.get('at_date'):
params['grouping_query'] = ComplexQuery(
SimpleQuery(grouping_reference=None),
SimpleQuery(grouping_date=params['at_date'], comparison_operator=">="),
logical_operator="OR")
params['grouping_query'] = portal.ERP5Site_getIsNotGrouppedAtQuery(params['at_date'])
else:
params['grouping_reference'] = None
......
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