示例#1
0
文件: custom.py 项目: mrmoyeez/XacCRM
    def _create_pie(self, cr, uid, ids, report, fields, results, context):
        pdf_string = cStringIO.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')
        ar = area.T(size=(350, 350),
                    legend=legend.T(),
                    x_grid_style=None,
                    y_grid_style=None)
        colors = map(lambda x: fill_style.Plain(bgcolor=x),
                     misc.choice_colors(len(results)))

        if reduce(lambda x, y: x + y, map(lambda x: x[1], results)) == 0.0:
            raise except_osv(
                _('Error'),
                _("The sum of the data (2nd field) is null.\nWe can't draw a pie chart !"
                  ))

        plot = pie_plot.T(data=results,
                          arc_offsets=[0, 10, 0, 10],
                          shadow=(2, -2, fill_style.gray50),
                          label_offset=25,
                          arrow_style=arrow.a3,
                          fill_styles=colors)
        ar.add_plot(plot)
        ar.draw(can)
        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return True
示例#2
0
文件: custom.py 项目: 0k/OpenUpgrade
    def _create_pie(self, cr, uid, ids, report, fields, results, context):
        pdf_string = cStringIO.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')
        ar = area.T(size=(350,350), legend=legend.T(),
                    x_grid_style = None, y_grid_style = None)
        colors = map(lambda x:fill_style.Plain(bgcolor=x), misc.choice_colors(len(results)))

        if reduce(lambda x,y : x+y, map(lambda x : x[1],results)) == 0.0:
            raise except_osv(_('Error'), _("The sum of the data (2nd field) is null.\nWe can't draw a pie chart !"))

        plot = pie_plot.T(data=results, arc_offsets=[0,10,0,10],
                          shadow = (2, -2, fill_style.gray50),
                          label_offset = 25,
                          arrow_style = arrow.a3,
                          fill_styles=colors)
        ar.add_plot(plot)
        ar.draw(can)
        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return True
示例#3
0
文件: custom.py 项目: mrmoyeez/XacCRM
    def _create_bars(self, cr, uid, ids, report, fields, results, context):
        service = netsvc.LocalService("object_proxy")
        pdf_string = cStringIO.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')

        can.show(80, 380, '/16/H' + report['title'])

        process_date = {}
        process_date['D'] = lambda x: reduce(lambda xx, yy: xx + '-' + yy,
                                             x.split('-')[1:3])
        process_date['M'] = lambda x: x.split('-')[1]
        process_date['Y'] = lambda x: x.split('-')[0]

        order_date = {}
        order_date['D'] = lambda x: time.mktime((2005, int(x.split('-')[
            0]), int(x.split('-')[1]), 0, 0, 0, 0, 0, 0))
        order_date['M'] = lambda x: x
        order_date['Y'] = lambda x: x

        ar = area.T(size=(350, 350),
                    x_axis=axis.X(label=fields[0]['name'], format="/a-30{}%s"),
                    y_axis=axis.Y(
                        label=', '.join(map(lambda x: x['name'], fields[1:]))))

        idx = 0
        date_idx = None
        fct = {}
        for f in fields:
            field_id = (f['field_child3'] and f['field_child3'][0]) or (
                f['field_child2'] and f['field_child2'][0]) or (
                    f['field_child1']
                    and f['field_child1'][0]) or (f['field_child0']
                                                  and f['field_child0'][0])
            if field_id:
                type = service.execute(cr.dbname, uid, 'ir.model.fields',
                                       'read', [field_id], ['ttype'])
                if type[0]['ttype'] == 'date':
                    date_idx = idx
                    fct[idx] = process_date[report['frequency']]
                else:
                    fct[idx] = lambda x: x
            else:
                fct[idx] = lambda x: x
            idx += 1

        # plot are usually displayed year by year
        # so we do so if the first field is a date
        data_by_year = {}
        if date_idx != None:
            for r in results:
                key = process_date['Y'](r[date_idx])
                if not data_by_year.has_key(key):
                    data_by_year[key] = []
                for i in range(len(r)):
                    r[i] = fct[i](r[i])
                data_by_year[key].append(r)
        else:
            data_by_year[''] = results

        nb_bar = len(data_by_year) * (len(fields) - 1)
        colors = map(lambda x: fill_style.Plain(bgcolor=x),
                     misc.choice_colors(nb_bar))

        abscissa = {}
        for line in data_by_year.keys():
            fields_bar = []
            # sum data and save it in a list. An item for a fields
            for d in data_by_year[line]:
                for idx in range(len(fields) - 1):
                    fields_bar.append({})
                    if fields_bar[idx].has_key(d[0]):
                        fields_bar[idx][d[0]] += d[idx + 1]
                    else:
                        fields_bar[idx][d[0]] = d[idx + 1]
            for idx in range(len(fields) - 1):
                data = {}
                for k in fields_bar[idx].keys():
                    if data.has_key(k):
                        data[k] += fields_bar[idx][k]
                    else:
                        data[k] = fields_bar[idx][k]
                data_cum = []
                prev = 0.0
                keys = data.keys()
                keys.sort()
                # cumulate if necessary
                for k in keys:
                    data_cum.append([k, float(data[k]) + float(prev)])
                    if fields[idx + 1]['cumulate']:
                        prev += data[k]

                idx0 = 0
                plot = bar_plot.T(
                    label=fields[idx + 1]['name'] + ' ' + str(line),
                    data=data_cum,
                    cluster=(idx0 * (len(fields) - 1) + idx, nb_bar),
                    fill_style=colors[idx0 * (len(fields) - 1) + idx])
                ar.add_plot(plot)
                abscissa.update(fields_bar[idx])
            idx0 += 1
        abscissa = map(lambda x: [x, None], abscissa)
        abscissa.sort()
        ar.x_coord = category_coord.T(abscissa, 0)
        ar.draw(can)

        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return True
示例#4
0
文件: custom.py 项目: 0k/OpenUpgrade
    def _create_bars(self, cr, uid, ids, report, fields, results, context):
        pool = openerp.registry(cr.dbname)
        pdf_string = cStringIO.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')
        
        can.show(80,380,'/16/H'+report['title'])
        
        process_date = {
            'D': lambda x: reduce(lambda xx, yy: xx + '-' + yy, x.split('-')[1:3]),
            'M': lambda x: x.split('-')[1],
            'Y': lambda x: x.split('-')[0]
        }

        order_date = {
            'D': lambda x: time.mktime((2005, int(x.split('-')[0]), int(x.split('-')[1]), 0, 0, 0, 0, 0, 0)),
            'M': lambda x: x,
            'Y': lambda x: x
        }

        ar = area.T(size=(350,350),
            x_axis = axis.X(label = fields[0]['name'], format="/a-30{}%s"),
            y_axis = axis.Y(label = ', '.join(map(lambda x : x['name'], fields[1:]))))

        idx = 0 
        date_idx = None
        fct = {}
        for f in fields:
            field_id = (f['field_child3'] and f['field_child3'][0]) or (f['field_child2'] and f['field_child2'][0]) or (f['field_child1'] and f['field_child1'][0]) or (f['field_child0'] and f['field_child0'][0])
            if field_id:
                type = pool['ir.model.fields'].read(cr, uid, [field_id],['ttype'])
                if type[0]['ttype'] == 'date':
                    date_idx = idx
                    fct[idx] = process_date[report['frequency']] 
                else:
                    fct[idx] = lambda x : x
            else:
                fct[idx] = lambda x : x
            idx+=1
        
        # plot are usually displayed year by year
        # so we do so if the first field is a date
        data_by_year = {}
        if date_idx is not None:
            for r in results:
                key = process_date['Y'](r[date_idx])
                if key not in data_by_year:
                    data_by_year[key] = []
                for i in range(len(r)):
                    r[i] = fct[i](r[i])
                data_by_year[key].append(r)
        else:
            data_by_year[''] = results


        nb_bar = len(data_by_year)*(len(fields)-1)
        colors = map(lambda x:fill_style.Plain(bgcolor=x), misc.choice_colors(nb_bar))
        
        abscissa = {}
        for line in data_by_year.keys():
            fields_bar = []
            # sum data and save it in a list. An item for a fields
            for d in data_by_year[line]:
                for idx in range(len(fields)-1):
                    fields_bar.append({})
                    if d[0] in fields_bar[idx]:
                        fields_bar[idx][d[0]] += d[idx+1]
                    else:
                        fields_bar[idx][d[0]] = d[idx+1]
            for idx  in range(len(fields)-1):
                data = {}
                for k in fields_bar[idx].keys():
                    if k in data:
                        data[k] += fields_bar[idx][k]
                    else:
                        data[k] = fields_bar[idx][k]
                data_cum = []
                prev = 0.0
                keys = data.keys()
                keys.sort()
                # cumulate if necessary
                for k in keys:
                    data_cum.append([k, float(data[k])+float(prev)])
                    if fields[idx+1]['cumulate']:
                        prev += data[k]
                        
                idx0 = 0
                plot = bar_plot.T(label=fields[idx+1]['name']+' '+str(line), data = data_cum, cluster=(idx0*(len(fields)-1)+idx,nb_bar), fill_style=colors[idx0*(len(fields)-1)+idx])
                ar.add_plot(plot)
                abscissa.update(fields_bar[idx])
            idx0 += 1
        abscissa = map(lambda x : [x, None], abscissa)
        abscissa.sort()
        ar.x_coord = category_coord.T(abscissa,0)
        ar.draw(can)

        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return True
示例#5
0
文件: custom.py 项目: 0k/odoo
    def _create_lines(self, cr, uid, ids, report, fields, results, context):
        pool = openerp.registry(cr.dbname)
        pdf_string = cStringIO.StringIO()
        can = canvas.init(fname=pdf_string, format="pdf")

        can.show(80, 380, "/16/H" + report["title"])

        ar = area.T(
            size=(350, 350),
            # x_coord = category_coord.T(['2005-09-01','2005-10-22'],0),
            x_axis=axis.X(label=fields[0]["name"], format="/a-30{}%s"),
            y_axis=axis.Y(label=", ".join(map(lambda x: x["name"], fields[1:]))),
        )

        process_date = {
            "D": lambda x: reduce(lambda xx, yy: xx + "-" + yy, x.split("-")[1:3]),
            "M": lambda x: x.split("-")[1],
            "Y": lambda x: x.split("-")[0],
        }

        order_date = {
            "D": lambda x: time.mktime((2005, int(x.split("-")[0]), int(x.split("-")[1]), 0, 0, 0, 0, 0, 0)),
            "M": lambda x: x,
            "Y": lambda x: x,
        }

        abscissa = []

        idx = 0
        date_idx = None
        fct = {}
        for f in fields:
            field_id = (
                (f["field_child3"] and f["field_child3"][0])
                or (f["field_child2"] and f["field_child2"][0])
                or (f["field_child1"] and f["field_child1"][0])
                or (f["field_child0"] and f["field_child0"][0])
            )
            if field_id:
                type = pool["ir.model.fields"].read(cr, uid, [field_id], ["ttype"])
                if type[0]["ttype"] == "date":
                    date_idx = idx
                    fct[idx] = process_date[report["frequency"]]
                else:
                    fct[idx] = lambda x: x
            else:
                fct[idx] = lambda x: x
            idx += 1

        # plots are usually displayed year by year
        # so we do so if the first field is a date
        data_by_year = {}
        if date_idx is not None:
            for r in results:
                key = process_date["Y"](r[date_idx])
                if key not in data_by_year:
                    data_by_year[key] = []
                for i in range(len(r)):
                    r[i] = fct[i](r[i])
                data_by_year[key].append(r)
        else:
            data_by_year[""] = results

        idx0 = 0
        nb_bar = len(data_by_year) * (len(fields) - 1)
        colors = map(lambda x: line_style.T(color=x), misc.choice_colors(nb_bar))
        abscissa = {}
        for line in data_by_year.keys():
            fields_bar = []
            # sum data and save it in a list. An item for a fields
            for d in data_by_year[line]:
                for idx in range(len(fields) - 1):
                    fields_bar.append({})
                    if d[0] in fields_bar[idx]:
                        fields_bar[idx][d[0]] += d[idx + 1]
                    else:
                        fields_bar[idx][d[0]] = d[idx + 1]
            for idx in range(len(fields) - 1):
                data = {}
                for k in fields_bar[idx].keys():
                    if k in data:
                        data[k] += fields_bar[idx][k]
                    else:
                        data[k] = fields_bar[idx][k]
                data_cum = []
                prev = 0.0
                keys = data.keys()
                keys.sort()
                # cumulate if necessary
                for k in keys:
                    data_cum.append([k, float(data[k]) + float(prev)])
                    if fields[idx + 1]["cumulate"]:
                        prev += data[k]
                idx0 = 0
                plot = line_plot.T(
                    label=fields[idx + 1]["name"] + " " + str(line),
                    data=data_cum,
                    line_style=colors[idx0 * (len(fields) - 1) + idx],
                )
                ar.add_plot(plot)
                abscissa.update(fields_bar[idx])
                idx0 += 1

        abscissa = map(lambda x: [x, None], abscissa)
        ar.x_coord = category_coord.T(abscissa, 0)
        ar.draw(can)

        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return True
