~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to project/report/_date_compute.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2005 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id: _date_compute.py 1005 2005-07-25 08:41:42Z nicoe $
 
6
#
 
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
 
12
# Service Company
 
13
#
 
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.
 
18
#
 
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.
 
23
#
 
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.
 
27
#
 
28
##############################################################################
 
29
 
 
30
import mx.DateTime
 
31
from mx.DateTime import *
 
32
 
 
33
import time
 
34
import pooler
 
35
 
 
36
#
 
37
# TODO: improve sequences code
 
38
#
 
39
def _compute_tasks(cr, uid, task_list, date_begin):
 
40
        sequences = []
 
41
        users = {}
 
42
        tasks = {}
 
43
        last_date = date_begin
 
44
        for task in task_list:
 
45
                # TODO: reorder ! with dependencies
 
46
                if not task.planned_hours:
 
47
                        continue
 
48
                if task.state in ('open','progress') and task.user_id:
 
49
 
 
50
                        # Find the starting date of the task
 
51
                        if task.user_id.id in users:
 
52
                                date_start = users[task.user_id.id]
 
53
                        else:
 
54
                                date_start = date_begin
 
55
                        if task.start_sequence:
 
56
                                sequences.sort()
 
57
                                for (seq,dt) in sequences:
 
58
                                        if seq<task.sequence:
 
59
                                                date_start = max(dt,date_start)
 
60
                                        else:
 
61
                                                break
 
62
 
 
63
                        if task.date_start and date_start<task.date_start:
 
64
                                date_start = task.date_start
 
65
 
 
66
                        # Compute the closing date of the task
 
67
                        tasks[task.id] = []
 
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)
 
69
                        for (d1,d2) in res:
 
70
                                tasks[task.id].append((d1, d2, task.name, task.user_id.login))
 
71
                        date_close = tasks[task.id][-1][1]
 
72
 
 
73
                        # Store result
 
74
                        users[task.user_id.id] = date_close
 
75
                        sequences.append((task.sequence, date_close))
 
76
                        if date_close>last_date:
 
77
                                last_date=date_close
 
78
        return tasks, last_date
 
79
 
 
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')
 
84
                if d0 > last_date:
 
85
                        last_date = d0
 
86
                t2, l2 = _compute_project(cr, uid, proj, last_date)
 
87
                tasks.update(t2)
 
88
                last_date = l2
 
89
        return tasks, last_date
 
90
 
 
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')
 
95
        else:
 
96
                date_begin = now()
 
97
        tasks, last_date = _compute_project(cr, uid, project, date_begin)
 
98
        return tasks, last_date
 
99