2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2009-11-23 11:49:56 +00:00
#
2009-10-14 11:15:34 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2006-12-07 13:41:40 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2006-12-07 13:41:40 +00:00
#
2008-11-03 19:18:56 +00:00
# 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
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2006-12-07 13:41:40 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-11-23 11:49:56 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
from mx import DateTime
import time
def compute_burndown ( cr , uid , tasks_id , date_start , date_stop ) :
2008-07-22 15:11:28 +00:00
latest = False
if len ( tasks_id ) :
2010-06-10 13:34:19 +00:00
cr . execute ( ' select id,create_date,state,planned_hours from project_task where id IN %s order by create_date ' , ( tuple ( tasks_id ) , ) )
2008-07-22 15:11:28 +00:00
tasks = cr . fetchall ( )
2006-12-07 13:41:40 +00:00
2010-06-10 13:34:19 +00:00
cr . execute ( ' select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id IN %s and t.state in ( %s , %s ) order by date ' , ( tuple ( tasks_id ) , ' open ' , ' progress ' , ) )
2008-07-22 15:11:28 +00:00
tasks2 = cr . fetchall ( )
2006-12-07 13:41:40 +00:00
2010-06-10 13:34:19 +00:00
cr . execute ( ' select date_end,planned_hours from project_task where id IN %s and state in ( %s , %s ) order by date_end ' , ( tuple ( tasks_id ) , ' cancelled ' , ' done ' , ) )
2008-07-22 15:11:28 +00:00
tasks2 + = cr . fetchall ( )
tasks2 . sort ( )
else :
tasks = [ ]
tasks2 = [ ]
2006-12-07 13:41:40 +00:00
2008-07-22 15:11:28 +00:00
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 < len ( tasks2 ) :
2010-02-25 07:13:59 +00:00
if tasks2 [ i ] [ 0 ] and tasks2 [ i ] [ 0 ] [ : 10 ] < = current_date :
2008-07-22 15:11:28 +00:00
t = tasks2 . pop ( i )
done + = t [ 1 ]
else :
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
2006-12-07 13:41:40 +00:00
2008-07-23 14:41:47 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: