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