1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 # - relations (one2many, many2one, many2many)
28 # _classic_read: is a classic sql fields
38 from psycopg2 import Binary
44 def _symbol_set(symb):
45 if symb == None or symb == False:
47 elif isinstance(symb, unicode):
48 return symb.encode('utf-8')
52 class _column(object):
61 _symbol_f = _symbol_set
62 _symbol_set = (_symbol_c, _symbol_f)
65 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):
66 self.states = states or {}
68 self.readonly = readonly
69 self.required = required
71 self.help = args.get('help', '')
72 self.priority = priority
73 self.change_default = change_default
74 self.ondelete = ondelete
75 self.translate = translate
76 self._domain = domain or []
77 self._context = context
82 self.selectable = True
85 setattr(self, a, args[a])
90 def set(self, cr, obj, id, name, value, user=None, context=None):
91 cr.execute('update '+obj._table+' set '+name+'='+self._symbol_set[0]+' where id=%s', (self._symbol_set[1](value), id))
93 def set_memory(self, cr, obj, id, name, value, user=None, context=None):
94 raise Exception(_('Not implemented set_memory method !'))
96 def get_memory(self, cr, obj, ids, name, user=None, context=None, values=None):
97 raise Exception(_('Not implemented get_memory method !'))
99 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
100 raise Exception(_('undefined get method !'))
102 def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
103 ids = obj.search(cr, uid, args+self._domain+[(name, 'ilike', value)], offset, limit, context=context)
104 res = obj.read(cr, uid, ids, [name], context=context)
105 return [x[name] for x in res]
107 def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
108 raise Exception(_('Not implemented search_memory method !'))
111 # ---------------------------------------------------------
113 # ---------------------------------------------------------
114 class boolean(_column):
117 _symbol_f = lambda x: x and 'True' or 'False'
118 _symbol_set = (_symbol_c, _symbol_f)
121 class integer_big(_column):
122 _type = 'integer_big'
124 _symbol_f = lambda x: int(x or 0)
125 _symbol_set = (_symbol_c, _symbol_f)
127 class integer(_column):
130 _symbol_f = lambda x: int(x or 0)
131 _symbol_set = (_symbol_c, _symbol_f)
134 class reference(_column):
137 def __init__(self, string, selection, size, **args):
138 _column.__init__(self, string=string, size=size, selection=selection, **args)
144 def __init__(self, string, size, **args):
145 _column.__init__(self, string=string, size=size, **args)
146 self._symbol_set = (self._symbol_c, self._symbol_set_char)
148 # takes a string (encoded in utf8) and returns a string (encoded in utf8)
149 def _symbol_set_char(self, symb):
151 # * we need to remove the "symb==False" from the next line BUT
152 # for now too many things rely on this broken behavior
153 # * the symb==None test should be common to all data types
154 if symb == None or symb == False:
157 # we need to convert the string to a unicode object to be able
158 # to evaluate its length (and possibly truncate it) reliably
159 u_symb = tools.ustr(symb)
161 return u_symb[:self.size].encode('utf8')
169 class float(_column):
172 _symbol_f = lambda x: __builtin__.float(x or 0.0)
173 _symbol_set = (_symbol_c, _symbol_f)
175 def __init__(self, string='unknown', digits=None, **args):
176 _column.__init__(self, string=string, **args)
184 class datetime(_column):
192 class binary(_column):
195 _symbol_f = lambda symb: symb and Binary(symb) or None
196 _symbol_set = (_symbol_c, _symbol_f)
197 _symbol_get = lambda self, x: x and str(x)
199 _classic_read = False
202 def __init__(self, string='unknown', filters=None, **args):
203 _column.__init__(self, string=string, **args)
204 self.filters = filters
206 def get_memory(self, cr, obj, ids, name, user=None, context=None, values=None):
218 if context.get('bin_size', False) and val:
219 res[i] = tools.human_size(long(val))
227 class selection(_column):
230 def __init__(self, selection, string='unknown', **args):
231 _column.__init__(self, string=string, **args)
232 self.selection = selection
234 # ---------------------------------------------------------
236 # ---------------------------------------------------------
239 # Values: (0, 0, { fields }) create
240 # (1, ID, { fields }) modification
241 # (2, ID) remove (delete)
242 # (3, ID) unlink one (target id or target of relation)
244 # (5) unlink all (only valid for one2many)
246 #CHECKME: dans la pratique c'est quoi la syntaxe utilisee pour le 5? (5) ou (5, 0)?
247 class one2one(_column):
248 _classic_read = False
249 _classic_write = True
252 def __init__(self, obj, string='unknown', **args):
253 warnings.warn("The one2one field doesn't work anymore", DeprecationWarning)
254 _column.__init__(self, string=string, **args)
257 def set(self, cr, obj_src, id, field, act, user=None, context=None):
260 obj = obj_src.pool.get(self._obj)
261 self._table = obj_src.pool.get(self._obj)._table
263 id_new = obj.create(cr, user, act[1])
264 cr.execute('update '+obj_src._table+' set '+field+'=%s where id=%s', (id_new, id))
266 cr.execute('select '+field+' from '+obj_src._table+' where id=%s', (act[0],))
267 id = cr.fetchone()[0]
268 obj.write(cr, user, [id], act[1], context=context)
270 def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
271 return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit, context=context)
274 class many2one(_column):
275 _classic_read = False
276 _classic_write = True
279 _symbol_f = lambda x: x or None
280 _symbol_set = (_symbol_c, _symbol_f)
282 def __init__(self, obj, string='unknown', **args):
283 _column.__init__(self, string=string, **args)
286 def set_memory(self, cr, obj, id, field, values, user=None, context=None):
287 obj.datas.setdefault(id, {})
288 obj.datas[id][field] = values
290 def get_memory(self, cr, obj, ids, name, user=None, context=None, values=None):
293 result[id] = obj.datas[id][name]
296 def get(self, cr, obj, ids, name, user=None, context=None, values=None):
303 res[r['id']] = r[name]
305 res.setdefault(id, '')
306 obj = obj.pool.get(self._obj)
308 # build a dictionary of the form {'id_of_distant_resource': name_of_distant_resource}
309 from orm import except_orm
311 names = dict(obj.name_get(cr, user, filter(None, res.values()), context))
314 iids = filter(None, res.values())
316 names[iiid] = '// Access Denied //'
318 if res[r] and res[r] in names:
319 res[r] = (res[r], names[res[r]])
324 def set(self, cr, obj_src, id, field, values, user=None, context=None):
327 obj = obj_src.pool.get(self._obj)
328 self._table = obj_src.pool.get(self._obj)._table
329 if type(values) == type([]):
332 id_new = obj.create(cr, act[2])
333 cr.execute('update '+obj_src._table+' set '+field+'=%s where id=%s', (id_new, id))
335 obj.write(cr, [act[1]], act[2], context=context)
337 cr.execute('delete from '+self._table+' where id=%s', (act[1],))
338 elif act[0] == 3 or act[0] == 5:
339 cr.execute('update '+obj_src._table+' set '+field+'=null where id=%s', (id,))
341 cr.execute('update '+obj_src._table+' set '+field+'=%s where id=%s', (act[1], id))
344 cr.execute('update '+obj_src._table+' set '+field+'=%s where id=%s', (values, id))
346 cr.execute('update '+obj_src._table+' set '+field+'=null where id=%s', (id,))
348 def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, context=None):
349 return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', 'like', value)], offset, limit, context=context)
352 class one2many(_column):
353 _classic_read = False
354 _classic_write = False
358 def __init__(self, obj, fields_id, string='unknown', limit=None, **args):
359 _column.__init__(self, string=string, **args)
361 self._fields_id = fields_id
363 #one2many can't be used as condition for defaults
364 assert(self.change_default != True)
366 def get_memory(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
370 context = context.copy()
371 context.update(self._context)
377 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id, 'in', ids)], limit=self._limit, context=context)
378 for r in obj.pool.get(self._obj).read(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
379 if r[self._fields_id] in res:
380 res[r[self._fields_id]].append(r['id'])
383 def set_memory(self, cr, obj, id, field, values, user=None, context=None):
387 context = context.copy()
388 context.update(self._context)
391 obj = obj.pool.get(self._obj)
394 act[2][self._fields_id] = id
395 obj.create(cr, user, act[2], context=context)
397 obj.write(cr, user, [act[1]], act[2], context=context)
399 obj.unlink(cr, user, [act[1]], context=context)
401 obj.datas[act[1]][self._fields_id] = False
403 obj.datas[act[1]] = id
405 for o in obj.datas.values():
406 if o[self._fields_id] == id:
407 o[self._fields_id] = False
409 for id2 in (act[2] or []):
410 obj.datas[id2][self._fields_id] = id
412 def search_memory(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
413 raise _('Not Implemented')
415 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
419 context = context.copy()
420 context.update(self._context)
426 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id, 'in', ids)], limit=self._limit, context=context)
427 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
428 res[r[self._fields_id]].append(r['id'])
431 def set(self, cr, obj, id, field, values, user=None, context=None):
436 context = context.copy()
437 context.update(self._context)
438 context['no_store_function'] = True
441 _table = obj.pool.get(self._obj)._table
442 obj = obj.pool.get(self._obj)
445 act[2][self._fields_id] = id
446 id_new = obj.create(cr, user, act[2], context=context)
447 result += obj._store_get_values(cr, user, [id_new], act[2].keys(), context)
449 obj.write(cr, user, [act[1]], act[2], context=context)
451 obj.unlink(cr, user, [act[1]], context=context)
453 cr.execute('update '+_table+' set '+self._fields_id+'=null where id=%s', (act[1],))
455 cr.execute('update '+_table+' set '+self._fields_id+'=%s where id=%s', (id, act[1]))
457 cr.execute('update '+_table+' set '+self._fields_id+'=null where '+self._fields_id+'=%s', (id,))
459 obj.write(cr, user, act[2], {self._fields_id:id}, context=context or {})
461 cr.execute('select id from '+_table+' where '+self._fields_id+'=%s and id <> ALL (%s)', (id,ids2))
462 ids3 = map(lambda x:x[0], cr.fetchall())
463 obj.write(cr, user, ids3, {self._fields_id:False}, context=context or {})
466 def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
467 return obj.pool.get(self._obj).name_search(cr, uid, value, self._domain, operator, context=context,limit=limit)
471 # Values: (0, 0, { fields }) create
472 # (1, ID, { fields }) modification
477 # (6, ?, ids) set a list of links
479 class many2many(_column):
480 _classic_read = False
481 _classic_write = False
485 def __init__(self, obj, rel, id1, id2, string='unknown', limit=None, **args):
486 _column.__init__(self, string=string, **args)
489 raise Exception(_('The second argument of the many2many field %s must be a SQL table !'\
490 'You used %s, which is not a valid SQL table name.')% (string,rel))
496 def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
506 limit_str = self._limit is not None and ' limit %d' % self._limit or ''
507 obj = obj.pool.get(self._obj)
509 d1, d2, tables = obj.pool.get('ir.rule').domain_get(cr, user, obj._name, context=context)
511 d1 = ' and ' + ' and '.join(d1)
514 cr.execute('SELECT '+self._rel+'.'+self._id2+','+self._rel+'.'+self._id1+' \
515 FROM '+self._rel+' , '+(','.join(tables))+' \
516 WHERE '+self._rel+'.'+self._id1+' = ANY (%s) \
517 AND '+self._rel+'.'+self._id2+' = '+obj._table+'.id '+d1
518 +limit_str+' order by '+obj._table+'.'+obj._order+' offset %s',
520 for r in cr.fetchall():
521 res[r[1]].append(r[0])
524 def set(self, cr, obj, id, name, values, user=None, context=None):
529 obj = obj.pool.get(self._obj)
531 if not (isinstance(act, list) or isinstance(act, tuple)) or not act:
534 idnew = obj.create(cr, user, act[2])
535 cr.execute('insert into '+self._rel+' ('+self._id1+','+self._id2+') values (%s,%s)', (id, idnew))
537 obj.write(cr, user, [act[1]], act[2], context=context)
539 obj.unlink(cr, user, [act[1]], context=context)
541 cr.execute('delete from '+self._rel+' where ' + self._id1 + '=%s and '+ self._id2 + '=%s', (id, act[1]))
543 cr.execute('insert into '+self._rel+' ('+self._id1+','+self._id2+') values (%s,%s)', (id, act[1]))
545 cr.execute('update '+self._rel+' set '+self._id2+'=null where '+self._id2+'=%s', (id,))
548 d1, d2,tables = obj.pool.get('ir.rule').domain_get(cr, user, obj._name, context=context)
550 d1 = ' and ' + ' and '.join(d1)
553 cr.execute('delete from '+self._rel+' where '+self._id1+'=%s AND '+self._id2+' IN (SELECT '+self._rel+'.'+self._id2+' FROM '+self._rel+', '+','.join(tables)+' WHERE '+self._rel+'.'+self._id1+'=%s AND '+self._rel+'.'+self._id2+' = '+obj._table+'.id '+ d1 +')', [id, id]+d2)
555 for act_nbr in act[2]:
556 cr.execute('insert into '+self._rel+' ('+self._id1+','+self._id2+') values (%s, %s)', (id, act_nbr))
559 # TODO: use a name_search
561 def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):
562 return obj.pool.get(self._obj).search(cr, uid, args+self._domain+[('name', operator, value)], offset, limit, context=context)
564 def get_memory(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
567 result[id] = obj.datas[id].get(name, [])
570 def set_memory(self, cr, obj, id, name, values, user=None, context=None):
574 # TODO: use constants instead of these magic numbers
576 raise _('Not Implemented')
578 raise _('Not Implemented')
580 raise _('Not Implemented')
582 raise _('Not Implemented')
584 raise _('Not Implemented')
586 raise _('Not Implemented')
588 obj.datas[id][name] = act[2]
591 def get_nice_size(a):
593 if isinstance(y, (int,long)):
599 return (x, tools.human_size(size))
601 # ---------------------------------------------------------
603 # ---------------------------------------------------------
604 class function(_column):
605 _classic_read = False
606 _classic_write = False
612 # multi: compute several fields in one call
614 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):
615 _column.__init__(self, **args)
617 self._method = method
619 self._fnct_inv = fnct_inv
622 if 'relation' in args:
623 self._obj = args['relation']
626 self.digits = args['digits']
630 self._fnct_inv_arg = fnct_inv_arg
634 self._fnct_search = fnct_search
637 if not fnct_search and not store:
638 self.selectable = False
641 self._classic_read = True
642 self._classic_write = True
644 self._symbol_get=lambda x:x and str(x)
647 self._symbol_c = float._symbol_c
648 self._symbol_f = float._symbol_f
649 self._symbol_set = float._symbol_set
651 def search(self, cr, uid, obj, name, args, context=None):
652 if not self._fnct_search:
653 #CHECKME: should raise an exception
655 return self._fnct_search(obj, cr, uid, obj, name, args, context=context)
657 def get(self, cr, obj, ids, name, user=None, context=None, values=None):
664 res = self._fnct(obj, cr, user, ids, name, self._arg, context)
666 res = self._fnct(cr, obj._table, ids, name, self._arg, context)
668 if self._type == "many2one" :
669 # Filtering only integer/long values if passed
670 res_ids = [x for x in res.values() if x and isinstance(x, (int,long))]
673 obj_model = obj.pool.get(self._obj)
674 dict_names = dict(obj_model.name_get(cr, user, res_ids, context))
676 if res[r] and res[r] in dict_names:
677 res[r] = (res[r], dict_names[res[r]])
679 if self._type == 'binary' and context.get('bin_size', False):
680 # convert the data returned by the function with the size of that data...
681 res = dict(map( get_nice_size, res.items()))
682 if self._type == "integer":
684 # Converting value into string so that it does not affect XML-RPC Limits
689 def set(self, cr, obj, id, name, value, user=None, context=None):
693 self._fnct_inv(obj, cr, user, id, name, value, self._fnct_inv_arg, context)
696 # ---------------------------------------------------------
698 # ---------------------------------------------------------
700 class related(function):
702 def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context={}):
703 self._field_get2(cr, uid, obj, context)
707 if type(sarg) in [type([]), type( (1,) )]:
708 where = [(self._arg[i], 'in', sarg)]
710 where = [(self._arg[i], '=', sarg)]
712 where = map(lambda x: (self._arg[i],x[1], x[2]), domain)
714 sarg = obj.pool.get(self._relations[i]['object']).search(cr, uid, where, context=context)
716 return [(self._arg[0], 'in', sarg)]
718 def _fnct_write(self,obj,cr, uid, ids, field_name, values, args, context=None):
719 if values and field_name:
720 self._field_get2(cr, uid, obj, context)
723 if type(ids) != type([]):
725 objlst = obj.browse(cr, uid, ids)
730 for i in range(len(self.arg)):
731 field_detail = self._relations[i]
732 relation = field_detail['object']
733 if not t_data[self.arg[i]]:
736 if field_detail['type'] in ('one2many', 'many2many'):
737 if self._type != "many2one":
739 t_data = t_data[self.arg[i]][0]
742 t_data = t_data[self.arg[i]]
744 obj.pool.get(field_detail['object']).write(cr,uid,[t_id],{args[-1]:values}, context=context)
746 def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None):
747 self._field_get2(cr, uid, obj, context)
748 if not ids: return {}
750 res = {}.fromkeys(ids, False)
752 objlst = obj.browse(cr, uid, ids, context=context)
758 for i in range(len(self.arg)):
759 field_detail = self._relations[i]
760 relation = field_detail['object']
762 if not t_data[self.arg[i]]:
768 if field_detail['type'] in ('one2many', 'many2many') and i != len(self.arg) - 1:
769 t_data = t_data[self.arg[i]][0]
771 t_data = t_data[self.arg[i]]
772 if type(t_data) == type(objlst[0]):
773 res[data.id] = t_data.id
775 res[data.id] = t_data
777 if self._type=='many2one':
778 ids = filter(None, res.values())
780 ng = dict(obj.pool.get(self._obj).name_get(cr, uid, ids, context=context))
783 res[r] = (res[r], ng[res[r]])
784 elif self._type in ('one2many', 'many2many'):
787 res[r] = [x.id for x in res[r]]
791 def __init__(self, *arg, **args):
794 super(related, self).__init__(self._fnct_read, arg, self._fnct_write, fnct_inv_arg=arg, method=True, fnct_search=self._fnct_search, **args)
795 if self.store is True:
796 # TODO: improve here to change self.store = {...} according to related objects
799 def _field_get2(self, cr, uid, obj, context={}):
803 for i in range(len(self._arg)):
804 f = obj.pool.get(obj_name).fields_get(cr, uid, [self._arg[i]], context=context)[self._arg[i]]
805 self._relations.append({
810 if f.get('relation',False):
811 obj_name = f['relation']
812 self._relations[-1]['relation'] = f['relation']
814 # ---------------------------------------------------------
816 # ---------------------------------------------------------
818 class dummy(function):
819 def _fnct_search(self, tobj, cr, uid, obj=None, name=None, domain=None, context={}):
822 def _fnct_write(self,obj,cr, uid, ids, field_name, values, args, context=None):
825 def _fnct_read(self, obj, cr, uid, ids, field_name, args, context=None):
828 def __init__(self, *arg, **args):
831 super(dummy, self).__init__(self._fnct_read, arg, self._fnct_write, fnct_inv_arg=arg, method=True, fnct_search=None, **args)
833 # ---------------------------------------------------------
835 # ---------------------------------------------------------
836 class serialized(_column):
837 def __init__(self, string='unknown', serialize_func=repr, deserialize_func=eval, type='text', **args):
838 self._serialize_func = serialize_func
839 self._deserialize_func = deserialize_func
841 self._symbol_set = (self._symbol_c, self._serialize_func)
842 self._symbol_get = self._deserialize_func
843 super(serialized, self).__init__(string=string, **args)
846 class property(function):
848 def _fnct_write(self, obj, cr, uid, id, prop, id_val, val, context=None):
852 definition_id = self._field_get(cr, uid, obj._name, prop)
854 property = obj.pool.get('ir.property')
855 nid = property.search(cr, uid, [('fields_id', '=', definition_id),
856 ('res_id', '=', obj._name+','+str(id))])
858 cr.execute('DELETE FROM ir_property WHERE id=%s', (nid.pop(),))
860 nid = property.search(cr, uid, [('fields_id', '=', definition_id),
861 ('res_id', '=', False)])
864 default_val = property.browse(cr, uid, nid[0], context).value
866 company_id = obj.pool.get('res.company')._company_default_get(cr, uid, obj._name, prop, context=context)
869 newval = (id_val and obj_dest+','+str(id_val)) or False
871 newval = id_val or False
872 if (newval != default_val) and newval:
873 propdef = obj.pool.get('ir.model.fields').browse(cr, uid,
874 definition_id, context=context)
875 res = property.create(cr, uid, {
876 'name': propdef.name,
878 'res_id': obj._name+','+str(id),
879 'company_id': company_id,
880 'fields_id': definition_id
884 def _fnct_read(self, obj, cr, uid, ids, prop, val, context=None):
887 property = obj.pool.get('ir.property')
888 definition_id = self._field_get(cr, uid, obj._name, prop)
890 nid = property.search(cr, uid, [('fields_id', '=', definition_id),
891 ('res_id', '=', False)])
894 d = property.browse(cr, uid, nid[0], context).value
895 default_val = (d and int(d.split(',')[1])) or False
897 vids = [obj._name + ',' + str(id) for id in ids]
898 nids = property.search(cr, uid, [('fields_id', '=', definition_id),
899 ('res_id', 'in', vids)])
903 res[id] = default_val
904 for prop in property.browse(cr, uid, nids):
905 if prop.value.find(',') >= 0:
906 res[int(prop.res_id.split(',')[1])] = (prop.value and \
907 int(prop.value.split(',')[1])) or False
909 res[int(prop.res_id.split(',')[1])] = prop.value or ''
912 obj = obj.pool.get(self._obj)
913 to_check = res.values()
914 if default_val and default_val not in to_check:
915 to_check += [default_val]
916 existing_ids = obj.search(cr, uid, [('id', 'in', to_check)])
917 for id, res_id in res.items():
918 if res_id not in existing_ids:
919 cr.execute('DELETE FROM ir_property WHERE value=%s', ((obj._name+','+str(res_id)),))
920 res[id] = default_val
921 names = dict(obj.name_get(cr, uid, existing_ids, context))
923 if res[r] and res[r] in names:
924 res[r] = (res[r], names[res[r]])
929 def _field_get(self, cr, uid, model_name, prop):
930 if not self.field_id.get(cr.dbname):
931 cr.execute('SELECT id \
932 FROM ir_model_fields \
933 WHERE name=%s AND model=%s', (prop, model_name))
935 self.field_id[cr.dbname] = res and res[0]
936 return self.field_id[cr.dbname]
938 def __init__(self, obj_prop, **args):
940 function.__init__(self, self._fnct_read, False, self._fnct_write,
941 (obj_prop, ), **args)
947 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: