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 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 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 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 get_textual_value(self, model): count = False if isinstance(model, group_record): val = int(model.value.get(self.field_name, 0)) count = model.value.get('%s_count' % self.field_name, '') else: val = int(model[self.field_name].get_client(model) or 0) converted_val = user_locale_format.format('%d', val) if count: converted_val = str(converted_val) + ' (' + str(count) + ')' return converted_val
def get_textual_value(self, model): count = False if isinstance(model, group_record): val = int(model.value.get(self.field_name, 0)) count = model.value.get('%s_count' % self.field_name, '') else: val = int(model[self.field_name].get_client(model) or 0) converted_val = user_locale_format.format('%d', val) if count: converted_val = str(converted_val) + ' (' + str(count) + ')' return converted_val
def get_textual_value(self, model): interger, digit = self.attrs.get('digits', (16,2) ) count = False if isinstance(model, group_record): val = model.value.get(self.field_name, 0.0) count = model.value.get('%s_count' % self.field_name,'') else: val = model[self.field_name].get_client(model) or 0.0 converted_val = user_locale_format.format('%.' + str(digit) + 'f', val) if count: converted_val = str(converted_val) + ' (' + str(count) + ')' return converted_val
def get_textual_value(self, model): interger, digit = self.attrs.get("digits", (16, 2)) count = False if isinstance(model, group_record): val = model.value.get(self.field_name, 0.0) count = model.value.get("%s_count" % self.field_name, "") else: val = model[self.field_name].get_client(model) or 0.0 converted_val = user_locale_format.format("%." + str(digit) + "f", val) if count: converted_val = str(converted_val) + " (" + str(count) + ")" return converted_val
def get_textual_value(self, model): interger, digit = self.attrs.get('digits', (16, 2)) count = False if isinstance(model, group_record): val = model.value.get(self.field_name, 0.0) count = model.value.get('%s_count' % self.field_name, '') else: val = model[self.field_name].get_client(model) or 0.0 converted_val = user_locale_format.format('%.' + str(digit) + 'f', val) if count: converted_val = str(converted_val) + ' (' + str(count) + ')' return converted_val
def _on_insert_text(self, editable, value, length, position): text = self.widget.get_text() if value: current_pos = self.widget.get_position() new_text = text[:current_pos] + value + text[current_pos:] digits = self.widget.get_digits() try: spin_value = user_locale_format.str2float(new_text) new_spin_value = user_locale_format.format("%." + str(digits) + "f", spin_value) except: self.widget.set_text(text) self.widget.stop_emission("insert-text") self.widget.show() return
def _on_insert_text(self, editable, value, length, position): text = self.widget.get_text() if value: current_pos = self.widget.get_position() new_text = text[:current_pos] + value + text[current_pos:] digits = self.widget.get_digits() try: spin_value = user_locale_format.str2float(new_text) new_spin_value = user_locale_format.format( '%.' + str(digits) + 'f', spin_value) except: self.widget.set_text(text) self.widget.stop_emission('insert-text') self.widget.show() return
def _on_insert_text(self, editable, value, length, position): text = self.widget.get_text() if value: current_pos = self.widget.get_position() new_text = text[:current_pos] + value + text[current_pos:] digits = self.widget.get_digits() try: spin_value = user_locale_format.str2float(new_text) new_spin_value = user_locale_format.format('%.' + str(digits) + 'f', spin_value) except: self.widget.set_text(text) #allow entering -ve sign if new_text != '-': self.widget.stop_emission('insert-text') self.widget.show() return
def format_output(self, spin): digits = spin.get_digits() value = spin.get_value() text = user_locale_format.format('%.' + str(digits) + 'f', value) spin.set_text(text) return True
def format_output(self, spin): digits = spin.get_digits() value = spin.get_value() text = user_locale_format.format('%.' + str(digits) + 'f', value) spin.set_text(text) return True
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