[FIX] multi company, speed improvement
bzr revid: fp@tinyerp.com-20091222212036-oeekt3f06k5j0ize
This commit is contained in:
parent
320e418660
commit
89be98debf
|
@ -137,9 +137,9 @@ class ir_rule(osv.osv):
|
|||
if not (field_id or operator or operand):
|
||||
return {}
|
||||
|
||||
def domain_get2(self, cr, uid, model_name, context={}):
|
||||
def domain_get(self, cr, uid, model_name, context={}):
|
||||
if uid == 1:
|
||||
return []
|
||||
return [], [], []
|
||||
|
||||
cr.execute("""SELECT r.id FROM
|
||||
ir_rule r
|
||||
|
@ -154,12 +154,8 @@ class ir_rule(osv.osv):
|
|||
dom = []
|
||||
for rule in self.browse(cr, uid, ids):
|
||||
dom += rule.domain
|
||||
return dom
|
||||
|
||||
def domain_get(self, cr, uid, model_name, context={}):
|
||||
dom = self.domain_get2(cr, uid, model_name, context=context)
|
||||
d1,d2,tables = self.pool.get(model_name)._where_calc(cr, uid, dom, active_test=False)
|
||||
return ' and '.join(d1), d2, tables
|
||||
return d1, d2, tables
|
||||
domain_get = tools.cache()(domain_get)
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
|
|
@ -2400,7 +2400,7 @@ class orm(orm_template):
|
|||
sub_ids = ids[i:i+cr.IN_MAX]
|
||||
if d1:
|
||||
cr.execute('SELECT %s FROM %s WHERE %s.id = ANY (%%s) AND %s ORDER BY %s' % \
|
||||
(','.join(fields_pre2 + [self._table + '.id']), ','.join(tables), self._table, d1,
|
||||
(','.join(fields_pre2 + [self._table + '.id']), ','.join(tables), self._table, ' and '.join(d1),
|
||||
self._order),[sub_ids,]+d2)
|
||||
if not cr.rowcount == len({}.fromkeys(sub_ids)):
|
||||
raise except_orm(_('AccessError'),
|
||||
|
@ -2588,14 +2588,14 @@ class orm(orm_template):
|
|||
|
||||
d1, d2,tables = self.pool.get('ir.rule').domain_get(cr, uid, self._name, context=context)
|
||||
if d1:
|
||||
d1 = ' AND '+d1
|
||||
d1 = ' AND '+' and '.join(d1)
|
||||
|
||||
for i in range(0, len(ids), cr.IN_MAX):
|
||||
sub_ids = ids[i:i+cr.IN_MAX]
|
||||
str_d = string.join(('%s',)*len(sub_ids), ',')
|
||||
if d1:
|
||||
cr.execute('SELECT '+self._table+'.id FROM '+','.join(tables)+' ' \
|
||||
'WHERE '+self._table+'.id IN ('+str_d+')'+d1, sub_ids+d2)
|
||||
'WHERE '+self._table+'.id IN ('+str_d+')'+' and '.join(d1), sub_ids+d2)
|
||||
if not cr.rowcount == len(sub_ids):
|
||||
raise except_orm(_('AccessError'),
|
||||
_('You try to bypass an access rule (Document type: %s).') % \
|
||||
|
@ -2704,14 +2704,14 @@ class orm(orm_template):
|
|||
|
||||
d1, d2,tables = self.pool.get('ir.rule').domain_get(cr, user, self._name, context=context)
|
||||
if d1:
|
||||
d1 = ' and '+d1
|
||||
d1 = ' and '+' and '.join(d1)
|
||||
|
||||
for i in range(0, len(ids), cr.IN_MAX):
|
||||
sub_ids = ids[i:i+cr.IN_MAX]
|
||||
ids_str = string.join(map(str, sub_ids), ',')
|
||||
if d1:
|
||||
cr.execute('SELECT '+self._table+'.id FROM '+','.join(tables)+' ' \
|
||||
'WHERE '+self._table+'.id IN ('+ids_str+')'+d1, d2)
|
||||
'WHERE '+self._table+'.id IN ('+ids_str+')'+' and '.join(d1), d2)
|
||||
if not cr.rowcount == len({}.fromkeys(sub_ids)):
|
||||
raise except_orm(_('AccessError'),
|
||||
_('You try to bypass an access rule while writing (Document type: %s).') % \
|
||||
|
@ -3155,13 +3155,21 @@ class orm(orm_template):
|
|||
if not context:
|
||||
context = {}
|
||||
# compute the where, order by, limit and offset clauses
|
||||
dom = self.pool.get('ir.rule').domain_get2(cr, user, self._name, context=context)
|
||||
(qu1, qu2, tables) = self._where_calc(cr, user, args+dom, context=context)
|
||||
(qu1, qu2, tables) = self._where_calc(cr, user, args, context=context)
|
||||
dom = self.pool.get('ir.rule').domain_get(cr, user, self._name, context=context)
|
||||
print '***', dom, qu1,qu2,tables
|
||||
qu1 = qu1 + dom[0]
|
||||
qu2 = qu2 + dom[1]
|
||||
for t in dom[2]:
|
||||
if t not in tables:
|
||||
tables.append(t)
|
||||
|
||||
if len(qu1):
|
||||
qu1 = ' where '+string.join(qu1, ' and ')
|
||||
else:
|
||||
qu1 = ''
|
||||
|
||||
|
||||
if order:
|
||||
self._check_qorder(order)
|
||||
order_by = order or self._order
|
||||
|
|
|
@ -82,7 +82,6 @@ class Cursor(object):
|
|||
self.sql_into_log = {}
|
||||
self.sql_log = False
|
||||
self.sql_log_count = 0
|
||||
|
||||
self.__closed = True # avoid the call of close() (by __del__) if an exception
|
||||
# is raised by any of the following initialisations
|
||||
self._pool = pool
|
||||
|
|
Loading…
Reference in New Issue