def parse_groups(group_by, grp_records, headers, ids, model,  offset, limit, context, data, total_fields, fields):
    proxy = rpc.RPCProxy(model)
    grouped = []
    grp_ids = []
    for grp in grp_records:
        inner = {}
        for key, head in headers:
            if not isinstance(head, int):
                kind = head.get('type')
                if kind == 'progressbar':
                    inner[key] = CELLTYPES[kind](value=grp.get(key), **head)
        grouped.append(inner)

    child = len(group_by) == 1
    digits = (16,2)
    if fields:
        for key, val in fields.items():
            if val.get('digits'):
                digits = val['digits']
    if isinstance(digits, basestring):
            digits = eval(digits)
    integer, digit = digits

    if grp_records and total_fields and group_by:
        for sum_key, sum_val in total_fields.items():
            if grp_records[0].has_key(sum_key):
                value = sum(map(lambda x: x[sum_key], grp_records))
                if isinstance(value, float):
                    total_fields[sum_key][1] = format.format_decimal(value or 0.0, digit)
                else:
                    total_fields[sum_key][1] = value
    if grp_records:
        for rec in grp_records:
            for key, val in rec.items():
                if isinstance(val, float):
                    rec[key] = format.format_decimal(val or 0.0, digit)

            for grp_by in group_by:
                if fields.get(grp_by).get('type') == 'boolean' and grp_by in rec and rec.get(grp_by) == False:
                    rec[grp_by] = 'False'
                elif not rec.get(grp_by):
                    rec[grp_by] = ''

            ch_ids = []
            if child:
                rec_dom =  rec.get('__domain')
                dom = [('id', 'in', ids), rec_dom[0]]
                ch_ids = [d for id in proxy.search(dom, offset, limit, 0, context)
                            for  d in data
                            if int(str(d.get('id'))) == id] # Need to convert in String and then Int.
            rec['child_rec'] = ch_ids
            rec['groups_id'] = 'group_' + str(random.randrange(1, 10000))
            if group_by:
                rec['group_by_id'] = group_by[0]+'_'+str(grp_records.index(rec))

    return grouped, grp_ids
Exemple #2
0
    def get_text(self):
        digits = self.attrs.get('digits', (16,2))
        if isinstance(digits, basestring):
            digits = eval(digits)

        integer, digit = digits
        return format.format_decimal(self.value or 0.0, digit)
Exemple #3
0
    def get_text(self):
        digits = self.attrs.get('digits', (16, 2))
        if isinstance(digits, basestring):
            digits = eval(digits)

        integer, digit = digits
        return format.format_decimal(self.value or 0.0, digit)
Exemple #4
0
    def get_text(self):
        digits = self.attrs.get('digits', (16,2))
        if isinstance(digits, basestring):
            digits = eval(digits)
            
        # custom fields - decimal_precision computation
        computation = self.attrs.get('computation', False)
        if isinstance(computation, basestring):
            computation = eval(computation)

        integer, digit = digits
        return format.format_decimal(self.value or 0.0, digit, computation=computation)
Exemple #5
0
    def do_sum(self, data, field):
        sum = 0.0

        for d in data:
            value = d[field].value
            sum += value

        attrs = {}
        if data:
            d = data[0]
            attrs = d[field].attrs

        digits = attrs.get('digits', (16,2))
        if isinstance(digits, basestring):
            digits = eval(digits)

        integer, digit = digits
        return format.format_decimal(sum or 0.0, digit)
Exemple #6
0
    def do_sum(self, data, field):
        sum = 0.0

        for d in data:
            value = d[field].value
            sum += value

        attrs = {}
        if data:
            d = data[0]
            attrs = d[field].attrs

        digits = attrs.get('digits', (16, 2))
        if isinstance(digits, basestring):
            digits = eval(digits)

        integer, digit = digits
        return format.format_decimal(sum or 0.0, digit)
Exemple #7
0
    def do_sum(self, data, field):
        sum = 0.0

        for d in data:
            value = d[field].value
            sum += value

        attrs = {}
        if data:
            d = data[0]
            attrs = d[field].attrs

        digits = attrs.get('digits', (16,2))
        if isinstance(digits, basestring):
            digits = eval(digits)
        
        # custom fields - decimal_precision computation
        computation = attrs.get('computation', False)
        if isinstance(computation, basestring):
            computation = eval(computation)

        integer, digit = digits
        return format.format_decimal(sum or 0.0, digit, computation=computation)
Exemple #8
0
 def _from_python(self, value, state):
     return format.format_decimal(float(value) or 0.0, self.digit)
 def _from_python(self, value, state):
     return format.format_decimal(float(value) or 0.0, self.digit)