~openerp-groupes/openobject-server/6.0-fix-setup-windows

« back to all changes in this revision

Viewing changes to bin/addons/base/res/ir_property.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-3f10ee12cea3c4c75cef44ab04ad33ef47432907
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting from its eventual inadequacies and bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees and support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it and/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
 
 
29
from osv import osv,fields
 
30
 
 
31
# -------------------------------------------------------------------------
 
32
# Properties
 
33
# -------------------------------------------------------------------------
 
34
 
 
35
def _models_get2(self, cr, uid, context={}):
 
36
        obj = self.pool.get('ir.model.fields')
 
37
        ids = obj.search(cr, uid, [('view_load','=',1)])
 
38
        res = []
 
39
        done = {}
 
40
        for o in obj.browse(cr, uid, ids, context=context):
 
41
                if o.relation not in done:
 
42
                        res.append( [o.relation, o.relation])
 
43
                        done[o.relation] = True
 
44
        return res
 
45
 
 
46
def _models_get(self, cr, uid, context={}):
 
47
        obj = self.pool.get('ir.model.fields')
 
48
        ids = obj.search(cr, uid, [('view_load','=',1)])
 
49
        res = []
 
50
        done = {}
 
51
        for o in obj.browse(cr, uid, ids, context=context):
 
52
                if o.model_id.id not in done:
 
53
                        res.append( [o.model_id.model, o.model_id.name])
 
54
                        done[o.model_id.id] = True
 
55
        return res
 
56
 
 
57
class ir_property(osv.osv):
 
58
        _name = 'ir.property'
 
59
        _columns = {
 
60
                'name': fields.char('Name', size=128),
 
61
                'value': fields.reference('Value', selection=_models_get2, size=128),
 
62
                'res_id': fields.reference('Resource', selection=_models_get, size=128),
 
63
                'company_id': fields.many2one('res.company', 'Company'),
 
64
                'fields_id': fields.many2one('ir.model.fields', 'Fields', ondelete='cascade', required=True)
 
65
        }
 
66
        def get(self, cr, uid, name, model, res_id=False, context={}):
 
67
                cr.execute('select id from ir_model_fields where name=%s and model=%s', (name, model))
 
68
                res = cr.fetchone()
 
69
                if res:
 
70
                        nid = self.search(cr, uid, [('fields_id','=',res[0]),('res_id','=',res_id)])
 
71
                        if nid:
 
72
                                d = self.browse(cr, uid, nid[0], context).value
 
73
                                return (d and int(d.split(',')[1])) or False
 
74
                return False
 
75
ir_property()
 
76
 
 
77