- def _read_flat(self, cr, user, ids, fields, context=None, load='_classic_read'):
- if context is None:
- context = {}
- if not ids:
- return []
-
- if fields is None:
- fields = self._columns.keys()
- res_trans_obj = self.pool.get('ir.translation')
-
- # construct a clause for the rules:
- d1, d2, tables = self.pool.get('ir.rule').domain_get(cr, user, self._name, 'read', context=context)
-
- # all inherited fields + all non inherited fields for which the attribute whose name is in load is True
- fields_pre = filter(lambda x: x in self._columns and getattr(self._columns[x],'_classic_write'), fields) + self._inherits.values()
- res = []
- cr.execute('SELECT MAX(id) FROM res_users')
- max_user = cr.fetchone()[0]
- if fields_pre:
- fields_pre2 = map(lambda x: (x in ('create_date', 'write_date')) and ('date_trunc(\'second\', '+x+') as '+x) or '"'+x+'"', fields_pre)
- for i in range(0, len(ids), cr.IN_MAX):
- sub_ids = ids[i:i+cr.IN_MAX]
- if d1:
- cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) ' \
- 'AND account_id IN (%s) ' \
- 'AND "user" IN (%s) AND %s ORDER BY %s' % \
- (','.join(fields_pre2 + ['id']), self._table,
- ','.join([str(x) for x in sub_ids]),
- ','.join([str(x/max_user - (x%max_user == 0 and 1 or 0)) for x in sub_ids]),
- ','.join([str(x-((x/max_user - (x%max_user == 0 and 1 or 0)) *max_user)) for x in sub_ids]), d1,
- self._order),d2)
- if not cr.rowcount == len({}.fromkeys(sub_ids)):
- raise except_orm(_('AccessError'),
- _('You try to bypass an access rule (Document type: %s).') % self._description)
- else:
- cr.execute('SELECT %s FROM \"%s\" WHERE id IN (%s) ' \
- 'AND account_id IN (%s) ' \
- 'AND "user" IN (%s) ORDER BY %s' % \
- (','.join(fields_pre2 + ['id']), self._table,
- ','.join([str(x) for x in sub_ids]),
- ','.join([str(x/max_user - (x%max_user == 0 and 1 or 0)) for x in sub_ids]),
- ','.join([str(x-((x/max_user - (x%max_user == 0 and 1 or 0)) *max_user)) for x in sub_ids]),
- self._order))
- res.extend(cr.dictfetchall())
- else:
- res = map(lambda x: {'id': x}, ids)
- for f in fields_pre:
- if self._columns[f].translate:
- ids = map(lambda x: x['id'], res)
- res_trans = res_trans_obj._get_ids(cr, user, self._name+','+f, 'model', context.get('lang', False) or 'en_US', ids)
- for r in res:
- r[f] = res_trans.get(r['id'], False) or r[f]
-
- for table in self._inherits:
- col = self._inherits[table]
- cols = intersect(self._inherit_fields.keys(), fields)
- if not cols:
- continue
- res2 = self.pool.get(table).read(cr, user, [x[col] for x in res], cols, context, load)
-
- res3 = {}
- for r in res2:
- res3[r['id']] = r
- del r['id']
-
- for record in res:
- record.update(res3[record[col]])
- if col not in fields:
- del record[col]
-
- # all fields which need to be post-processed by a simple function (symbol_get)
- fields_post = filter(lambda x: x in self._columns and self._columns[x]._symbol_get, fields)
- if fields_post:
- # maybe it would be faster to iterate on the fields then on res, so that we wouldn't need
- # to get the _symbol_get in each occurence
- for r in res:
- for f in fields_post:
- r[f] = self.columns[f]._symbol_get(r[f])
- ids = map(lambda x: x['id'], res)
-
- # all non inherited fields for which the attribute whose name is in load is False
- fields_post = filter(lambda x: x in self._columns and not getattr(self._columns[x], load), fields)
- for f in fields_post:
- # get the value of that field for all records/ids
- res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
- for record in res:
- record[f] = res2[record['id']]
-
- return res
-