Exemplo n.º 1
0
    def display(self, models):
        datas = []
        self.axis = copy.copy(self.old_axis)
        group_by = self.widget.screen.context.get('group_by', False)
        if group_by:
            if not self.key:
                del self.widget.screen.context['group_by']
                self.key = True 
                self.widget.screen.search_filter() ## TODO: Check why was this needed ?
                models = self.widget.screen.models
                self.widget.screen.context['group_by'] = group_by
                self.key = False 
            self.axis[0] = group_by[0]
            self.axis_data[group_by[0]] = {}
            # This is to get the missing field. if the field is not available in the graph view
            # for use case :graph view loaded directly from a dashboard and user executes groupby
            if self.axis[0] not in models.mfields:
                missing_gb_field = rpc.session.rpc_exec_auth('/object', 'execute', self.model, 'fields_get', [self.axis[0]], {})
                if missing_gb_field:
                    models.add_fields(missing_gb_field, models)

        for m in models:
            res = {}
            for x in self.axis_data.keys():
                if not self.axis_data[x]:
                    self.axis_data[x] = self.fields[x]
                field_val = m[x].get_client(m)
                if self.fields[x]['type'] in ('many2one', 'char','time','text'):
                    res[x] = field_val and str(field_val) or _('Undefined')
                elif self.fields[x]['type'] == 'selection':
                    selection = dict(m[x].attrs['selection'])
                    if field_val:
                        val = str(field_val)
                        res[x] = selection.get(val, val)
                    else:
                        res[x] = _('Undefined')
                elif self.fields[x]['type'] == 'date':
                    if field_val:
                        res[x] = datetime_util.server_to_local_timestamp(field_val,
                                    DT_FORMAT, user_locale_format.get_date_format(), tz_offset=False)
                    else:
                        res[x] = _('Undefined')
                elif self.fields[x]['type'] == 'datetime':
                    if field_val:
                        res[x] = datetime_util.server_to_local_timestamp(field_val,
                                    DHM_FORMAT, user_locale_format.get_datetime_format(True))
                    else:
                        res[x] = _('Undefined')
                else:
                    res[x] = field_val and float(field_val) or 0.0
            datas.append(res)
        tinygraph.tinygraph(self._subplot, self.attrs.get('type', 'pie'), self.axis, self.axis_data, datas, axis_group_field=self.axis_group, orientation=self.attrs.get('orientation', 'vertical'))
        # the draw function may generate exception but it is not a problem as it will be redraw latter
        try:
            self._subplot.draw(None)
            #XXX it must have some better way to force the redraw but this one works
            self._canvas.queue_resize()
        except:
            pass
Exemplo n.º 2
0
 def _read(self, ids, fields):
     c = {}
     c.update(rpc.session.context)
     c.update(self.context)
     if self.invisible_fields:
         fields += self.invisible_fields
     try:
         res_ids = rpc.session.rpc_exec_auth_try("/object", "execute", self.view["model"], "read", ids, fields, c)
     except:
         res_ids = []
         for id in ids:
             val = {"id": id}
             for f in fields:
                 if self.fields_type[f]["type"] in ("one2many", "many2many"):
                     val[f] = []
                 else:
                     val[f] = ""
             res_ids.append(val)
     for field in self.fields + self.invisible_fields:
         for x in res_ids:
             if self.fields_type[field]["type"] in ("date",):
                 display_format = user_locale_format.get_date_format()
                 if x[field]:
                     x[field] = datetime_util.server_to_local_timestamp(
                         x[field], DT_FORMAT, display_format, tz_offset=False
                     )
                 else:
                     x[field] = str(x[field])
             elif self.fields_type[field]["type"] in ("datetime",):
                 display_format = user_locale_format.get_datetime_format(True)
                 if x[field]:
                     x[field] = datetime_util.server_to_local_timestamp(x[field], DHM_FORMAT, display_format)
                 else:
                     x[field] = str(x[field])
             elif self.fields_type[field]["type"] in ("one2one", "many2one"):
                 if x[field]:
                     x[field] = x[field][1]
             elif self.fields_type[field]["type"] in ("selection"):
                 if x[field]:
                     x[field] = dict(self.fields_type[field]["selection"]).get(x[field], "")
             elif self.fields_type[field]["type"] in ("float",):
                 interger, digit = self.fields_type[field].get("digits", (16, 2))
                 x[field] = user_locale_format.format("%." + str(digit) + "f", x[field] or 0.0)
             elif self.fields_type[field]["type"] in ("integer",):
                 x[field] = int(user_locale_format.format("%d", int(x[field]) or 0))
             elif self.fields_type[field]["type"] in ("float_time",):
                 val = datetime_util.float_time_convert(x[field])
                 if x[field] < 0:
                     val = "-" + val
                 x[field] = val
     return res_ids
