############################################################################## # # Copyright (c) 2005 TINY SPRL. (http://tiny.be) All Rights Reserved. # # $Id: gantt_report.py 1005 2005-07-25 08:41:42Z nicoe $ # # WARNING: This program as such is intended to be used by professional # programmers who take the whole responsability of assessing all potential # consequences resulting from its eventual inadequacies and bugs # End users who are looking for a ready-to-use solution with commercial # garantees and support are strongly adviced to contract a Free Software # Service Company # # This program is Free Software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## from mx import DateTime import time def compute_burndown(cr, uid, tasks_id, date_start, date_stop): latest = False cr.execute('select id,create_date,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by create_date') tasks = cr.fetchall() cr.execute('select id,date_close,write_date,state,planned_hours*progress/100 from project_task where id in ('+','.join(map(str,tasks_id))+') and state in (%s,%s,%s,%s) order by date_close', ('progress','done','open','cancelled')) tasks2 = cr.fetchall() current_date = date_start total = 0 done = 0 result = [] while current_date<=date_stop: while len(tasks) and tasks[0][1] and tasks[0][1][:10]<=current_date: latest = tasks.pop(0) total += latest[3] i = 0 while i'cancelled': done += t[4] else: total -= t[4] elif tasks2[i][3] in ('open','progress') and tasks2[i][2] and tasks2[i][2][:10]<=current_date: print current_date, tasks2[i], '2' t = tasks2.pop(i) done += t[4] print 'open' elif (not tasks2[i][1]) and (not tasks2[i][2]): t = tasks2.pop(i) done += t[4] else: print current_date, tasks2[i], '3' i+=1 result.append( (int(time.mktime(time.strptime(current_date,'%Y-%m-%d'))), total-done) ) current_date = (DateTime.strptime(current_date, '%Y-%m-%d') + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d') if not len(tasks) and not len(tasks2): break result.append( (int(time.mktime(time.strptime(date_stop,'%Y-%m-%d'))), 0) ) return result