[MERGE] Merged OpenChatter-3-5 followers refactoring. This server-side branch holds a small refactoring in many2many fields: the query has been taken in a method to be more easily overiden. Please note that this commit is likely to be trashed when merging trunk-mail-review.
bzr revid: tde@openerp.com-20120816002627-n3gnbi7izq34t09h
This commit is contained in:
commit
5f866fbacd
|
@ -330,7 +330,8 @@ class res_partner(osv.osv):
|
||||||
|
|
||||||
def update_address(self, cr, uid, ids, vals, context=None):
|
def update_address(self, cr, uid, ids, vals, context=None):
|
||||||
addr_vals = dict((key, vals[key]) for key in POSTAL_ADDRESS_FIELDS if vals.get(key))
|
addr_vals = dict((key, vals[key]) for key in POSTAL_ADDRESS_FIELDS if vals.get(key))
|
||||||
return super(res_partner, self).write(cr, uid, ids, addr_vals, context)
|
if addr_vals:
|
||||||
|
return super(res_partner, self).write(cr, uid, ids, addr_vals, context)
|
||||||
|
|
||||||
def name_get(self, cr, uid, ids, context=None):
|
def name_get(self, cr, uid, ids, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
|
|
|
@ -658,6 +658,20 @@ class many2many(_column):
|
||||||
col2 = '%s_id' % dest_model._table
|
col2 = '%s_id' % dest_model._table
|
||||||
return (tbl, col1, col2)
|
return (tbl, col1, col2)
|
||||||
|
|
||||||
|
def _get_query_and_where_params(self, cr, model, ids, values, where_params):
|
||||||
|
""" Extracted from ``get`` to facilitate fine-tuning of the generated
|
||||||
|
query. """
|
||||||
|
query = 'SELECT %(rel)s.%(id2)s, %(rel)s.%(id1)s \
|
||||||
|
FROM %(rel)s, %(from_c)s \
|
||||||
|
WHERE %(rel)s.%(id1)s IN %%s \
|
||||||
|
AND %(rel)s.%(id2)s = %(tbl)s.id \
|
||||||
|
%(where_c)s \
|
||||||
|
%(order_by)s \
|
||||||
|
%(limit)s \
|
||||||
|
OFFSET %(offset)d' \
|
||||||
|
% values
|
||||||
|
return query, where_params
|
||||||
|
|
||||||
def get(self, cr, model, ids, name, user=None, offset=0, context=None, values=None):
|
def get(self, cr, model, ids, name, user=None, offset=0, context=None, values=None):
|
||||||
if not context:
|
if not context:
|
||||||
context = {}
|
context = {}
|
||||||
|
@ -695,15 +709,7 @@ class many2many(_column):
|
||||||
if self._limit is not None:
|
if self._limit is not None:
|
||||||
limit_str = ' LIMIT %d' % self._limit
|
limit_str = ' LIMIT %d' % self._limit
|
||||||
|
|
||||||
query = 'SELECT %(rel)s.%(id2)s, %(rel)s.%(id1)s \
|
query, where_params = self._get_query_and_where_params(cr, model, ids, {'rel': rel,
|
||||||
FROM %(rel)s, %(from_c)s \
|
|
||||||
WHERE %(rel)s.%(id1)s IN %%s \
|
|
||||||
AND %(rel)s.%(id2)s = %(tbl)s.id \
|
|
||||||
%(where_c)s \
|
|
||||||
%(order_by)s \
|
|
||||||
%(limit)s \
|
|
||||||
OFFSET %(offset)d' \
|
|
||||||
% {'rel': rel,
|
|
||||||
'from_c': from_c,
|
'from_c': from_c,
|
||||||
'tbl': obj._table,
|
'tbl': obj._table,
|
||||||
'id1': id1,
|
'id1': id1,
|
||||||
|
@ -712,7 +718,8 @@ class many2many(_column):
|
||||||
'limit': limit_str,
|
'limit': limit_str,
|
||||||
'order_by': order_by,
|
'order_by': order_by,
|
||||||
'offset': offset,
|
'offset': offset,
|
||||||
}
|
}, where_params)
|
||||||
|
|
||||||
cr.execute(query, [tuple(ids),] + where_params)
|
cr.execute(query, [tuple(ids),] + where_params)
|
||||||
for r in cr.fetchall():
|
for r in cr.fetchall():
|
||||||
res[r[1]].append(r[0])
|
res[r[1]].append(r[0])
|
||||||
|
|
Loading…
Reference in New Issue