1
##############################################################################
3
# Copyright (c) 2005 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# $Id: _date_compute.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
##############################################################################
31
from mx.DateTime import *
37
# TODO: improve sequences code
39
def _compute_tasks(cr, uid, task_list, date_begin):
43
last_date = date_begin
44
for task in task_list:
45
# TODO: reorder ! with dependencies
46
if not task.planned_hours:
48
if task.state in ('open','progress') and task.user_id:
50
# Find the starting date of the task
51
if task.user_id.id in users:
52
date_start = users[task.user_id.id]
54
date_start = date_begin
55
if task.start_sequence:
57
for (seq,dt) in sequences:
59
date_start = max(dt,date_start)
63
if task.date_start and date_start<task.date_start:
64
date_start = task.date_start
66
# Compute the closing date of the task
68
res = pooler.get_pool(cr.dbname).get('hr.timesheet.group').interval_get(cr, uid, task.project_id.timesheet_id.id, date_start, task.planned_hours)
70
tasks[task.id].append((d1, d2, task.name, task.user_id.login))
71
date_close = tasks[task.id][-1][1]
74
users[task.user_id.id] = date_close
75
sequences.append((task.sequence, date_close))
76
if date_close>last_date:
78
return tasks, last_date
80
def _compute_project(cr, uid, project, date_begin):
81
tasks, last_date = _compute_tasks(cr, uid, project.tasks, date_begin)
82
for proj in project.child_id:
83
d0 = mx.DateTime.strptime(proj.date_start,'%Y-%m-%d')
86
t2, l2 = _compute_project(cr, uid, proj, last_date)
89
return tasks, last_date
91
def _project_compute(cr, uid, project_id):
92
project = pooler.get_pool(cr.dbname).get('project.project').browse(cr, uid, project_id)
93
if project.date_start:
94
date_begin = mx.DateTime.strptime(project.date_start, '%Y-%m-%d')
97
tasks, last_date = _compute_project(cr, uid, project, date_begin)
98
return tasks, last_date