~zaber/openobject-server/main

« back to all changes in this revision

Viewing changes to bin/osv/orm.py

  • Committer: Don Kirkby
  • Date: 2012-02-24 01:10:37 UTC
  • mfrom: (1970.17.24 server)
  • Revision ID: donkirkby+launpd@gmail.com-20120224011037-396gper7msz5w1hr
[MERGE] release 5.0.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
483
483
           
484
484
        lines = []
485
485
        data = map(lambda x: '', range(len(fields)))
 
486
        done = []
486
487
        for fpos in range(len(fields)):
487
 
            done = []
488
488
            f = fields[fpos]            
489
489
            if f:
490
490
                r = row
529
529
                        fields2 = map(lambda x: (x[:i+1]==f[:i+1] and x[i+1:]) \
530
530
                                or [], fields)
531
531
                        if fields2 in done:
532
 
                            break
 
532
                            if [x for x in fields2 if x]:
 
533
                                break
533
534
                        done.append(fields2)                        
534
535
                        for row2 in r:
535
536
                            lines2 = self.__export_row(cr, uid, row2, fields2,
1102
1103
                    trans = self.pool.get('ir.translation')._get_source(cr, user, context['base_model_name'], 'view', context['lang'], node.get('string'))
1103
1104
                if trans:
1104
1105
                    node.set('string', trans)
 
1106
            if node.get('confirm'):
 
1107
                trans = self.pool.get('ir.translation')._get_source(cr, user, self._name, 'view', context['lang'], node.get('confirm'))
 
1108
                if trans:
 
1109
                    node.set('confirm', trans)
1105
1110
            if node.get('sum'):
1106
1111
                trans = self.pool.get('ir.translation')._get_source(cr, user, self._name, 'view', context['lang'], node.get('sum'))
1107
1112
                if trans:
1258
1263
                                node.addprevious(child)
1259
1264
                            node.getparent().remove(node)
1260
1265
                    else:
1261
 
                        sib = node.getnext()
1262
1266
                        for child in node2:
1263
1267
                            if pos == 'inside':
1264
1268
                                node.append(child)
1265
1269
                            elif pos == 'after':
1266
 
                                if sib is None:
1267
 
                                    node.addnext(child)
1268
 
                                else:
1269
 
                                    sib.addprevious(child)
 
1270
                                node.addnext(child)
 
1271
                                node = child
1270
1272
                            elif pos == 'before':
1271
1273
                                node.addprevious(child)
1272
1274
                            else:
1513
1515
            fields_to_read = self._columns.keys()
1514
1516
        result = []
1515
1517
        if self.datas:
 
1518
            ids_orig = ids
1516
1519
            if isinstance(ids, (int, long)):
1517
1520
                ids = [ids]
1518
1521
            for id in ids:
1530
1533
                res2 = self._columns[f].get_memory(cr, self, ids, f, user, context=context, values=result)
1531
1534
                for record in result:
1532
1535
                    record[f] = res2[record['id']]
1533
 
            if isinstance(ids, (int, long)):
 
1536
            if isinstance(ids_orig, (int, long)):
1534
1537
                return result[0]
1535
1538
        return result
1536
1539
 
2008
2011
        
2009
2012
        for record in store_fncts:
2010
2013
            if record[0] == self._name and (self._columns.get(record[1],False) or self._inherit_fields.get(record[1],False)):
2011
 
                if (not isinstance(self._columns[record[1]],fields.function)) or (record[1] in self._inherit_fields and not isinstance(self._inherit_fields[[record[1]]][2],fields.function)):
 
2014
                if (not isinstance(self._columns[record[1]],fields.function)) or (record[1] in self._inherit_fields and not isinstance(self._inherit_fields[record[1]][2],fields.function)):
2012
2015
                    remove_stores.append(record)
2013
2016
 
2014
2017
        for stores in remove_stores:
2233
2236
                if v is None:
2234
2237
                    r[key] = False
2235
2238
                if key in self._columns.keys():
2236
 
                    type = self._columns[key]._type
 
2239
                    field = self._columns[key]
2237
2240
                elif key in self._inherit_fields.keys():
2238
 
                    type = self._inherit_fields[key][2]._type
 
2241
                    field = self._inherit_fields[key][2]
2239
2242
                else:
2240
2243
                    continue
2241
 
                if type == 'reference' and v:
 
2244
                if field._type == 'reference' and getattr(field, 'store', True) and v:
2242
2245
                    model,ref_id = v.split(',')
2243
2246
                    table = self.pool.get(model)._table
2244
2247
                    cr.execute('select id from "%s" where id=%%s' % (table,), (ref_id,))
2709
2712
                    clause, params = '%s=%%s' % (self._parent_name,), (parent_val,)
2710
2713
                else:
2711
2714
                    clause, params = '%s IS NULL' % (self._parent_name,), ()
2712
 
                cr.execute('SELECT parent_right, id FROM "%s" WHERE %s ORDER BY %s' % (self._table, clause, order), params)
2713
 
                parents = cr.fetchall()
2714
2715
 
2715
2716
                for id in parents_changed:
2716
2717
                    cr.execute('SELECT parent_left, parent_right FROM "%s" WHERE id=%%s' % (self._table,), (id,))
2717
2718
                    pleft, pright = cr.fetchone()
2718
2719
                    distance = pright - pleft + 1
2719
 
 
 
2720
                                                
 
2721
                    cr.execute('SELECT parent_right, id FROM "%s" WHERE %s ORDER BY %s' % (self._table, clause, order), params)
 
2722
                    parents = cr.fetchall()
 
2723
                    
2720
2724
                    # Find Position of the element
2721
2725
                    position = None
2722
2726
                    for (parent_pright, parent_id) in parents:
2745
2749
                        cr.execute('update '+self._table+' set parent_left=parent_left-%s, parent_right=parent_right-%s where parent_left>=%s and parent_left<%s', (pleft-position+distance,pleft-position+distance, pleft+distance, pright+distance))
2746
2750
 
2747
2751
        result += self._store_get_values(cr, user, ids, vals.keys(), context)
2748
 
        for order, object, ids, fields in result:
2749
 
            self.pool.get(object)._store_set_values(cr, user, ids, fields, context)
2750
 
 
 
2752
        done = {}
 
2753
        for order, object, ids_to_update, fields_to_recompute in result:
 
2754
            key = (object, tuple(fields_to_recompute))
 
2755
            done.setdefault(key, {})
 
2756
            # avoid to do several times the same computation
 
2757
            todo = []
 
2758
            for id in ids_to_update:
 
2759
                if id not in done[key]:
 
2760
                    done[key][id] = True
 
2761
                    todo.append(id)
 
2762
            self.pool.get(object)._store_set_values(cr, user, todo, fields_to_recompute, context)
 
2763
            
2751
2764
        wf_service = netsvc.LocalService("workflow")
2752
2765
        for id in ids:
2753
2766
            wf_service.trg_write(user, self._name, id, cr)