1
# -*- coding: utf-8 -*-
2
from openerp.osv import orm, fields
4
def selection_fn(obj, cr, uid, context=None):
5
return list(enumerate(["Corge", "Grault", "Wheee", "Moog"]))
7
def function_fn(model, cr, uid, ids, field_name, arg, context):
8
return dict((id, 3) for id in ids)
9
def function_fn_write(model, cr, uid, id, field_name, field_value, fnct_inv_arg, context):
10
""" just so CreatorCase.export can be used
15
('boolean', fields.boolean()),
16
('integer', fields.integer()),
17
('float', fields.float()),
18
('decimal', fields.float(digits=(16, 3))),
19
('string.bounded', fields.char('unknown', size=16)),
20
('string.required', fields.char('unknown', size=None, required=True)),
21
('string', fields.char('unknown', size=None)),
22
('date', fields.date()),
23
('datetime', fields.datetime()),
24
('text', fields.text()),
25
('selection', fields.selection([(1, "Foo"), (2, "Bar"), (3, "Qux"), (4, '')])),
26
('selection.function', fields.selection(selection_fn)),
27
# just relate to an integer
28
('many2one', fields.many2one('export.integer')),
29
('one2many', fields.one2many('export.one2many.child', 'parent_id')),
30
('many2many', fields.many2many('export.many2many.other')),
31
('function', fields.function(function_fn, fnct_inv=function_fn_write, type="integer")),
32
# related: specialization of fields.function, should work the same way
35
for name, field in models:
37
'_name': 'export.%s' % name,
39
'const': fields.integer(),
42
'_defaults': {'const': 4},
43
'name_get': (lambda self, cr, uid, ids, context=None:
44
[(record.id, "%s:%s" % (self._name, record.value))
45
for record in self.browse(cr, uid, ids, context=context)]),
46
'name_search': (lambda self, cr, uid, name, operator, context=None:
47
self.name_get(cr, uid,
48
self.search(cr, uid, [['value', operator, int(name.split(':')[1])]])
50
if isinstance(name, basestring) and name.split(':')[0] == self._name
54
'Export%s' % ''.join(section.capitalize() for section in name.split('.')),
58
class One2ManyChild(orm.Model):
59
_name = 'export.one2many.child'
60
# FIXME: orm.py:1161, fix to name_get on m2o field
64
'parent_id': fields.many2one('export.one2many'),
65
'str': fields.char('unknown', size=None),
66
'value': fields.integer()
68
def name_get(self, cr, uid, ids, context=None):
69
return [(record.id, "%s:%s" % (self._name, record.value))
70
for record in self.browse(cr, uid, ids, context=context)]
71
def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
72
return (self.name_get(cr, user,
73
self.search(cr, user, [['value', operator, int(name.split(':')[1])]])
75
if isinstance(name, basestring) and name.split(':')[0] == self._name
78
class One2ManyMultiple(orm.Model):
79
_name = 'export.one2many.multiple'
82
'const': fields.integer(),
83
'child1': fields.one2many('export.one2many.child.1', 'parent_id'),
84
'child2': fields.one2many('export.one2many.child.2', 'parent_id'),
86
_defaults = { 'const': 36 }
88
class One2ManyChildMultiple(orm.Model):
89
_name = 'export.one2many.multiple.child'
90
# FIXME: orm.py:1161, fix to name_get on m2o field
94
'parent_id': fields.many2one('export.one2many.multiple'),
95
'str': fields.char('unknown', size=None),
96
'value': fields.integer()
98
def name_get(self, cr, uid, ids, context=None):
99
return [(record.id, "%s:%s" % (self._name, record.value))
100
for record in self.browse(cr, uid, ids, context=context)]
101
class One2ManyChild1(orm.Model):
102
_name = 'export.one2many.child.1'
103
_inherit = 'export.one2many.multiple.child'
104
class One2ManyChild2(orm.Model):
105
_name = 'export.one2many.child.2'
106
_inherit = 'export.one2many.multiple.child'
108
class Many2ManyChild(orm.Model):
109
_name = 'export.many2many.other'
110
# FIXME: orm.py:1161, fix to name_get on m2o field
114
'str': fields.char('unknown', size=None),
115
'value': fields.integer()
117
def name_get(self, cr, uid, ids, context=None):
118
return [(record.id, "%s:%s" % (self._name, record.value))
119
for record in self.browse(cr, uid, ids, context=context)]
120
def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=100):
121
return (self.name_get(cr, user,
122
self.search(cr, user, [['value', operator, int(name.split(':')[1])]])
124
if isinstance(name, basestring) and name.split(':')[0] == self._name
127
class SelectionWithDefault(orm.Model):
128
_name = 'export.selection.withdefault'
131
'const': fields.integer(),
132
'value': fields.selection([(1, "Foo"), (2, "Bar")]),