def update_children(self): ids = self.sel_ids_get() for c in self.children: value = 0.0 cal_model = self.screen.models.models if not cal_model: cal_model = self.store.models.lst length = len(cal_model) if ids: length = len(ids) for model in cal_model: if model.id in ids or model in ids or not ids: if isinstance(model, group_record): value += float(model[self.children[c][0]].get() or 0.0) else: value += float(model.fields_get()[self.children[c][0]].get(model, check_load=False) or 0.0) if self.children[c][5] == 'avg' and length: value = value/length if self.children[c][6] == 'float_time': label_str = float_time_convert(value) else: label_str = user_locale_format.format('%.' + str(self.children[c][3]) + 'f', value) if self.children[c][4]: self.children[c][2].set_markup('<b>%s</b>' % label_str) else: self.children[c][2].set_markup(label_str)
def display(self, model, model_field): if not model_field: self.widget.set_text('00:00') return False super(float_time, self).display(model, model_field) val = model_field.get(model) t= datetime_util.float_time_convert(val) if val<0: t = '-'+t self.widget.set_text(t)
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
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