Speed Improvement:
[odoo/odoo.git] / bin / osv / fields.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 #
6 # $Id$
7 #
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
14 #
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28 #
29 ##############################################################################
30
31 # . Fields:
32 #      - simple
33 #      - relations (one2many, many2one, many2many)
34 #      - function
35 #
36 # Fields Attributes:
37 #   _classic_read: is a classic sql fields
38 #   _type   : field type
39 #   readonly
40 #   required
41 #   size
42 #
43 import string
44 import netsvc
45
46 import psycopg
47 import warnings
48
49 import tools
50
51
52 def _symbol_set(symb):
53     if symb == None or symb == False:
54         return None
55     elif isinstance(symb, unicode):
56         return symb.encode('utf-8')
57     return str(symb)
58
59
60 class _column(object):
61     _classic_read = True
62     _classic_write = True
63     _properties = False
64     _type = 'unknown'
65     _obj = None
66     _multi = False
67     _symbol_c = '%s'
68     _symbol_f = _symbol_set
69     _symbol_set = (_symbol_c, _symbol_f)
70     _symbol_get = None
71
72     def __init__(self, string='unknown', required=False, readonly=False, domain=None, context='', states=None, priority=0, change_default=False, size=None, ondelete="set null", translate=False, select=False, **args):
73         self.states = states or {}
74         self.string = string
75         self.readonly = readonly
76         self.required = required
77         self.size = size
78         self.help = args.get('help', '')
79         self.priority = priority
80         self.change_default = change_default
81         self.ondelete = ondelete
82         self.translate = translate
83         self._domain = domain or []
84         self.relate = False
85         self._context = context
86         self.group_name = False
87         self.write = False
88         self.read = False
89         self.view_load = 0
90         self.select = select
91         for a in args:
92             if args[a]:
93                 setattr(self, a, args[a])
94         if self.relate:
95             warnings.warn("The relate attribute doesn't work anymore, use act_window tag instead", DeprecationWarning)
96
97     def restart(self):
98         pass
99
100     def set(self, cr, obj, id, name, value, user=None, context=None):
101         cr.execute('update '+obj._table+' set '+name+'='+self._symbol_set[0]+' where id=%d', (self._symbol_set[1](value), id))
102
103     def set_memory(self, cr, obj, id, name, value, user=None, context=None):
104         raise Exception(_('Not implemented set_memory method !'))
105
106     def get_memory(self, cr, obj, ids, name, context=None, values=None):
107         raise Exception(_('Not implemented get_memory method !'))
108
109     def get(self, cr, obj, ids, name, context=None, values=None):
110         raise Exception(_('undefined get method !'))
111
112     def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
113         ids = obj.search(cr, uid, args+self._domain+[(name, 'ilike', value)], offset, limit)
114         res = obj.read(cr, uid, ids, [name])
115         return [x[name] for x in res]
116
117     def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
118         raise Exception(_('Not implemented search_memory method !'))
119
120
121 # ---------------------------------------------------------
122 # Simple fields
123 # ---------------------------------------------------------
124 class boolean(_column):
125     _type = 'boolean'
126     _symbol_c = '%s'
127     _symbol_f = lambda x: x and 'True' or 'False'
128     _symbol_set = (_symbol_c, _symbol_f)
129
130
131 class integer(_column):
132     _type = 'integer'
133     _symbol_c = '%d'
134     _symbol_f = lambda x: int(x or 0)
135     _symbol_set = (_symbol_c, _symbol_f)
136
137
138 class reference(_column):
139     _type = 'reference'
140
141     def __init__(self, string, selection, size, **args):
142         _column.__init__(self, string=string, size=size, selection=selection, **args)
143
144
145 class char(_column):
146     _type = 'char'
147
148     def __init__(self, string, size, **args):
149         _column.__init__(self, string=string, size=size, **args)
150         self._symbol_set = (self._symbol_c, self._symbol_set_char)
151
152     # takes a string (encoded in utf8) and returns a string (encoded in utf8)
153     def _symbol_set_char(self, symb):
154         #TODO:
155         # * we need to remove the "symb==False" from the next line BUT
156         #   for now too many things rely on this broken behavior
157         # * the symb==None test should be common to all data types
158         if symb == None or symb == False:
159             return None
160
161         # we need to convert the string to a unicode object to be able
162         # to evaluate its length (and possibly truncate it) reliably
163         if isinstance(symb, str):
164             u_symb = unicode(symb, 'utf8')
165         elif isinstance(symb, unicode):
166             u_symb = symb
167         else:
168             u_symb = unicode(symb)
169         return u_symb.encode('utf8')[:self.size]
170
171
172 class text(_column):
173     _type = 'text'
174
175 import __builtin__
176
177
178 class float(_column):
179     _type = 'float'
180     _symbol_c = '%f'
181     _symbol_f = lambda x: __builtin__.float(x or 0.0)
182     _symbol_set = (_symbol_c, _symbol_f)
183
184     def __init__(self, string='unknown', digits=None, **args):
185         _column.__init__(self, string=string, **args)
186         self.digits = digits
187
188
189 class date(_column):
190     _type = 'date'
191
192
193 class datetime(_column):
194     _type = 'datetime'
195
196
197 class time(_column):
198     _type = 'time'
199
200
201 class binary(_column):
202     _type = 'binary'
203     _symbol_c = '%s'
204     _symbol_f = lambda symb: symb and psycopg.Binary(symb) or None
205     _symbol_set = (_symbol_c, _symbol_f)
206
207
208 class selection(_column):
209     _type = 'selection'
210
211     def __init__(self, selection, string='unknown', **args):
212         _column.__init__(self, string=string, **args)
213         self.selection = selection
214
215 # ---------------------------------------------------------
216 # Relationals fields
217 # ---------------------------------------------------------
218
219 #
220 # Values: (0, 0,  { fields })    create
221 #         (1, ID, { fields })    modification
222 #         (2, ID)                remove (delete)
223 #         (3, ID)                unlink one (target id or target of relation)
224 #         (4, ID)                link
225 #         (5)                    unlink all (only valid for one2many)
226 #
227 #CHECKME: dans la pratique c'est quoi la syntaxe utilisee pour le 5? (5) ou (5, 0)?
228 class one2one(_column):
229     _classic_read = False
230     _classic_write = True
231     _type = 'one2one'
232
233     def __init__(self, obj, string='unknown', **args):
234         warnings.warn("The one2one field doesn't work anymore", DeprecationWarning)
235         _column.__init__(self, string=string, **args)
236         self._obj = obj
237
238     def set(self, cr, obj_src, id, field, act, user=None, context=None):
239         if not context:
240             context = {}
241         obj = obj_src.pool.get(self._obj)
242         self._table = obj_src.pool.get(self._obj)._table
243         if act[0] == 0:
244             id_new = obj.create(cr, user, act[1])
245             cr.execute('update '+obj_src._table+' set '+field+'=%d where id=%d', (id_new, id))
246         else:
247             cr.execute('select '+field+' from '+obj_src._table+' where id=%d', (act[0],))
248             id = cr.fetchone()[0]
249             obj.write(cr, user, [id], act[1], context=context)
250
251     def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
252         return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit)
253
254
255 class many2one(_column):
256     _classic_read = False
257     _classic_write = True
258     _type = 'many2one'
259
260     def __init__(self, obj, string='unknown', **args):
261         _column.__init__(self, string=string, **args)
262         self._obj = obj
263
264     #
265     # TODO: speed improvement
266     #
267     # name is the name of the relation field
268     def get_memory(self, cr, obj, ids, name, user=None, context=None, values=None):
269         result = {}
270         for id in ids:
271             result[id] = obj.datas[id][name]
272         return result
273
274     def get(self, cr, obj, ids, name, user=None, context=None, values=None):
275         if not context:
276             context = {}
277         if not values:
278             values = {}
279         res = {}
280         for r in values:
281             res[r['id']] = r[name]
282         for id in ids:
283             res.setdefault(id, '')
284         obj = obj.pool.get(self._obj)
285         # build a dictionary of the form {'id_of_distant_resource': name_of_distant_resource}
286         from orm import except_orm
287         try:
288             names = dict(obj.name_get(cr, user, filter(None, res.values()), context))
289         except except_orm:
290             names = {}
291
292             iids = filter(None, res.values())
293             cr.execute('select id,'+obj._rec_name+' from '+obj._table+' where id in ('+','.join(map(str, iids))+')')
294             for res22 in cr.fetchall():
295                 names[res22[0]] = res22[1]
296
297         for r in res.keys():
298             if res[r] and res[r] in names:
299                 res[r] = (res[r], names[res[r]])
300             else:
301                 res[r] = False
302         return res
303
304     def set(self, cr, obj_src, id, field, values, user=None, context=None):
305         if not context:
306             context = {}
307         obj = obj_src.pool.get(self._obj)
308         self._table = obj_src.pool.get(self._obj)._table
309         if type(values)==type([]):
310             for act in values:
311                 if act[0] == 0:
312                     id_new = obj.create(cr, act[2])
313                     cr.execute('update '+obj_src._table+' set '+field+'=%d where id=%d', (id_new, id))
314                 elif act[0] == 1:
315                     obj.write(cr, [act[1]], act[2], context=context)
316                 elif act[0] == 2:
317                     cr.execute('delete from '+self._table+' where id=%d', (act[1],))
318                 elif act[0] == 3 or act[0] == 5:
319                     cr.execute('update '+obj_src._table+' set '+field+'=null where id=%d', (id,))
320                 elif act[0] == 4:
321                     cr.execute('update '+obj_src._table+' set '+field+'=%d where id=%d', (act[1], id))
322         else:
323             if values:
324                 cr.execute('update '+obj_src._table+' set '+field+'=%d where id=%d', (values, id))
325             else:
326                 cr.execute('update '+obj_src._table+' set '+field+'=null where id=%d', (id,))
327
328     def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None):
329         return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit)
330
331
332 class one2many(_column):
333     _classic_read = False
334     _classic_write = False
335     _type = 'one2many'
336
337     def __init__(self, obj, fields_id, string='unknown', limit=None, **args):
338         _column.__init__(self, string=string, **args)
339         self._obj = obj
340         self._fields_id = fields_id
341         self._limit = limit
342         #one2many can't be used as condition for defaults
343         assert(self.change_default != True)
344
345     def get_memory(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
346         if not context:
347             context = {}
348         if not values:
349             values = {}
350         res = {}
351         for id in ids:
352             res[id] = []
353         ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id, 'in', ids)], limit=self._limit)
354         for r in obj.pool.get(self._obj).read(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
355             if r[self._fields_id] in res:
356                 res[r[self._fields_id]].append(r['id'])
357         return res
358
359     def set_memory(self, cr, obj, id, field, values, user=None, context=None):
360         if not context:
361             context = {}
362         if not values:
363             return
364         obj = obj.pool.get(self._obj)
365         for act in values:
366             if act[0] == 0:
367                 act[2][self._fields_id] = id
368                 obj.create(cr, user, act[2], context=context)
369             elif act[0] == 1:
370                 obj.write(cr, user, [act[1]], act[2], context=context)
371             elif act[0] == 2:
372                 obj.unlink(cr, user, [act[1]], context=context)
373             elif act[0] == 3:
374                 obj.datas[act[1]][self._fields_id] = False
375             elif act[0] == 4:
376                 obj.datas[act[1]] = id
377             elif act[0] == 5:
378                 for o in obj.datas.values():
379                     if o[self._fields_id] == id:
380                         o[self._fields_id] = False
381             elif act[0] == 6:
382                 for id2 in (act[2] or []):
383                     obj.datas[id2][self._fields_id] = id
384
385     def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
386         raise _('Not Implemented')
387
388     def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
389         if not context:
390             context = {}
391         if not values:
392             values = {}
393         res = {}
394         for id in ids:
395             res[id] = []
396         ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id, 'in', ids)], limit=self._limit)
397         for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
398             res[r[self._fields_id]].append(r['id'])
399         return res
400
401     def set(self, cr, obj, id, field, values, user=None, context=None):
402         if not context:
403             context = {}
404         if not values:
405             return
406         _table = obj.pool.get(self._obj)._table
407         obj = obj.pool.get(self._obj)
408         for act in values:
409             if act[0] == 0:
410                 act[2][self._fields_id] = id
411                 obj.create(cr, user, act[2], context=context)
412             elif act[0] == 1:
413                 obj.write(cr, user, [act[1]], act[2], context=context)
414             elif act[0] == 2:
415                 obj.unlink(cr, user, [act[1]], context=context)
416             elif act[0] == 3:
417                 cr.execute('update '+_table+' set '+self._fields_id+'=null where id=%d', (act[1],))
418             elif act[0] == 4:
419                 cr.execute('update '+_table+' set '+self._fields_id+'=%d where id=%d', (id, act[1]))
420             elif act[0] == 5:
421                 cr.execute('update '+_table+' set '+self._fields_id+'=null where '+self._fields_id+'=%d', (id,))
422             elif act[0] == 6:
423                 if not act[2]:
424                     ids2 = [0]
425                 else:
426                     ids2 = act[2]
427                 cr.execute('update '+_table+' set '+self._fields_id+'=NULL where '+self._fields_id+'=%d and id not in ('+','.join(map(str, ids2))+')', (id,))
428                 if act[2]:
429                     cr.execute('update '+_table+' set '+self._fields_id+'=%d where id in ('+','.join(map(str, act[2]))+')', (id,))
430
431     def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like'):
432         return obj.pool.get(self._obj).name_search(cr, uid, value, self._domain, offset, limit)
433
434
435 #
436 # Values: (0, 0,  { fields })    create
437 #         (1, ID, { fields })    modification
438 #         (2, ID)                remove
439 #         (3, ID)                unlink
440 #         (4, ID)                link
441 #         (5, ID)                unlink all
442 #         (6, ?, ids)            set a list of links
443 #
444 class many2many(_column):
445     _classic_read = False
446     _classic_write = False
447     _type = 'many2many'
448
449     def __init__(self, obj, rel, id1, id2, string='unknown', limit=None, **args):
450         _column.__init__(self, string=string, **args)
451         self._obj = obj
452         self._rel = rel
453         self._id1 = id1
454         self._id2 = id2
455         self._limit = limit
456
457     def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
458         if not context:
459             context = {}
460         if not values:
461             values = {}
462         res = {}
463         if not ids:
464             return res
465         for id in ids:
466             res[id] = []
467         ids_s = ','.join(map(str, ids))
468         limit_str = self._limit is not None and ' limit %d' % self._limit or ''
469         obj = obj.pool.get(self._obj)
470
471         d1, d2 = obj.pool.get('ir.rule').domain_get(cr, user, obj._name)
472         if d1:
473             d1 = ' and '+d1
474
475         cr.execute('SELECT '+self._rel+'.'+self._id2+','+self._rel+'.'+self._id1+' \
476                 FROM '+self._rel+' , '+obj._table+' \
477                 WHERE '+self._rel+'.'+self._id1+' in ('+ids_s+') \
478                     AND '+self._rel+'.'+self._id2+' = '+obj._table+'.id '+d1
479                 +limit_str+' order by '+obj._table+'.'+obj._order+' offset %d',
480                 d2+[offset])
481         for r in cr.fetchall():
482             res[r[1]].append(r[0])
483         return res
484
485     def set(self, cr, obj, id, name, values, user=None, context=None):
486         if not context:
487             context = {}
488         if not values:
489             return
490         obj = obj.pool.get(self._obj)
491         for act in values:
492             if act[0] == 0:
493                 idnew = obj.create(cr, user, act[2])
494                 cr.execute('insert into '+self._rel+' ('+self._id1+','+self._id2+') values (%d,%d)', (id, idnew))
495             elif act[0] == 1:
496                 obj.write(cr, user, [act[1]], act[2], context=context)
497             elif act[0] == 2:
498                 obj.unlink(cr, user, [act[1]], context=context)
499             elif act[0] == 3:
500                 cr.execute('delete from '+self._rel+' where ' + self._id1 + '=%d and '+ self._id2 + '=%d', (id, act[1]))
501             elif act[0] == 4:
502                 cr.execute('insert into '+self._rel+' ('+self._id1+','+self._id2+') values (%d,%d)', (id, act[1]))
503             elif act[0] == 5:
504                 cr.execute('update '+self._rel+' set '+self._id2+'=null where '+self._id2+'=%d', (id,))
505             elif act[0] == 6:
506
507                 d1, d2 = obj.pool.get('ir.rule').domain_get(cr, user, obj._name)
508                 if d1:
509                     d1 = ' and '+d1
510                 cr.execute('delete from '+self._rel+' where '+self._id1+'=%d AND '+self._id2+' IN (SELECT '+self._rel+'.'+self._id2+' FROM '+self._rel+', '+obj._table+' WHERE '+self._rel+'.'+self._id1+'=%d AND '+self._rel+'.'+self._id2+' = '+obj._table+'.id '+ d1 +')', [id, id]+d2)
511
512                 for act_nbr in act[2]:
513                     cr.execute('insert into '+self._rel+' ('+self._id1+','+self._id2+') values (%d, %d)', (id, act_nbr))
514
515     #
516     # TODO: use a name_search
517     #
518     def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like'):
519         return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', operator, value)], offset, limit)
520
521     def get_memory(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
522         result = {}
523         for id in ids:
524             result[id] = obj.datas[id].get(name, [])
525         return result
526
527     def set_memory(self, cr, obj, id, name, values, user=None, context=None):
528         if not values:
529             return
530         for act in values:
531             # TODO: use constants instead of these magic numbers
532             if act[0] == 0:
533                 raise _('Not Implemented')
534             elif act[0] == 1:
535                 raise _('Not Implemented')
536             elif act[0] == 2:
537                 raise _('Not Implemented')
538             elif act[0] == 3:
539                 raise _('Not Implemented')
540             elif act[0] == 4:
541                 raise _('Not Implemented')
542             elif act[0] == 5:
543                 raise _('Not Implemented')
544             elif act[0] == 6:
545                 obj.datas[id][name] = act[2]
546
547
548 # ---------------------------------------------------------
549 # Function fields
550 # ---------------------------------------------------------
551 class function(_column):
552     _classic_read = False
553     _classic_write = False
554     _type = 'function'
555     _properties = True
556
557 #
558 # multi: compute several fields in one call
559 #
560     def __init__(self, fnct, arg=None, fnct_inv=None, fnct_inv_arg=None, type='float', fnct_search=None, obj=None, method=False, store=False, multi=False, **args):
561         _column.__init__(self, **args)
562         self._obj = obj
563         self._method = method
564         self._fnct = fnct
565         self._fnct_inv = fnct_inv
566         self._arg = arg
567         self._multi = multi
568         if 'relation' in args:
569             self._obj = args['relation']
570         self._fnct_inv_arg = fnct_inv_arg
571         if not fnct_inv:
572             self.readonly = 1
573         self._type = type
574         self._fnct_search = fnct_search
575         self.store = store
576         if type == 'float':
577             self._symbol_c = '%f'
578             self._symbol_f = lambda x: __builtin__.float(x or 0.0)
579             self._symbol_set = (self._symbol_c, self._symbol_f)
580
581     def search(self, cr, uid, obj, name, args):
582         if not self._fnct_search:
583             #CHECKME: should raise an exception
584             return []
585         return self._fnct_search(obj, cr, uid, obj, name, args)
586
587     def get(self, cr, obj, ids, name, user=None, context=None, values=None):
588         if not context:
589             context = {}
590         if not values:
591             values = {}
592         res = {}
593         if self._method:
594             return self._fnct(obj, cr, user, ids, name, self._arg, context)
595         else:
596             return self._fnct(cr, obj._table, ids, name, self._arg, context)
597
598     def set(self, cr, obj, id, name, value, user=None, context=None):
599         if not context:
600             context = {}
601         if self._fnct_inv:
602             self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)
603
604
605 # ---------------------------------------------------------
606 # Serialized fields
607 # ---------------------------------------------------------
608 class serialized(_column):
609     def __init__(self, string='unknown', serialize_func=repr, deserialize_func=eval, type='text', **args):
610         self._serialize_func = serialize_func
611         self._deserialize_func = deserialize_func
612         self._type = type
613         self._symbol_set = (self._symbol_c, self._serialize_func)
614         self._symbol_get = self._deserialize_func
615         super(serialized, self).__init__(string=string, **args)
616
617
618 class property(function):
619
620     def _fnct_write(self, obj, cr, uid, id, prop, id_val, val, context=None):
621         if not context:
622             context = {}
623         (obj_dest,) = val
624         definition_id = self._field_get(cr, uid, obj._name, prop)
625
626         property = obj.pool.get('ir.property')
627         nid = property.search(cr, uid, [('fields_id', '=', definition_id),
628             ('res_id', '=', obj._name+','+str(id))])
629         while len(nid):
630             cr.execute('DELETE FROM ir_property WHERE id=%d', (nid.pop(),))
631
632         nid = property.search(cr, uid, [('fields_id', '=', definition_id),
633             ('res_id', '=', False)])
634         default_val = False
635         if nid:
636             default_val = property.browse(cr, uid, nid[0], context).value
637
638         company_id = obj.pool.get('res.users').company_get(cr, uid, uid)
639         res = False
640         newval = (id_val and obj_dest+','+str(id_val)) or False
641         if (newval != default_val) and newval:
642             propdef = obj.pool.get('ir.model.fields').browse(cr, uid,
643                     definition_id, context=context)
644             res = property.create(cr, uid, {
645                 'name': propdef.name,
646                 'value': newval,
647                 'res_id': obj._name+','+str(id),
648                 'company_id': company_id,
649                 'fields_id': definition_id
650             }, context=context)
651         return res
652
653     def _fnct_read(self, obj, cr, uid, ids, prop, val, context=None):
654         if not context:
655             context = {}
656         property = obj.pool.get('ir.property')
657         definition_id = self._field_get(cr, uid, obj._name, prop)
658
659         nid = property.search(cr, uid, [('fields_id', '=', definition_id),
660             ('res_id', '=', False)])
661         default_val = False
662         if nid:
663             d = property.browse(cr, uid, nid[0], context).value
664             default_val = (d and int(d.split(',')[1])) or False
665
666         vids = [obj._name + ',' + str(id) for id in  ids]
667         nids = property.search(cr, uid, [('fields_id', '=', definition_id),
668             ('res_id', 'in', vids)])
669
670         res = {}
671         for id in ids:
672             res[id] = default_val
673         for prop in property.browse(cr, uid, nids):
674             res[int(prop.res_id.split(',')[1])] = (prop.value and \
675                     int(prop.value.split(',')[1])) or False
676
677         obj = obj.pool.get(self._obj)
678         names = dict(obj.name_get(cr, uid, filter(None, res.values()), context))
679         for r in res.keys():
680             if res[r] and res[r] in names:
681                 res[r] = (res[r], names[res[r]])
682             else:
683                 res[r] = False
684         return res
685
686     def _field_get(self, cr, uid, model_name, prop):
687         if not self.field_id.get(cr.dbname):
688             cr.execute('SELECT id \
689                     FROM ir_model_fields \
690                     WHERE name=%s AND model=%s', (prop, model_name))
691             res = cr.fetchone()
692             self.field_id[cr.dbname] = res and res[0]
693         return self.field_id[cr.dbname]
694
695     def __init__(self, obj_prop, **args):
696         self.field_id = {}
697         function.__init__(self, self._fnct_read, False, self._fnct_write,
698                 (obj_prop, ), **args)
699
700     def restart(self):
701         self.field_id = {}
702
703
704 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
705