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
This commit is contained in:
Cédric Krier committed 2015-09-17 09:29:43 +02:00
1 parent 3271d661b5
commit 423c3e3570
4 files changed
+20 -8

No files matched your search

+2
View File
@@ -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
+1 -1
View File
@@ -6,6 +6,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="name"/>
</x>
<y>
<field name="duration" timedelta="company_work_time"/>
<field name="total_duration" timedelta="company_work_time"/>
</y>
</graph>
+1 -1
View File
@@ -3,5 +3,5 @@
this repository contains the full copyright notices and license terms. -->
<tree string="Works">
<field name="name"/>
<field name="duration"/>
<field name="total_duration"/>
</tree>
+16 -6
View File
@@ -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():