Пример #1
0
    def create(self, cr, uid, ids, datas, context=None):
        if context is None:
            context = {}
        io = StringIO.StringIO()

        if "date_start" not in datas:
            cr.execute("select min(date_start) from project_task where id IN %s", (tuple(ids),))
            dt = cr.fetchone()[0]
            if dt:
                datas["date_start"] = dt[:10]
            else:
                datas["date_start"] = time.strftime("%Y-%m-%d")
        if "date_stop" not in datas:
            cr.execute("select max(date_start),max(date_end) from project_task where id IN %s", (tuple(ids),))
            res = cr.fetchone()
            datas["date_stop"] = (res[0] and res[0][:10]) or time.strftime("%Y-%m-%d")
            if res[1] and datas["date_stop"] < res[1]:
                datas["date_stop"] = res[1][:10]

        datas = _burndown.compute_burndown(cr, uid, ids, datas["date_start"], datas["date_stop"])
        canv = canvas.init(fname=io, format="pdf")
        canv.set_author("OpenERP")

        max_hour = reduce(lambda x, y: max(y[1], x), datas, 0)

        int_to_date = lambda x: "/a60{}" + datetime(
            time.localtime(x).tm_year, time.localtime(x).tm_mon, time.localtime(x).tm_mday
        ).strftime("%d %m %Y")

        def _interval_get(*args):
            result = set()
            for i in range(20):
                d = time.localtime(datas[0][0] + (((datas[-1][0] - datas[0][0]) / 20) * (i + 1)))
                res = time.mktime(d)
                result.add(res)

            return list(result)

        if datas[-1][0] == datas[0][0]:
            x_range = (datas[0][0], datas[-1][0] + 1)
        else:
            x_range = (datas[0][0], datas[-1][0])

        ar = area.T(
            x_grid_style=line_style.gray50_dash1,
            x_axis=axis.X(label="Date", format=int_to_date),
            y_axis=axis.Y(label="Burndown Chart - Planned Hours"),
            x_grid_interval=_interval_get,
            x_range=x_range,
            y_range=(0, max_hour),
            legend=None,
            size=(680, 450),
        )
        ar.add_plot(line_plot.T(data=datas))
        ar.draw(canv)
        canv.close()

        self.obj = _burndown.external_pdf(io.getvalue())
        self.obj.render()
        return (self.obj.pdf, "pdf")
Пример #2
0
    def create(self, cr, uid, ids, datas, context=None):
        if context is None:
            context = {}
        io = StringIO.StringIO()

        canv = canvas.init(fname=io, format='pdf')
        canv.set_author("OpenERP")
        canv.set_title("Burndown Chart")
        pool = pooler.get_pool(cr.dbname)
        sprint_pool = pool.get('project.scrum.sprint')
        task_pool = pool.get('project.task')
        # For add the report header on the top of the report.
        tb = text_box.T(loc=(320, 500), text="/hL/15/bBurndown Chart", line_style=None)
        tb.draw()
        int_to_date = lambda x: '/a60{}' + datetime(time.localtime(x).tm_year, time.localtime(x).tm_mon, time.localtime(x).tm_mday).strftime('%d %m %Y')
        for sprint in sprint_pool.browse(cr, uid, ids, context=context):
            task_ids = task_pool.search(cr, uid, [('sprint_id','=',sprint.id)], context=context)
            datas = _burndown.compute_burndown(cr, uid, task_ids, sprint.date_start, sprint.date_stop)
            max_hour = reduce(lambda x,y: max(y[1],x), datas, 0) or None 
            def _interval_get(*args):
                result = []
                for i in range(20):
                    d = time.localtime(datas[0][0] + (((datas[-1][0]-datas[0][0])/20)*(i+1)))
                    res = time.mktime(d)
                    if (not result) or result[-1]<>res:
                        result.append(res)
                return result

            guideline__data=[(datas[0][0],max_hour), (datas[-1][0],0)]
            
            ar = area.T(x_grid_style=line_style.gray50_dash1,
                x_axis=axis.X(label="Date", format=int_to_date),
                y_axis=axis.Y(label="Burndown Chart - Planned Hours"),
                x_grid_interval=_interval_get,
                x_range = (datas[0][0],datas[-1][0]),
                y_range = (0,max_hour),
                legend = None,
                size = (680,450))
            ar.add_plot(line_plot.T(data=guideline__data, line_style=line_style.red))
            ar.add_plot(line_plot.T(data=datas, line_style=line_style.green))

            entr1 = pychart.legend.Entry(label="guideline", line_style=line_style.red)
            entr2 = pychart.legend.Entry(label="burndownchart",line_style=line_style.green)
            legend = pychart.legend.T(nr_rows=2, inter_row_sep=5)
            legend.draw(ar,[entr1,entr2],canv)

            ar.draw(canv)
        canv.close()

        self.obj = _burndown.external_pdf(io.getvalue())
        self.obj.render()
        return (self.obj.pdf, 'pdf')
Пример #3
0
    def create(self, cr, uid, ids, datas, context=None):
        if context is None:
            context = {}
        io = StringIO.StringIO()

        if 'date_start' not in datas:
            cr.execute(
                'select min(date_start) from project_task where id IN %s',
                (tuple(ids), ))
            dt = cr.fetchone()[0]
            if dt:
                datas['date_start'] = dt[:10]
            else:
                datas['date_start'] = time.strftime('%Y-%m-%d')
        if 'date_stop' not in datas:
            cr.execute(
                'select max(date_start),max(date_end) from project_task where id IN %s',
                (tuple(ids), ))
            res = cr.fetchone()
            datas['date_stop'] = (res[0]
                                  and res[0][:10]) or time.strftime('%Y-%m-%d')
            if res[1] and datas['date_stop'] < res[1]:
                datas['date_stop'] = res[1][:10]

        datas = _burndown.compute_burndown(cr, uid, ids, datas['date_start'],
                                           datas['date_stop'])
        canv = canvas.init(fname=io, format='pdf')
        canv.set_author("OpenERP")

        max_hour = reduce(lambda x, y: max(y[1], x), datas, 0)

        int_to_date = lambda x: '/a60{}' + datetime(
            time.localtime(x).tm_year,
            time.localtime(x).tm_mon,
            time.localtime(x).tm_mday).strftime('%d %m %Y')

        def _interval_get(*args):
            result = set()
            for i in range(20):
                d = time.localtime(datas[0][0] +
                                   (((datas[-1][0] - datas[0][0]) / 20) *
                                    (i + 1)))
                res = time.mktime(d)
                result.add(res)

            return list(result)

        if datas[-1][0] == datas[0][0]:
            x_range = (datas[0][0], datas[-1][0] + 1)
        else:
            x_range = (datas[0][0], datas[-1][0])

        ar = area.T(x_grid_style=line_style.gray50_dash1,
                    x_axis=axis.X(label="Date", format=int_to_date),
                    y_axis=axis.Y(label="Burndown Chart - Planned Hours"),
                    x_grid_interval=_interval_get,
                    x_range=x_range,
                    y_range=(0, max_hour),
                    legend=None,
                    size=(680, 450))
        ar.add_plot(line_plot.T(data=datas))
        ar.draw(canv)
        canv.close()

        self.obj = _burndown.external_pdf(io.getvalue())
        self.obj.render()
        return (self.obj.pdf, 'pdf')