1
# -*- coding: utf-8 -*-
3
from osv import fields, osv
7
class many2many_sorted(fields.many2many):
8
def __init__(self, obj, rel, id1, id2, string='unknown', limit=None, **args):
9
super(many2many_sorted, self).__init__(obj, rel, id1, id2, string, limit, **args)
11
def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
22
warnings.warn("Specifying offset at a many2many.get() may produce unpredictable results.",
23
DeprecationWarning, stacklevel=2)
24
obj = obj.pool.get(self._obj)
26
# static domains are lists, and are evaluated both here and on client-side, while string
27
# domains supposed by dynamic and evaluated on client-side only (thus ignored here)
28
# FIXME: make this distinction explicit in API!
29
domain = isinstance(self._domain, list) and self._domain or []
31
wquery = obj._where_calc(cr, user, domain, context=context)
32
obj._apply_ir_rules(cr, user, wquery, 'read', context=context)
33
from_c, where_c, where_params = wquery.get_sql()
35
where_c = ' AND ' + where_c
38
rel_obj = obj.pool.get('account.destination.link')
40
order_by = ' ORDER BY '
42
for order in rel_obj._order.split(','):
43
order_tab.append('%s.%s' %(from_c, order.strip()))
44
order_by += ','.join(order_tab)
47
if self._limit is not None:
48
limit_str = ' LIMIT %d' % self._limit
50
query = 'SELECT %(rel)s.%(id2)s, %(rel)s.%(id1)s \
51
FROM %(rel)s, %(from_c)s \
52
WHERE %(rel)s.%(id1)s IN %%s \
53
AND %(rel)s.%(id2)s = %(tbl)s.id \
68
cr.execute(query, [tuple(ids),] + where_params)
69
for r in cr.fetchall():
70
res[r[1]].append(r[0])