From 85084db0b8ec755b97e56f0754a77da705ce6fab Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Wed, 5 Sep 2007 08:48:50 +0000 Subject: [PATCH] Update group-by heuristic method: - it's its job to handle group-by-resource-by-default behaviour when another group-by is provided - move task of updating dictionnary from this method to caller, to make it easier to understand when reading caller git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16062 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Tool/SimulationTool.py | 38 ++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/product/ERP5/Tool/SimulationTool.py b/product/ERP5/Tool/SimulationTool.py index 055931cdac..f61dbd9a06 100644 --- a/product/ERP5/Tool/SimulationTool.py +++ b/product/ERP5/Tool/SimulationTool.py @@ -806,20 +806,34 @@ class SimulationTool(BaseTool): """ return self.getInventory(simulation_period='Future', **kw) - def _getDefaultGroupByParameters(self, ignore_group_by=0, **kw): + def _getDefaultGroupByParameters(self, ignore_group_by=0, + group_by_node=0, group_by_mirror_node=0, + group_by_section=0, group_by_mirror_section=0, + group_by_payment=0, + group_by_variation=0, group_by_sub_variation=0, + group_by_movement=0, + group_by_resource=1, + **ignored): """ Set defaults group_by parameters + + If ignore_group_by is true, this function returns an empty dict. + + If any group-by is provided, automatically group by resource aswell + unless group_by_resource is explicitely set to false. + If no group by is provided, group by movement, node and resource. """ - if not (ignore_group_by \ - or kw.get('group_by_node', 0) or kw.get('group_by_mirror_node', 0) \ - or kw.get('group_by_section', 0) or kw.get('group_by_mirror_section', 0) \ - or kw.get('group_by_payment', 0) or kw.get('group_by_sub_variation', 0) \ - or kw.get('group_by_variation', 0) or kw.get('group_by_movement', 0) \ - or kw.get('group_by_resource', 0)): - kw['group_by_movement'] = 1 - kw['group_by_node'] = 1 - kw['group_by_resource'] = 1 - return kw + new_group_by_dict = {} + if not ignore_group_by: + if group_by_node or group_by_mirror_node or group_by_section or \ + group_by_mirror_section or group_by_payment or \ + group_by_sub_variation or group_by_variation or group_by_movement: + new_group_by_dict['group_by_resource'] = group_by_resource + else: + new_group_by_dict['group_by_movement'] = 1 + new_group_by_dict['group_by_node'] = 1 + new_group_by_dict['group_by_resource'] = 1 + return new_group_by_dict security.declareProtected(Permissions.AccessContentsInformation, 'getInventoryList') @@ -838,7 +852,7 @@ class SimulationTool(BaseTool): average, cost, etc.) """ # If no group at all, give a default sort group by - kw = self._getDefaultGroupByParameters(**kw) + kw.update(self._getDefaultGroupByParameters(**kw)) sql_kw = self._generateSQLKeywordDict(**kw) return self.Resource_zGetInventoryList( src__=src__, ignore_variation=ignore_variation, -- 2.30.9