1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# $Id: gantt_report.py 1005 2005-07-25 08:41:42Z nicoe $
7
# WARNING: This program as such is intended to be used by professional
8
# programmers who take the whole responsability of assessing all potential
9
# consequences resulting from its eventual inadequacies and bugs
10
# End users who are looking for a ready-to-use solution with commercial
11
# garantees and support are strongly adviced to contract a Free Software
14
# This program is Free Software; you can redistribute it and/or
15
# modify it under the terms of the GNU General Public License
16
# as published by the Free Software Foundation; either version 2
17
# of the License, or (at your option) any later version.
19
# This program is distributed in the hope that it will be useful,
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
# GNU General Public License for more details.
24
# You should have received a copy of the GNU General Public License
25
# along with this program; if not, write to the Free Software
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
##############################################################################
32
from report.render import render
33
from report.interface import report_int
35
from mx import DateTime
43
class external_pdf(render):
44
def __init__(self, pdf):
47
self.output_type='pdf'
51
def burndown_chart(cr, uid, tasks_id, date_start, date_stop):
53
cr.execute('select id,date_start,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by date_start')
55
cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id in ('+','.join(map(str,tasks_id))+') and state in (%s,%s) order by date_close', ('progress','done'))
56
tasks2 = cr.fetchall()
57
current_date = date_start
61
while current_date<=date_stop:
62
while len(tasks) and tasks[0][1] and tasks[0][1][:10]<=current_date:
63
total += tasks.pop(0)[3]
64
while len(tasks2) and tasks2[0][1] and tasks2[0][1][:10]<=current_date:
70
result.append( (int(time.mktime(time.strptime(current_date,'%Y-%m-%d'))), total-done) )
71
current_date = (DateTime.strptime(current_date, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d')
72
if not len(tasks) and not len(tasks2):
74
result.append( (int(time.mktime(time.strptime(date_stop,'%Y-%m-%d'))), 0) )
77
class report_tasks(report_int):
78
def create(self, cr, uid, ids, datas, context={}):
79
io = StringIO.StringIO()
81
if 'date_start' not in datas:
82
cr.execute('select min(date_start) from project_task where id in ('+','.join(map(str,ids))+')')
85
datas['date_start'] = dt[:10]
87
datas['date_start'] = time.strftime('%Y-%m-%d')
88
if 'date_stop' not in datas:
89
cr.execute('select max(date_start),max(date_close) from project_task where id in ('+','.join(map(str,ids))+')')
91
datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d')
92
if res[1] and datas['date_stop']<res[1]:
93
datas['date_stop'] = res[1][:10]
95
date_to_int = lambda x: int(x.ticks())
96
int_to_date = lambda x: '/a60{}'+DateTime.localtime(x).strftime('%d/%m/%Y')
98
datas = _burndown.compute_burndown(cr, uid, ids, datas['date_start'], datas['date_stop'])
100
canv = canvas.init(fname=io, format='pdf')
101
canv.set_author("Tiny ERP")
103
max_hour = reduce(lambda x,y: max(y[1],x), datas, 0)
105
date_to_int = lambda x: int(x.ticks())
106
int_to_date = lambda x: '/a60{}'+DateTime.localtime(x).strftime('%d %m %Y')
108
def _interval_get(*args):
111
d = DateTime.localtime(datas[0][0] + (((datas[-1][0]-datas[0][0])/20)*(i+1)))
112
res = DateTime.DateTime(d.year, d.month, d.day).ticks()
113
if (not result) or result[-1]<>res:
117
ar = area.T(x_grid_style=line_style.gray50_dash1,
118
x_axis=axis.X(label="Date", format=int_to_date),
119
y_axis=axis.Y(label="Burndown Chart - Planned Hours"),
120
x_grid_interval=_interval_get,
121
x_range = (datas[0][0],datas[-1][0]),
122
y_range = (0,max_hour),
125
ar.add_plot(line_plot.T(data=datas))
129
self.obj = external_pdf(io.getvalue())
131
return (self.obj.pdf,'pdf')
132
report_tasks('report.project.tasks.burndown')