From 423c3e35705d093f614664d842e444535f4016dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 17 Sep 2015 09:29:43 +0200 Subject: [PATCH] Split duration into simple and total duration As the project doesn't have anymore the same tree structure, it requires to have the duration only of the work but it still needs the total for work reporting. issue4970 review20391003 --- CHANGELOG | 2 ++ view/work_graph.xml | 2 +- view/work_tree2.xml | 2 +- work.py | 22 ++++++++++++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bca10c5ece..ac2d009e34 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Split duration into simple and total duration + Version 3.6.0 - 2015-04-20 * Bug fixes (see mercurial logs for details) * Add support for PyPy diff --git a/view/work_graph.xml b/view/work_graph.xml index 0e598ba90c..8195458fbf 100644 --- a/view/work_graph.xml +++ b/view/work_graph.xml @@ -6,6 +6,6 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/view/work_tree2.xml b/view/work_tree2.xml index 81e9d02e2f..9cc87c0b98 100644 --- a/view/work_tree2.xml +++ b/view/work_tree2.xml @@ -3,5 +3,5 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/work.py b/work.py index a1109c9025..bc803da76e 100644 --- a/work.py +++ b/work.py @@ -38,6 +38,10 @@ class Work(ModelSQL, ModelView): duration = fields.Function(fields.TimeDelta('Timesheet Duration', 'company_work_time', help="Total time spent on this work"), 'get_duration') + total_duration = fields.Function(fields.TimeDelta( + 'Total Timesheet Duration', 'company_work_time', + help='Total time spent on this work and the sub-works'), + 'get_duration') timesheet_available = fields.Boolean('Available on timesheets', help="Allow to fill in timesheets with this work") timesheet_start_date = fields.Date('Timesheet Start', @@ -103,7 +107,6 @@ class Work(ModelSQL, ModelView): context = transaction.context table_w = cls.__table__() - table_c = cls.__table__() line = Line.__table__() ids = [w.id for w in works] durations = dict.fromkeys(ids, None) @@ -114,13 +117,20 @@ class Work(ModelSQL, ModelView): where &= line.date <= context['to_date'] if context.get('employees'): where &= line.employee.in_(context['employees']) + + if name == 'duration': + query_table = table_w.join(line, 'LEFT', + condition=line.work == table_w.id) + else: + table_c = cls.__table__() + query_table = table_w.join(table_c, + condition=(table_c.left >= table_w.left) + & (table_c.right <= table_w.right) + ).join(line, 'LEFT', condition=line.work == table_c.id) + for sub_ids in grouped_slice(ids): red_sql = reduce_ids(table_w.id, sub_ids) - cursor.execute(*table_w.join(table_c, - condition=(table_c.left >= table_w.left) - & (table_c.right <= table_w.right) - ).join(line, 'LEFT', condition=line.work == table_c.id - ).select(table_w.id, Sum(line.duration), + cursor.execute(*query_table.select(table_w.id, Sum(line.duration), where=red_sql & where, group_by=table_w.id)) for work_id, duration in cursor.fetchall():