1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
25 from report.render import render
26 from report.interface import report_int
28 from datetime import datetime
35 class report_tasks(report_int):
36 def create(self, cr, uid, ids, datas, context=None):
39 io = StringIO.StringIO()
41 canv = canvas.init(fname=io, format='pdf')
42 canv.set_author("OpenERP")
43 canv.set_title("Burndown Chart")
44 pool = pooler.get_pool(cr.dbname)
45 sprint_pool = pool.get('project.scrum.sprint')
46 task_pool = pool.get('project.task')
47 int_to_date = lambda x: '/a60{}' + datetime(time.localtime(x).tm_year, time.localtime(x).tm_mon, time.localtime(x).tm_mday).strftime('%d %m %Y')
48 for sprint in sprint_pool.browse(cr, uid, ids, context=context):
49 task_ids = task_pool.search(cr, uid, [('sprint_id','=',sprint.id)], context=context)
50 datas = _burndown.compute_burndown(cr, uid, task_ids, sprint.date_start, sprint.date_stop)
51 max_hour = reduce(lambda x,y: max(y[1],x), datas, 0)
52 def _interval_get(*args):
55 d = time.localtime(datas[0][0] + (((datas[-1][0]-datas[0][0])/20)*(i+1)))
57 if (not result) or result[-1]<>res:
61 guideline__data=[(datas[0][0],max_hour), (datas[-1][0],0)]
63 ar = area.T(x_grid_style=line_style.gray50_dash1,
64 x_axis=axis.X(label="Date", format=int_to_date),
65 y_axis=axis.Y(label="Burndown Chart - Planned Hours"),
66 x_grid_interval=_interval_get,
67 x_range = (datas[0][0],datas[-1][0]),
68 y_range = (0,max_hour),
71 ar.add_plot(line_plot.T(data=guideline__data, line_style=line_style.red))
72 ar.add_plot(line_plot.T(data=datas, line_style=line_style.green))
74 entr1 = pychart.legend.Entry(label="guideline", line_style=line_style.red)
75 entr2 = pychart.legend.Entry(label="burndownchart",line_style=line_style.green)
76 legend = pychart.legend.T(nr_rows=2, inter_row_sep=5)
77 legend.draw(ar,[entr1,entr2],canv)
82 self.obj = _burndown.external_pdf(io.getvalue())
84 return (self.obj.pdf, 'pdf')
85 report_tasks('report.scrum.sprint.burndown')
87 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: