Commit 1e0994d9 authored by Guillaume Michon's avatar Guillaume Michon

Improved getTrackingList()


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5880 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4978058c
......@@ -184,12 +184,14 @@ class SimulationTool (BaseTool):
from_date=None, to_date=None, at_date=None,
resource=None, node=None, payment=None,
section=None, mirror_section=None,
item=None, input=0, output=0,
resource_category=None, node_category=None, payment_category=None,
section_category=None, mirror_section_category=None,
strict_simulation_state=0,
simulation_state=None, transit_simulation_state = None, omit_transit=0,
input_simulation_state = None, output_simulation_state=None,
variation_text=None, sub_variation_text=None,
variation_category=None,
variation_category=None, is_accountable=None,
**kw) :
"""
generates keywork and calls buildSqlQuery
......@@ -198,6 +200,10 @@ class SimulationTool (BaseTool):
new_kw.update(kw)
sql_kw = {}
# input and output are used by getTrackingList
sql_kw['input'] = input
sql_kw['output'] = output
date_dict = {'query':[], 'operator':'and'}
if from_date :
date_dict['query'].append(from_date)
......@@ -221,6 +227,13 @@ class SimulationTool (BaseTool):
if len(resource_uid_list) :
new_kw[table + '.resource_uid'] = resource_uid_list
if is_accountable is not None:
new_kw[table + '.is_accountable'] = is_accountable
item_uid_list = self._generatePropertyUidList(item)
if len(item_uid_list) :
new_kw[table + '.aggregate_uid'] = item_uid_list
node_uid_list = self._generatePropertyUidList(node)
if len(node_uid_list) :
new_kw[table + '.node_uid'] = node_uid_list
......@@ -270,6 +283,12 @@ class SimulationTool (BaseTool):
# new_kw['variationCategory'] = variation_category_uid_list
# Simulation States
# If strict_simulation_state is set, we directly put it into the dictionary
if strict_simulation_state:
if type(simulation_state) in [type(''),type([]),type(())]:
if len(simulation_state):
new_kw['simulation_state'] = simulation_state
else:
# first, we evaluate simulation_state
if (type(simulation_state) is type('')) or (type(simulation_state) is type([])) or (type(simulation_state) is type(())) :
if len(simulation_state) :
......@@ -327,15 +346,15 @@ class SimulationTool (BaseTool):
# build the group by expression
group_by_expression_list = []
if kw.get('group_by_node',0):
group_by_expression_list.append('stock.node_uid')
group_by_expression_list.append('%s.node_uid' % table)
if kw.get('group_by_sub_variation',0):
group_by_expression_list.append('stock.sub_variation_text')
group_by_expression_list.append('%s.sub_variation_text' % table)
if kw.get('group_by_variation',0):
group_by_expression_list.append('stock.variation_text')
group_by_expression_list.append('%s.variation_text' % table)
if kw.get('group_by_mirror_node',0):
group_by_expression_list.append('stock.mirror_node_uid')
group_by_expression_list.append('%s.mirror_node_uid' % table)
if len(group_by_expression_list):
group_by_expression_list.append('stock.resource_uid') # Always group by resource
group_by_expression_list.append('%s.resource_uid' % table) # Always group by resource
sql_kw['group_by_expression'] = ', '.join(group_by_expression_list)
sql_kw.update(self.portal_catalog.buildSQLQuery(**new_kw))
......@@ -768,7 +787,8 @@ class SimulationTool (BaseTool):
# Traceability management
security.declareProtected(Permissions.AccessContentsInformation, 'getTrackingList')
def getTrackingList(self, src__=0,
selection_domain=None, selection_report=None, **kw) :
selection_domain=None, selection_report=None,
strict_simulation_state=1, **kw) :
"""
Returns a list of items in the form
......@@ -778,6 +798,7 @@ class SimulationTool (BaseTool):
section_uid
resource_uid
variation_text
delivery_uid
If at_date is provided, returns the a list which answers
to the question "where are those items at this date" or
......@@ -826,34 +847,36 @@ class SimulationTool (BaseTool):
simulation_state - only take rows with specified simulation_state
transit_simulation_state - take rows with specified transit_simulation_state and quantity < 0
selection_domain, selection_report - see ListBox
omit_transit - do not evaluate transit_simulation_state
**kw - if we want extended selection with more keywords (but bad performance)
check what we can do with buildSqlQuery
input_simulation_state - only take rows with specified input_simulation_state and quantity > 0
Extra parameters for getTrackingList :
output_simulation_state - only take rows with specified output_simulation_state and quantity < 0
item
selection_domain, selection_report - see ListBox
input - if set, answers to the question "which are those items which have been
delivered for the first time after from_date". Cannot be used with output
**kw - if we want extended selection with more keywords (but bad performance)
check what we can do with buildSqlQuery
output - if set, answers to the question "which are those items which have been
delivered for the last time before at_date or to_date". Cannot be used with input
"""
new_kw = {}
new_kw = self._generateSQLKeywordDict(table='item',strict_simulation_state=strict_simulation_state,**kw)
new_kw['at_date'] = kw.get('at_date')
new_kw['node_uid'] = self.portal_categories.getCategoryUid(kw.get('node'))
section_uid_list = self._generatePropertyUidList(kw.get('section'))
if len(section_uid_list) :
new_kw['section_uid_list'] = section_uid_list
# Extra parameters for the SQL Method
new_kw['join_on_item'] = new_kw.get('at_date') or \
new_kw.get('input') or \
new_kw.get('output')
new_kw['date_condition_in_join'] = not (new_kw.get('input') or new_kw.get('output'))
for property_name in ('portal_type', 'variation_text', 'simulation_state'):
property_list = self._generatePropertyUidList(kw.get(property_name), as_text=1)
if len(property_list) :
new_kw['%s_list' % property_name] = property_list
return self.Resource_zGetTrackingList(src__=src__, **new_kw)
return self.Resource_zGetTrackingList(src__=src__,
selection_domain=selection_domain,
selection_report=selection_report,
**new_kw)
security.declareProtected(Permissions.AccessContentsInformation, 'getCurrentTrackingList')
def getCurrentTrackingList(self, **kw):
......
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