Exemplo n.º 3
0
    def display(self, models):
        datas = []
        self.axis = copy.copy(self.old_axis)
        group_by = self.widget.screen.context.get("group_by", False)
        if group_by:
            if not self.key:
                del self.widget.screen.context["group_by"]
                self.key = True
                self.widget.screen.search_filter()
                models = self.widget.screen.models
                self.widget.screen.context["group_by"] = group_by
            self.axis[0] = group_by[0]
            self.axis_data[group_by[0]] = {}
            # This is to get the missing field. if the field is not available in the graph view
            # for use case :graph view loaded directly from a dashboard and user executes groupby
            if self.axis[0] not in models.mfields:
                missing_gb_field = rpc.session.rpc_exec_auth(
                    "/object", "execute", self.model, "fields_get", [self.axis[0]], {}
                )
                if missing_gb_field:
                    models.add_fields(missing_gb_field, models)

        for m in models:
            res = {}
            for x in self.axis_data.keys():
                if not self.axis_data[x]:
                    self.axis_data[x] = self.fields[x]
                field_val = m[x].get_client(m)
                if self.fields[x]["type"] in ("many2one", "char", "time", "text"):
                    res[x] = field_val and str(field_val) or "Undefined"
                elif self.fields[x]["type"] == "selection":
                    selection = dict(m[x].attrs["selection"])
                    if field_val:
                        val = str(field_val)
                        res[x] = selection.get(val, val)
                    else:
                        res[x] = "Undefined"
                elif self.fields[x]["type"] == "date":
                    if field_val:
                        res[x] = datetime_util.server_to_local_timestamp(
                            field_val, DT_FORMAT, user_locale_format.get_date_format(), tz_offset=False
                        )
                    else:
                        res[x] = "Undefined"
                elif self.fields[x]["type"] == "datetime":
                    if field_val:
                        res[x] = datetime_util.server_to_local_timestamp(
                            field_val, DHM_FORMAT, user_locale_format.get_datetime_format(True)
                        )
                    else:
                        res[x] = "Undefined"
                else:
                    res[x] = field_val and float(field_val) or 0.0
            datas.append(res)
        tinygraph.tinygraph(
            self._subplot,
            self.attrs.get("type", "pie"),
            self.axis,
            self.axis_data,
            datas,
            axis_group_field=self.axis_group,
            orientation=self.attrs.get("orientation", "vertical"),
        )
        # the draw function may generate exception but it is not a problem as it will be redraw latter
        try:
            self._subplot.draw(None)
            # XXX it must have some better way to force the redraw but this one works
            self._canvas.queue_resize()
        except:
            pass
