Exemplo n.º 1
0
 def update_children(self):
     ids = self.sel_ids_get()
     for c in self.children:
         to_operate = []
         operation = self.children[c][5]
         for model in self.screen.models.models:
             if model.id in ids or not ids:
                 value = model.fields_get()[self.children[c][0]].get(
                     model, check_load=False
                 )
                 to_operate.append(value)
         if operation == 'sum':
             value = sum(to_operate)
         elif operation == 'avg':
             if len(to_operate):
                 value = sum(to_operate) / len(to_operate)
             else:
                 value = 0.0
         elif operation == 'count':
             value = len(to_operate)
         label_str = tools.locale_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)
Exemplo n.º 2
0
 def update_children(self):
     ids = self.sel_ids_get()
     for c in self.children:
         to_operate = []
         operation = self.children[c][5]
         for model in self.screen.models.models:
             if model.id in ids or not ids:
                 value = model.fields_get()[self.children[c][0]].get(
                     model, check_load=False
                 )
                 to_operate.append(value)
         if operation == 'sum':
             value = sum(to_operate)
         elif operation == 'avg':
             if len(to_operate):
                 value = sum(to_operate) / len(to_operate)
             else:
                 value = 0.0
         elif operation == 'count':
             value = len(to_operate)
         label_str = tools.locale_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)
Exemplo n.º 3
0
 def get_textual_value(self, model):
     interger, digit = self.attrs.get('digits', (16, 2))
     return tools.locale_format(
         '%.' + str(digit) + 'f', model[self.field_name].get_client(model)
         or 0.0)
Exemplo n.º 4
0
 def get_textual_value(self, model):
     return tools.locale_format(
         '%d', model[self.field_name].get_client(model) or 0)
Exemplo n.º 5
0
 def get_textual_value(self, model):
     interger, digit = self.attrs.get('digits', (16,2) )
     return tools.locale_format('%.' + str(digit) + 'f', model[self.field_name].get_client(model) or 0.0)
Exemplo n.º 6
0
 def get_textual_value(self, model):
     return tools.locale_format('%d', model[self.field_name].get_client(model) or 0)
Exemplo n.º 7
0
    def _read(self, ids, fields):
        c = {}
        c.update(rpc.session.context)
        c.update(self.context)
        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:
            if self.fields_type[field]['type'] in ('date',):
                display_format = LDFMT
                for x in res_ids:
                    if x[field]:
                        date = time.strptime(x[field], DT_FORMAT)
                        x[field] = time.strftime(display_format, date)
            if self.fields_type[field]['type'] in ('datetime',):
                display_format = LDFMT + ' %H:%M:%S'
                for x in res_ids:
                    if x[field]:
                        date = time.strptime(x[field], DHM_FORMAT)
                        if rpc.session.context.get('tz'):
                            try:
                                lzone = pytz.timezone(rpc.session.context['tz'])
                                szone = pytz.timezone(rpc.session.timezone)
                                dt = DT.datetime(date[0], date[1], date[2],
                                        date[3], date[4], date[5], date[6])
                                sdt = szone.localize(dt, is_dst=True)
                                ldt = sdt.astimezone(lzone)
                                date = ldt.timetuple()
                            except pytz.UnknownTimeZoneError:
                                # Timezones are sometimes invalid under Windows
                                # and hard to figure out, so as a low-risk fix
                                # in stable branch we will simply ignore the
                                # exception and consider client in server TZ
                                # (and sorry about the code duplication as well,
                                # this is fixed properly in trunk)
                                pass
                        x[field] = time.strftime(display_format, date)

            if self.fields_type[field]['type'] in ('one2one','many2one'):
                for x in res_ids:
                    if x[field]:
                        x[field] = x[field][1]

            if self.fields_type[field]['type'] in ('selection'):
                for x in res_ids:
                    if x[field]:
                        x[field] = dict(self.fields_type[field]['selection']
                                ).get(x[field],'')
            if self.fields_type[field]['type'] in ('float',):
                interger, digit = self.fields_type[field].get('digits', (16,2))
                for x in res_ids:
                    x[field] = tools.locale_format('%.' + str(digit) + 'f', x[field] or 0.0)
            if self.fields_type[field]['type'] in ('float_time',):
                for x in res_ids:
                    hours = math.floor(abs(x[field]))
                    mins = round(abs(x[field]) % 1 + 0.01, 2)
                    if mins >= 1.0:
                        hours = hours + 1
                        mins = 0.0
                    else:
                        mins = mins * 60
                    val = '%02d:%02d' % (hours,mins)
                    if x[field] < 0:
                        val = '-' + val
                    x[field] = val
        return res_ids
Exemplo n.º 8
0
    def _read(self, ids, fields):
        c = {}
        c.update(rpc.session.context)
        c.update(self.context)
        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:
            if self.fields_type[field]['type'] in ('date', ):
                display_format = LDFMT
                for x in res_ids:
                    if x[field]:
                        date = time.strptime(x[field], DT_FORMAT)
                        x[field] = time.strftime(display_format, date)
            if self.fields_type[field]['type'] in ('datetime', ):
                display_format = LDFMT + ' %H:%M:%S'
                for x in res_ids:
                    if x[field]:
                        date = time.strptime(x[field], DHM_FORMAT)
                        if rpc.session.context.get('tz'):
                            try:
                                lzone = pytz.timezone(
                                    rpc.session.context['tz'])
                                szone = pytz.timezone(rpc.session.timezone)
                                dt = DT.datetime(date[0], date[1], date[2],
                                                 date[3], date[4], date[5],
                                                 date[6])
                                sdt = szone.localize(dt, is_dst=True)
                                ldt = sdt.astimezone(lzone)
                                date = ldt.timetuple()
                            except pytz.UnknownTimeZoneError:
                                # Timezones are sometimes invalid under Windows
                                # and hard to figure out, so as a low-risk fix
                                # in stable branch we will simply ignore the
                                # exception and consider client in server TZ
                                # (and sorry about the code duplication as well,
                                # this is fixed properly in trunk)
                                pass
                        x[field] = time.strftime(display_format, date)

            if self.fields_type[field]['type'] in ('one2one', 'many2one'):
                for x in res_ids:
                    if x[field]:
                        x[field] = x[field][1]

            if self.fields_type[field]['type'] in ('selection'):
                for x in res_ids:
                    if x[field]:
                        x[field] = dict(
                            self.fields_type[field]['selection']).get(
                                x[field], '')
            if self.fields_type[field]['type'] in ('float', ):
                interger, digit = self.fields_type[field].get(
                    'digits', (16, 2))
                for x in res_ids:
                    x[field] = tools.locale_format('%.' + str(digit) + 'f',
                                                   x[field] or 0.0)
            if self.fields_type[field]['type'] in ('float_time', ):
                for x in res_ids:
                    hours = math.floor(abs(x[field]))
                    mins = round(abs(x[field]) % 1 + 0.01, 2)
                    if mins >= 1.0:
                        hours = hours + 1
                        mins = 0.0
                    else:
                        mins = mins * 60
                    val = '%02d:%02d' % (hours, mins)
                    if x[field] < 0:
                        val = '-' + val
                    x[field] = val
        return res_ids