diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 70cb898894e..b1fe5c6adf8 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -912,6 +912,10 @@ class orm(object): cr.execute('SELECT id FROM '+self._table+' WHERE id IN ('+ids_str+')'+d1, d2) if not cr.rowcount == len({}.fromkeys(ids)): raise except_orm('AccessError', 'You try to bypass an access rule (Document type: %s).'%self._description) + else: + cr.execute('SELECT id FROM '+self._table+' WHERE id IN ('+ids_str+')') + if not cr.rowcount == len({}.fromkeys(ids)): + raise except_orm('AccessError', 'You try to write on an record that doesn\'t exist (Document type: %s).'%self._description) cr.execute('update '+self._table+' set '+string.join(upd0,',')+' where id in ('+ids_str+')'+d1, upd1+ d2) if totranslate: @@ -1517,8 +1521,25 @@ class orm(object): return (qu1,qu2,tables) def search_count(self, cr, user, args, context={}): - return 128 + # compute the count of records + (qu1,qu2,tables) = self._where_calc(cr, user, args, context) + if len(qu1): + qu1 = ' where '+string.join(qu1,' and ') + else: + qu1 = '' + + # construct a clause for the rules : + d1, d2 = self.pool.get('ir.rule').domain_get(cr, user, self._name) + if d1: + qu1 = qu1 and qu1+' and '+d1 or ' where '+d1 + qu2 += d2 + + # execute the "main" query to fetch the count of ids + cr.execute('select count(%s.id) from ' % self._table + ','.join(tables) +qu1, qu2) + res = cr.fetchall() + return res[0][0] + def search(self, cr, user, args, offset=0, limit=None, order=None, context={}): # compute the where, order by, limit and offset clauses