[IMP] Removed Gantt Reports on projects

bzr revid: fp@tinyerp.com-20100305204957-mw3q524vvhatbycu
This commit is contained in:
Fabien Pinckaers 2010-03-05 21:49:57 +01:00
parent 7bd07b1c86
commit c1132f4647
6 changed files with 98 additions and 392 deletions

View File

@ -2,7 +2,5 @@
<openerp>
<data>
<report auto="False" menu="False" id="report_project_task_gantt" model="project.task" name="project.tasks.gantt" string="Gantt Representation"/>
<report auto="False" id="report_project_project_gantt" model="project.project" name="project.project.gantt" string="Gantt Representation"/>
</data>
</openerp>

View File

@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import gantt_report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,96 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from mx import DateTime
import time
import pooler
#
# TODO: improve sequences code
#
def _compute_tasks(cr, uid, task_list, date_begin):
sequences = []
users = {}
tasks = {}
last_date = date_begin
for task in task_list:
# TODO: reorder ! with dependencies
if not task.planned_hours:
continue
if task.state in ('draft','open','progress') and task.user_id:
# Find the starting date of the task
if task.user_id.id in users:
date_start = users[task.user_id.id]
else:
date_start = date_begin
sequences.sort()
for (seq,dt) in sequences:
if seq<task.sequence:
date_start = max(dt,date_start)
else:
break
if task.date_start:
task_date_start = DateTime.strptime(task.date_start, '%Y-%m-%d %H:%M:%S')
if DateTime.cmp(date_start, task_date_start) < 0:
date_start = task_date_start
# Compute the closing date of the task
tasks[task.id] = []
res = pooler.get_pool(cr.dbname).get('resource.calendar').interval_get(cr, uid, task.project_id.resource_calendar_id.id, date_start, task.remaining_hours)
for (d1,d2) in res:
tasks[task.id].append((d1, d2, task.name, task.user_id.login))
date_close = tasks[task.id] and tasks[task.id][-1][1] or False
# Store result
if date_close:
users[task.user_id.id] = date_close
sequences.append((task.sequence, date_close))
if date_close>last_date:
last_date=date_close
return tasks, last_date
def _compute_project(cr, uid, project, date_begin):
tasks, last_date = _compute_tasks(cr, uid, project.tasks, date_begin)
for proj in project.child_ids:
d0 = DateTime.strptime(proj.date_start,'%Y-%m-%d')
if d0 > last_date:
last_date = d0
t2, l2 = _compute_project(cr, uid, proj, last_date)
tasks.update(t2)
last_date = l2
return tasks, last_date
def _project_compute(cr, uid, project_id):
project = pooler.get_pool(cr.dbname).get('project.project').browse(cr, uid, project_id)
if project.date_start:
date_begin = DateTime.strptime(project.date_start, '%Y-%m-%d')
else:
date_begin = DateTime.now()
tasks, last_date = _compute_project(cr, uid, project, date_begin)
return tasks, last_date
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,108 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from mx.DateTime import RelativeDateTime, now, DateTime, localtime
from pychart import *
import pychart.legend
from report.misc import choice_colors
#
# Draw a graph
#
class GanttCanvas(object):
def __init__(self, io, convertors=(lambda x:x,lambda x:x)):
self._datas = {}
self._canvas = canvas.init(fname=io, format='pdf')
self._canvas.set_author("Open ERP")
self._names = {}
self._conv = convertors
self._min = 0
self._max = 0
def add(self, user, name, datas):
if hasattr(user, 'replace'):
user=user.replace('/', '//')
if hasattr(name, 'replace'):
name=name.replace('/', '//')
name = name.encode('ascii', 'ignore')
if user not in self._datas:
self._datas[user] = []
for f in datas:
x = map(self._conv[0], f)
if x[0]<self._min or not self._min:
self._min = x[0]
if x[1]>self._max or not self._max:
self._max = x[1]
self._datas[user].append( (name, x))
self._names.setdefault(name, x[0])
def draw(self):
colors = choice_colors(len(self._datas.keys()))
user_color = {}
for user in self._datas.keys():
user_color[user] = colors.pop()
names = []
for n in self._names:
names.append((self._names[n], n))
names.sort()
names.reverse()
def _interval_get(*args):
result = []
for i in range(20):
d = localtime(self._min + (((self._max-self._min)/20)*(i+1)))
res = DateTime(d.year, d.month, d.day).ticks()
if (not result) or result[-1]<>res:
result.append(res)
return result
ar = area.T(y_coord = category_coord.T(names, 1),
x_grid_style=line_style.gray50_dash1,
x_grid_interval=_interval_get,
x_range = (self._min,self._max),
x_axis=axis.X(label="Date", format=self._conv[1]),
y_axis=axis.Y(label="Tasks"),
legend = legend.T(), size = (680,450))
for user in self._datas:
chart_object.set_defaults(interval_bar_plot.T, direction="horizontal", data=self._datas[user])
f = fill_style.Plain()
f.bgcolor = user_color[user]
ar.add_plot(interval_bar_plot.T(fill_styles = [f, None], label=user, cluster=(0,1)))
ar.draw(self._canvas)
def close(self):
self._canvas.close()
if __name__ == '__main__':
date_to_int = lambda x: int(x.ticks())
int_to_date = lambda x: '/a60{}'+localtime(x).strftime('%d %m %Y')
gt = GanttCanvas('test.pdf', convertors=(date_to_int, int_to_date))
gt.add('nicoe', 'Graphe de gantt', [(DateTime(2005,6,12), DateTime(2005,6,13))])
gt.add('nicoe', 'Tarifs', [(DateTime(2005,6,19), DateTime(2005,6,21))])
gt.add('gaetan', 'Calcul des prix', [(DateTime(2005,6,12), DateTime(2005,6,13))])
gt.add('nico', 'Mise a jour du site', [(DateTime(2005,6,13), DateTime(2005,6,16))])
gt.add('tom', 'Coucou', [(DateTime(2005,6,11), DateTime(2005,6,12))])
gt.draw()
gt.close()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,87 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# 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.
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from mx.DateTime import *
import StringIO
from report.render import render
from report.interface import report_int
from gantt import GanttCanvas
from _date_compute import _project_compute, _compute_tasks
import pooler
class external_pdf(render):
def __init__(self, pdf):
render.__init__(self)
self.pdf = pdf
self.output_type='pdf'
def _render(self):
return self.pdf
class report_tasks(report_int):
def create(self, cr, uid, ids, datas, context={}):
io = StringIO.StringIO()
date_to_int = lambda x: int(x.ticks())
int_to_date = lambda x: '/a60{}'+localtime(x).strftime('%d %m %Y')
gt = GanttCanvas(io, convertors=(date_to_int, int_to_date))
tasks = pooler.get_pool(cr.dbname).get('project.task').browse(cr, uid, ids)
tasks, last_date = _compute_tasks(cr, uid, tasks, now())
for user_id in tasks.keys():
for t in tasks[user_id]:
gt.add(t[3], t[2], [(t[0],t[1])])
try:
gt.draw()
except:
pass
gt.close()
self.obj = external_pdf(io.getvalue())
self.obj.render()
return (self.obj.pdf, 'pdf')
report_tasks('report.project.tasks.gantt')
class report_projects(report_int):
def create(self, cr, uid, ids, datas, context={}):
io = StringIO.StringIO()
date_to_int = lambda x: int(x.ticks())
int_to_date = lambda x: '/a60{}'+localtime(x).strftime('%d %m %Y')
gt = GanttCanvas(io, convertors=(date_to_int, int_to_date))
tasks, last_date = _project_compute(cr, uid, ids[0])
for user_id in tasks.keys():
for t in tasks[user_id]:
gt.add(t[3], t[2], [(t[0],t[1])])
try:
gt.draw()
except:
pass
gt.close()
self.obj = external_pdf(io.getvalue())
self.obj.render()
return (self.obj.pdf, 'pdf')
report_projects('report.project.project.gantt')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,108 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:apply-templates select="projects"/>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="projects"/>
</xsl:template>
<xsl:template match="projects">
<document xmlns:fo="http://www.w3.org/1999/XSL/Format">
<template leftMargin="2.0cm" rightMargin="2.0cm" topMargin="2.0cm" bottomMargin="2.0cm" title="Project" author="Generated by OpenERP.com" allowSplitting="20">
<pageTemplate id="all">
<pageGraphics/>
<frame id="list" x1="1.0cm" y1="2.0cm" width="19.0cm" height="27cm"/>
</pageTemplate>
</template>
<xsl:template match="projects">
<document xmlns:fo="http://www.w3.org/1999/XSL/Format">
<template leftMargin="2.0cm" rightMargin="2.0cm" topMargin="2.0cm" bottomMargin="2.0cm" title="Project" author="Generated by OpenERP.com" allowSplitting="20">
<pageTemplate id="all">
<pageGraphics/>
<frame id="list" x1="1.0cm" y1="2.0cm" width="19.0cm" height="27cm"/>
</pageTemplate>
</template>
<stylesheet>
<paraStyle name="title" fontName="Helvetica-Bold" fontSize="18" alignment="center"/>
<paraStyle name="notes" fontName="Helvetica" fontSize="8" alignment="justify"/>
<blockTableStyle id="project">
<blockFont name="Helvetica-Bold" size="10" start="0,0" stop="0,-1"/>
<blockFont name="Helvetica-Bold" size="10" start="2,0" stop="2,-1"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="tasks">
<blockValign value="TOP"/>
<blockAlignment value="LEFT"/>
<blockFont name="Helvetica-Bold" size="10" start="0,0" stop="-1,0"/>
<lineStyle kind="LINEABOVE" thickness="0.5" colorName="black" start="0,0" stop="-1,0"/>
<lineStyle kind="LINEBELOW" thickness="0.5" colorName="black" start="0,0" stop="-1,0"/>
<blockBackground colorName="(0.72,0.72,0.72)" start="0,0" stop="-1,0"/>
<blockValign value="TOP"/>
<blockAlignment value="CENTER" start="1,0" stop="-1,-1"/>
</blockTableStyle>
</stylesheet>
<stylesheet>
<paraStyle name="title" fontName="Helvetica-Bold" fontSize="18" alignment="center"/>
<paraStyle name="notes" fontName="Helvetica" fontSize="8" alignment="justify"/>
<blockTableStyle id="project">
<blockFont name="Helvetica-Bold" size="10" start="0,0" stop="0,-1"/>
<blockFont name="Helvetica-Bold" size="10" start="2,0" stop="2,-1"/>
<blockValign value="TOP"/>
</blockTableStyle>
<blockTableStyle id="tasks">
<blockValign value="TOP"/>
<blockAlignment value="LEFT"/>
<blockFont name="Helvetica-Bold" size="10" start="0,0" stop="-1,0"/>
<lineStyle kind="LINEABOVE" thickness="0.5" colorName="black" start="0,0" stop="-1,0"/>
<lineStyle kind="LINEBELOW" thickness="0.5" colorName="black" start="0,0" stop="-1,0"/>
<blockBackground colorName="(0.72,0.72,0.72)" start="0,0" stop="-1,0"/>
<blockValign value="TOP"/>
<blockAlignment value="CENTER" start="1,0" stop="-1,-1"/>
</blockTableStyle>
</stylesheet>
<story>
<xsl:apply-templates select="project"/>
</story>
</document>
</xsl:template>
<story>
<xsl:apply-templates select="project"/>
</story>
</document>
</xsl:template>
<xsl:template match="members">
<xsl:value-of select="member_name"/> (<i><xsl:value-of select="member_login"/></i>),
</xsl:template>
<xsl:template match="members">
<xsl:value-of select="member_name"/> (<i><xsl:value-of select="member_login"/></i>),
</xsl:template>
<xsl:template match="task">
<tr>
<td>
<para><xsl:value-of select="task_name"/></para>
<para style="notes"><xsl:value-of select="task_description"/></para>
</td>
<td><xsl:value-of select="task_planned_hours"/></td>
<td><xsl:value-of select="task_effective_hours"/></td>
<td><xsl:value-of select="task_deadline"/></td>
<td><xsl:value-of select="task_user_id"/></td>
</tr>
</xsl:template>
<xsl:template match="task">
<tr>
<td>
<para><xsl:value-of select="task_name"/></para>
<para style="notes"><xsl:value-of select="task_description"/></para>
</td>
<td><xsl:value-of select="task_planned_hours"/></td>
<td><xsl:value-of select="task_effective_hours"/></td>
<td><xsl:value-of select="task_deadline"/></td>
<td><xsl:value-of select="task_user_id"/></td>
</tr>
</xsl:template>
<xsl:template match="tasks">
<blockTable style="tasks" colWidths="10cm,1.6cm,1.6cm,2cm,2.5cm">
<tr>
<td t="True">Tasks</td>
<td t="True">Hours</td>
<td t="True">Done</td>
<td t="True">Deadline</td>
<td t="True">Responsible</td>
</tr>
<xsl:apply-templates select="task"/>
</blockTable>
</xsl:template>
<xsl:template match="tasks">
<blockTable style="tasks" colWidths="10cm,1.6cm,1.6cm,2cm,2.5cm">
<tr>
<td t="True">Tasks</td>
<td t="True">Hours</td>
<td t="True">Done</td>
<td t="True">Deadline</td>
<td t="True">Responsible</td>
</tr>
<xsl:apply-templates select="task"/>
</blockTable>
</xsl:template>
<xsl:template match="project">
<para style="title">
<xsl:value-of select="name"/>
</para>
<spacer length="1cm"/>
<blockTable colWidths="3cm,6cm,3cm,6cm" style="project">
<tr>
<td t="True">Manager:</td>
<td><para><b><xsl:value-of select="manager"/></b></para></td>
<td t="True">Members:</td>
<td><para><xsl:apply-templates select="members"/></para></td>
</tr><tr>
<td t="True">Project:</td>
<td><xsl:value-of select="parent"/></td>
<td></td>
<td></td>
</tr><tr>
<td t="True">Date Start:</td>
<td><xsl:value-of select="date_start"/></td>
<td t="True">Date Stop:</td>
<td><xsl:value-of select="date_stop"/></td>
</tr><tr>
<td t="True">Planned Hours:</td>
<td><xsl:value-of select="planned_hours"/></td>
<td t="True">Effective Hours:</td>
<td><xsl:value-of select="effective_hours"/></td>
</tr>
</blockTable>
<spacer length="0.3cm"/>
<pre>
<xsl:value-of select="notes"/>
</pre>
<spacer length="0.7cm"/>
<xsl:apply-templates select="tasks"/>
<pageBreak/>
</xsl:template>
<xsl:template match="project">
<para style="title">
<xsl:value-of select="name"/>
</para>
<spacer length="1cm"/>
<blockTable colWidths="3cm,6cm,3cm,6cm" style="project">
<tr>
<td t="True">Manager:</td>
<td><para><b><xsl:value-of select="manager"/></b></para></td>
<td t="True">Members:</td>
<td><para><xsl:apply-templates select="members"/></para></td>
</tr><tr>
<td t="True">Project:</td>
<td><xsl:value-of select="parent"/></td>
<td></td>
<td></td>
</tr><tr>
<td t="True">Date Start:</td>
<td><xsl:value-of select="date_start"/></td>
<td t="True">Date Stop:</td>
<td><xsl:value-of select="date_stop"/></td>
</tr><tr>
<td t="True">Planned Hours:</td>
<td><xsl:value-of select="planned_hours"/></td>
<td t="True">Effective Hours:</td>
<td><xsl:value-of select="effective_hours"/></td>
</tr>
</blockTable>
<spacer length="0.3cm"/>
<pre>
<xsl:value-of select="notes"/>
</pre>
<spacer length="0.7cm"/>
<xsl:apply-templates select="tasks"/>
<pageBreak/>
</xsl:template>
</xsl:stylesheet>