Exemplo n.º 4
0
 def _read(self, ids, fields):
     c = {}
     c.update(rpc.session.context)
     c.update(self.context)
     if self.invisible_fields:
         fields += self.invisible_fields
     try:
         res_ids = rpc.session.rpc_exec_auth_try('/object', 'execute',
                                                 self.view['model'], 'read',
                                                 ids, fields, c)
     except:
         res_ids = []
         for id in ids:
             val = {'id': id}
             for f in fields:
                 if self.fields_type[f]['type'] in ('one2many',
                                                    'many2many'):
                     val[f] = []
                 else:
                     val[f] = ''
             res_ids.append(val)
     for field in self.fields + self.invisible_fields:
         for x in res_ids:
             if self.fields_type[field]['type'] in ('date', ):
                 display_format = user_locale_format.get_date_format()
                 if x[field]:
                     x[field] = datetime_util.server_to_local_timestamp(
                         x[field],
                         DT_FORMAT,
                         display_format,
                         tz_offset=False)
                 else:
                     x[field] = str(x[field])
             elif self.fields_type[field]['type'] in ('datetime', ):
                 display_format = user_locale_format.get_datetime_format(
                     True)
                 if x[field]:
                     x[field] = datetime_util.server_to_local_timestamp(
                         x[field], DHM_FORMAT, display_format)
                 else:
                     x[field] = str(x[field])
             elif self.fields_type[field]['type'] in ('one2one',
                                                      'many2one'):
                 if x[field]:
                     x[field] = x[field][1]
             elif self.fields_type[field]['type'] in ('selection'):
                 if x[field]:
                     x[field] = dict(
                         self.fields_type[field]['selection']).get(
                             x[field], '')
             elif self.fields_type[field]['type'] in ('float', ):
                 interger, digit = self.fields_type[field].get(
                     'digits', (16, 2))
                 x[field] = user_locale_format.format(
                     '%.' + str(digit) + 'f', x[field] or 0.0)
             elif self.fields_type[field]['type'] in ('integer', ):
                 x[field] = int(
                     user_locale_format.format('%d',
                                               int(x[field]) or 0))
             elif self.fields_type[field]['type'] in ('float_time', ):
                 val = datetime_util.float_time_convert(x[field])
                 if x[field] < 0:
                     val = '-' + val
                 x[field] = val
     return res_ids
Exemplo n.º 5
0
    def display(self, models):
        datas = []
        self.axis = copy.copy(self.old_axis)
        group_by = self.widget.screen.context.get('group_by', False)
        if group_by:
            if not self.key:
                del self.widget.screen.context['group_by']
                self.key = True
                self.widget.screen.search_filter()
                models = self.widget.screen.models
                self.widget.screen.context['group_by'] = group_by
            self.axis[0] = group_by[0]
            self.axis_data[group_by[0]] = {}
            # This is to get the missing field. if the field is not available in the graph view
            # for use case :graph view loaded directly from a dashboard and user executes groupby
            if self.axis[0] not in models.mfields:
                missing_gb_field = rpc.session.rpc_exec_auth(
                    '/object', 'execute', self.model, 'fields_get',
                    [self.axis[0]], {})
                if missing_gb_field:
                    models.add_fields(missing_gb_field, models)

        for m in models:
            res = {}
            for x in self.axis_data.keys():
                if not self.axis_data[x]:
                    self.axis_data[x] = self.fields[x]
                field_val = m[x].get_client(m)
                if self.fields[x]['type'] in ('many2one', 'char', 'time',
                                              'text'):
                    res[x] = field_val and str(field_val) or 'Undefined'
                elif self.fields[x]['type'] == 'selection':
                    selection = dict(m[x].attrs['selection'])
                    if field_val:
                        val = str(field_val)
                        res[x] = selection.get(val, val)
                    else:
                        res[x] = 'Undefined'
                elif self.fields[x]['type'] == 'date':
                    if field_val:
                        res[x] = datetime_util.server_to_local_timestamp(
                            field_val,
                            DT_FORMAT,
                            user_locale_format.get_date_format(),
                            tz_offset=False)
                    else:
                        res[x] = 'Undefined'
                elif self.fields[x]['type'] == 'datetime':
                    if field_val:
                        res[x] = datetime_util.server_to_local_timestamp(
                            field_val, DHM_FORMAT,
                            user_locale_format.get_datetime_format(True))
                    else:
                        res[x] = 'Undefined'
                else:
                    res[x] = field_val and float(field_val) or 0.0
            datas.append(res)
        tinygraph.tinygraph(self._subplot,
                            self.attrs.get('type', 'pie'),
                            self.axis,
                            self.axis_data,
                            datas,
                            axis_group_field=self.axis_group,
                            orientation=self.attrs.get('orientation',
                                                       'vertical'))
        # the draw function may generate exception but it is not a problem as it will be redraw latter
        try:
            self._subplot.draw(None)
            #XXX it must have some better way to force the redraw but this one works
            self._canvas.queue_resize()
        except:
            pass