示例#6
0
    def _create_lines(self, cr, uid, ids, report, fields, results, context):
        pool = yuancloud.registry(cr.dbname)
        pdf_string = cStringIO.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')
        
        can.show(80,380,'/16/H'+report['title'])
        
        ar = area.T(size=(350,350),
        #x_coord = category_coord.T(['2005-09-01','2005-10-22'],0),
        x_axis = axis.X(label = fields[0]['name'], format="/a-30{}%s"),
        y_axis = axis.Y(label = ', '.join(map(lambda x : x['name'], fields[1:]))))
        
        process_date = {
            'D': lambda x: reduce(lambda xx, yy: xx + '-' + yy, x.split('-')[1:3]),
            'M': lambda x: x.split('-')[1],
            'Y': lambda x: x.split('-')[0]
        }

        order_date = {
            'D': lambda x: time.mktime((2005, int(x.split('-')[0]), int(x.split('-')[1]), 0, 0, 0, 0, 0, 0)),
            'M': lambda x: x,
            'Y': lambda x: x
        }

        abscissa = []
        
        idx = 0 
        date_idx = None
        fct = {}
        for f in fields:
            field_id = (f['field_child3'] and f['field_child3'][0]) or (f['field_child2'] and f['field_child2'][0]) or (f['field_child1'] and f['field_child1'][0]) or (f['field_child0'] and f['field_child0'][0])
            if field_id:
                type = pool['ir.model.fields'].read(cr, uid, [field_id],['ttype'])
                if type[0]['ttype'] == 'date':
                    date_idx = idx
                    fct[idx] = process_date[report['frequency']] 
                else:
                    fct[idx] = lambda x : x
            else:
                fct[idx] = lambda x : x
            idx+=1

        # plots are usually displayed year by year
        # so we do so if the first field is a date
        data_by_year = {}
        if date_idx is not None:
            for r in results:
                key = process_date['Y'](r[date_idx])
                if key not in data_by_year:
                    data_by_year[key] = []
                for i in range(len(r)):
                    r[i] = fct[i](r[i])
                data_by_year[key].append(r)
        else:
            data_by_year[''] = results

        idx0 = 0
        nb_bar = len(data_by_year)*(len(fields)-1)
        colors = map(lambda x:line_style.T(color=x), misc.choice_colors(nb_bar))
        abscissa = {}
        for line in data_by_year.keys():
            fields_bar = []
            # sum data and save it in a list. An item for a fields
            for d in data_by_year[line]:
                for idx in range(len(fields)-1):
                    fields_bar.append({})
                    if d[0] in fields_bar[idx]:
                        fields_bar[idx][d[0]] += d[idx+1]
                    else:
                        fields_bar[idx][d[0]] = d[idx+1]
            for idx  in range(len(fields)-1):
                data = {}
                for k in fields_bar[idx].keys():
                    if k in data:
                        data[k] += fields_bar[idx][k]
                    else:
                        data[k] = fields_bar[idx][k]
                data_cum = []
                prev = 0.0
                keys = data.keys()
                keys.sort()
                # cumulate if necessary
                for k in keys:
                    data_cum.append([k, float(data[k])+float(prev)])
                    if fields[idx+1]['cumulate']:
                        prev += data[k]
                idx0 = 0
                plot = line_plot.T(label=fields[idx+1]['name']+' '+str(line), data = data_cum, line_style=colors[idx0*(len(fields)-1)+idx])
                ar.add_plot(plot)
                abscissa.update(fields_bar[idx])
                idx0 += 1
        
        abscissa = map(lambda x : [x, None], abscissa)
        ar.x_coord = category_coord.T(abscissa,0)
        ar.draw(can)

        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return True
示例#7
0
文件: custom.py 项目: Buyanbat/XacCRM
    def _create_lines(self, cr, uid, ids, report, fields, results, context):
        service = netsvc.LocalService("object_proxy")
        pdf_string = cStringIO.StringIO()
        can = canvas.init(fname=pdf_string, format='pdf')
        
        can.show(80,380,'/16/H'+report['title'])
        
        ar = area.T(size=(350,350),
        #x_coord = category_coord.T(['2005-09-01','2005-10-22'],0),
        x_axis = axis.X(label = fields[0]['name'], format="/a-30{}%s"),
        y_axis = axis.Y(label = ', '.join(map(lambda x : x['name'], fields[1:]))))
        
        process_date = {}
        process_date['D'] = lambda x : reduce(lambda xx,yy : xx+'-'+yy,x.split('-')[1:3])
        process_date['M'] = lambda x : x.split('-')[1]
        process_date['Y'] = lambda x : x.split('-')[0]

        order_date = {}
        order_date['D'] = lambda x : time.mktime((2005,int(x.split('-')[0]), int(x.split('-')[1]),0,0,0,0,0,0))
        order_date['M'] = lambda x : x
        order_date['Y'] = lambda x : x

        abscissa = []
        tmp = {}
        
        idx = 0 
        date_idx = None
        fct = {}
        for f in fields:
            field_id = (f['field_child3'] and f['field_child3'][0]) or (f['field_child2'] and f['field_child2'][0]) or (f['field_child1'] and f['field_child1'][0]) or (f['field_child0'] and f['field_child0'][0])
            if field_id:
                type = service.execute(cr.dbname, uid, 'ir.model.fields', 'read', [field_id],['ttype'])
                if type[0]['ttype'] == 'date':
                    date_idx = idx
                    fct[idx] = process_date[report['frequency']] 
                else:
                    fct[idx] = lambda x : x
            else:
                fct[idx] = lambda x : x
            idx+=1

        # plots are usually displayed year by year
        # so we do so if the first field is a date
        data_by_year = {}
        if date_idx != None:
            for r in results:
                key = process_date['Y'](r[date_idx])
                if not data_by_year.has_key(key):
                    data_by_year[key] = []
                for i in range(len(r)):
                    r[i] = fct[i](r[i])
                data_by_year[key].append(r)
        else:
            data_by_year[''] = results

        idx0 = 0
        nb_bar = len(data_by_year)*(len(fields)-1)
        colors = map(lambda x:line_style.T(color=x), misc.choice_colors(nb_bar))
        abscissa = {}
        for line in data_by_year.keys():
            fields_bar = []
            # sum data and save it in a list. An item for a fields
            for d in data_by_year[line]:
                for idx in range(len(fields)-1):
                    fields_bar.append({})
                    if fields_bar[idx].has_key(d[0]):
                        fields_bar[idx][d[0]] += d[idx+1]
                    else:
                        fields_bar[idx][d[0]] = d[idx+1]
            for idx  in range(len(fields)-1):
                data = {}
                for k in fields_bar[idx].keys():
                    if data.has_key(k):
                        data[k] += fields_bar[idx][k]
                    else:
                        data[k] = fields_bar[idx][k]
                data_cum = []
                prev = 0.0
                keys = data.keys()
                keys.sort()
                # cumulate if necessary
                for k in keys:
                    data_cum.append([k, float(data[k])+float(prev)])
                    if fields[idx+1]['cumulate']:
                        prev += data[k]
                idx0 = 0
                plot = line_plot.T(label=fields[idx+1]['name']+' '+str(line), data = data_cum, line_style=colors[idx0*(len(fields)-1)+idx])
                ar.add_plot(plot)
                abscissa.update(fields_bar[idx])
                idx0 += 1
        
        abscissa = map(lambda x : [x, None], abscissa)
        ar.x_coord = category_coord.T(abscissa,0)
        ar.draw(can)

        can.close()
        self.obj = external_pdf(pdf_string.getvalue())
        self.obj.render()
        pdf_string.close()
        return True