Use string for selection on fields instead of function
- View cache works without clean the cache - Allow override the function without modify the field
This commit is contained in:
1 parent
4f0b048248
commit
eaf8d9853e
9 files changed
+100
-103
No files matched your search
+9
-10
@@ -46,15 +46,6 @@ class ActionKeyword(OSV):
|
||||
"Action keyword"
|
||||
_name = 'ir.action.keyword'
|
||||
_description = __doc__
|
||||
|
||||
def _models_get(self, cursor, user, context=None):
|
||||
model_obj = self.pool.get('ir.model')
|
||||
model_ids = model_obj.search(cursor, user, [])
|
||||
res = []
|
||||
for model in model_obj.browse(cursor, user, model_ids, context=context):
|
||||
res.append([model.model, model.name])
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'keyword': fields.Selection([
|
||||
('tree_open', 'Open tree'),
|
||||
@@ -63,7 +54,7 @@ class ActionKeyword(OSV):
|
||||
('form_action', 'Action form'),
|
||||
('form_relate', 'Form relate'),
|
||||
], string='Keyword', required=True),
|
||||
'model': fields.Reference('Model', selection=_models_get, size=128),
|
||||
'model': fields.Reference('Model', selection='models_get', size=128),
|
||||
'action': fields.many2one('ir.action', 'Action',
|
||||
ondelete='CASCADE'),
|
||||
}
|
||||
@@ -76,6 +67,14 @@ class ActionKeyword(OSV):
|
||||
vals['action'], context=context)
|
||||
return vals
|
||||
|
||||
def models_get(self, cursor, user, context=None):
|
||||
model_obj = self.pool.get('ir.model')
|
||||
model_ids = model_obj.search(cursor, user, [])
|
||||
res = []
|
||||
for model in model_obj.browse(cursor, user, model_ids, context=context):
|
||||
res.append([model.model, model.name])
|
||||
return res
|
||||
|
||||
def unlink(self, cursor, user, ids, context=None):
|
||||
for keyword in self.browse(cursor, user, ids, context=context):
|
||||
# Restart the cache view
|
||||
|
||||
+10
-11
@@ -6,8 +6,16 @@ class Property(OSV):
|
||||
"Property"
|
||||
_name = 'ir.property'
|
||||
_description = __doc__
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128),
|
||||
'value': fields.reference('Value', selection='models_get2', size=128),
|
||||
'res_id': fields.reference('Resource', selection='models_get', size=128),
|
||||
#'company_id': fields.many2one('res.company', 'Company'),
|
||||
'fields_id': fields.many2one('ir.model.fields', 'Fields',
|
||||
ondelete='cascade', required=True)
|
||||
}
|
||||
|
||||
def _models_get2(self, cursor, user, context=None):
|
||||
def models_get2(self, cursor, user, context=None):
|
||||
model_fields_obj = self.pool.get('ir.model.fields')
|
||||
ids = model_fields_obj.search(cursor, user, [('view_load', '=', 1)])
|
||||
res = []
|
||||
@@ -19,7 +27,7 @@ class Property(OSV):
|
||||
done[model_field.relation] = True
|
||||
return res
|
||||
|
||||
def _models_get(self, cursor, user, context=None):
|
||||
def models_get(self, cursor, user, context=None):
|
||||
model_fields_obj = self.pool.get('ir.model.fields')
|
||||
ids = model_fields_obj.search(cursor, user, [('view_load', '=', 1)])
|
||||
res = []
|
||||
@@ -32,15 +40,6 @@ class Property(OSV):
|
||||
done[model_field.model_id.id] = True
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128),
|
||||
'value': fields.reference('Value', selection=_models_get2, size=128),
|
||||
'res_id': fields.reference('Resource', selection=_models_get, size=128),
|
||||
#'company_id': fields.many2one('res.company', 'Company'),
|
||||
'fields_id': fields.many2one('ir.model.fields', 'Fields',
|
||||
ondelete='cascade', required=True)
|
||||
}
|
||||
|
||||
def unlink(self, cursor, user, ids, context=None):
|
||||
if ids:
|
||||
cursor.execute('DELETE FROM ir_model_fields ' \
|
||||
|
||||
+17
-18
@@ -56,8 +56,24 @@ class Rule(OSV):
|
||||
_name = 'ir.rule'
|
||||
_rec_name = 'field_id'
|
||||
_description = __doc__
|
||||
_columns = {
|
||||
'field_id': fields.many2one('ir.model.fields', 'Field',
|
||||
domain="[('model_id','=', parent.model_id)]", select=1,
|
||||
required=True),
|
||||
'operator':fields.selection([
|
||||
('=', '='),
|
||||
('<>', '<>'),
|
||||
('<=', '<='),
|
||||
('>=', '>='),
|
||||
('in', 'in'),
|
||||
('child_of', 'child_of'),
|
||||
], 'Operator', required=True),
|
||||
'operand':fields.selection('operand','Operand', size=64, required=True),
|
||||
'rule_group': fields.many2one('ir.rule.group', 'Group', select=2,
|
||||
required=True, ondelete="cascade")
|
||||
}
|
||||
|
||||
def _operand(self, cursor, user, context):
|
||||
def operand(self, cursor, user, context):
|
||||
|
||||
def get(obj_name, level=3, recur=None, root_tech='', root=''):
|
||||
res = []
|
||||
@@ -93,23 +109,6 @@ class Rule(OSV):
|
||||
recur=['many2one'], root_tech='user', root='User')
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'field_id': fields.many2one('ir.model.fields', 'Field',
|
||||
domain="[('model_id','=', parent.model_id)]", select=1,
|
||||
required=True),
|
||||
'operator':fields.selection([
|
||||
('=', '='),
|
||||
('<>', '<>'),
|
||||
('<=', '<='),
|
||||
('>=', '>='),
|
||||
('in', 'in'),
|
||||
('child_of', 'child_of'),
|
||||
], 'Operator', required=True),
|
||||
'operand':fields.selection(_operand,'Operand', size=64, required=True),
|
||||
'rule_group': fields.many2one('ir.rule.group', 'Group', select=2,
|
||||
required=True, ondelete="cascade")
|
||||
}
|
||||
|
||||
def domain_get(self, cursor, user, model_name):
|
||||
# root user above constraint
|
||||
if user == 1:
|
||||
|
||||
@@ -18,14 +18,9 @@ class Sequence(OSV):
|
||||
"Sequence"
|
||||
_name = 'ir.sequence'
|
||||
_description = __doc__
|
||||
|
||||
def _code_get(self, cursor, user, context=None):
|
||||
cursor.execute('select code, name from ir_sequence_type')
|
||||
return cursor.fetchall()
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Sequence Name',size=64, required=True),
|
||||
'code': fields.selection(_code_get, 'Sequence Code',size=64,
|
||||
'code': fields.selection('code_get', 'Sequence Code',size=64,
|
||||
required=True),
|
||||
'active': fields.boolean('Active'),
|
||||
'prefix': fields.char('Prefix',size=64),
|
||||
@@ -41,6 +36,10 @@ class Sequence(OSV):
|
||||
'padding' : lambda *a : 0,
|
||||
}
|
||||
|
||||
def code_get(self, cursor, user, context=None):
|
||||
cursor.execute('select code, name from ir_sequence_type')
|
||||
return cursor.fetchall()
|
||||
|
||||
def _process(self, string):
|
||||
return (string or '') % {
|
||||
'year':time.strftime('%Y'),
|
||||
|
||||
+21
-23
@@ -30,13 +30,6 @@ class Translation(OSV, Cacheable):
|
||||
_name = "ir.translation"
|
||||
_description = __doc__
|
||||
|
||||
def _get_language(self, cursor, user, context):
|
||||
lang_obj = self.pool.get('ir.lang')
|
||||
lang_ids = lang_obj.search(cursor, user, [], context=context)
|
||||
langs = lang_obj.browse(cursor, user, lang_ids, context=context)
|
||||
res = [(lang.code, lang.name) for lang in langs]
|
||||
return res
|
||||
|
||||
def _model(self, cursor, user, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for translation in self.browse(cursor, user, ids, context=context):
|
||||
@@ -57,7 +50,7 @@ class Translation(OSV, Cacheable):
|
||||
_columns = {
|
||||
'name': fields.Char('Field Name', size=128, required=True),
|
||||
'res_id': fields.Integer('Resource ID'),
|
||||
'lang': fields.Selection(_get_language, string='Language', size=5),
|
||||
'lang': fields.Selection('get_language', string='Language', size=5),
|
||||
'type': fields.Selection(TRANSLATION_TYPE, string='Type', size=16,
|
||||
required=True),
|
||||
'src': fields.Text('Source'),
|
||||
@@ -79,6 +72,13 @@ class Translation(OSV, Cacheable):
|
||||
CREATE INDEX ir_translation_res_id ON ir_translation (res_id);
|
||||
"""
|
||||
|
||||
def get_language(self, cursor, user, context):
|
||||
lang_obj = self.pool.get('ir.lang')
|
||||
lang_ids = lang_obj.search(cursor, user, [], context=context)
|
||||
langs = lang_obj.browse(cursor, user, lang_ids, context=context)
|
||||
res = [(lang.code, lang.name) for lang in langs]
|
||||
return res
|
||||
|
||||
def _get_ids(self, cursor, name, ttype, lang, ids):
|
||||
translations, to_fetch = {}, []
|
||||
if name.split(',')[0] == 'ir.model.fields':
|
||||
@@ -364,8 +364,12 @@ class TranslationUpdateInit(WizardOSV):
|
||||
"Update translation - language"
|
||||
_name = 'ir.translation.update.init'
|
||||
_description = __doc__
|
||||
_columns = {
|
||||
'lang': fields.Selection('get_language', string='Language', size=5,
|
||||
required=True),
|
||||
}
|
||||
|
||||
def _get_language(self, cursor, user, context):
|
||||
def get_language(self, cursor, user, context):
|
||||
lang_obj = self.pool.get('ir.lang')
|
||||
lang_ids = lang_obj.search(cursor, user, [('translatable', '=', True)],
|
||||
context=context)
|
||||
@@ -373,11 +377,6 @@ class TranslationUpdateInit(WizardOSV):
|
||||
res = [(lang.code, lang.name) for lang in langs if lang.code != 'en_US']
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'lang': fields.Selection(_get_language, string='Language', size=5,
|
||||
required=True),
|
||||
}
|
||||
|
||||
TranslationUpdateInit()
|
||||
|
||||
|
||||
@@ -489,15 +488,21 @@ class TranslationExportInit(WizardOSV):
|
||||
"Export translation - language and module"
|
||||
_name = 'ir.translation.export.init'
|
||||
_description = __doc__
|
||||
_columns = {
|
||||
'lang': fields.Selection('get_language', string='Language', size=5,
|
||||
required=True),
|
||||
'module': fields.Selection('get_module', string='Module', size=128,
|
||||
required=True),
|
||||
}
|
||||
|
||||
def _get_language(self, cursor, user, context):
|
||||
def get_language(self, cursor, user, context):
|
||||
lang_obj = self.pool.get('ir.lang')
|
||||
lang_ids = lang_obj.search(cursor, user, [], context=context)
|
||||
langs = lang_obj.browse(cursor, user, lang_ids, context=context)
|
||||
res = [(lang.code, lang.name) for lang in langs]
|
||||
return res
|
||||
|
||||
def _get_module(self, cursor, user, context):
|
||||
def get_module(self, cursor, user, context):
|
||||
module_obj = self.pool.get('ir.module.module')
|
||||
module_ids = module_obj.search(cursor, user, [], context=context)
|
||||
modules = module_obj.browse(cursor, user, module_ids, context=context)
|
||||
@@ -505,13 +510,6 @@ class TranslationExportInit(WizardOSV):
|
||||
for module in modules]
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'lang': fields.Selection(_get_language, string='Language', size=5,
|
||||
required=True),
|
||||
'module': fields.Selection(_get_module, string='Module', size=128,
|
||||
required=True),
|
||||
}
|
||||
|
||||
TranslationExportInit()
|
||||
|
||||
|
||||
|
||||
@@ -184,6 +184,10 @@ class Selection(_column):
|
||||
_type = 'selection'
|
||||
|
||||
def __init__(self, selections, string='unknown', **args):
|
||||
"""
|
||||
selections is a list of (key, string)
|
||||
or the name of the object function that return the list
|
||||
"""
|
||||
_column.__init__(self, string=string, **args)
|
||||
self.selection = selections
|
||||
|
||||
|
||||
+7
-6
@@ -1376,8 +1376,9 @@ class ORM(object):
|
||||
'is not in the selection' % \
|
||||
(val, field))
|
||||
else:
|
||||
if val not in dict(self._columns[field].selection(
|
||||
self, cursor, user, context=context)):
|
||||
if val not in dict(getattr(self,
|
||||
self._columns[field].selection)(
|
||||
cursor, user, context=context)):
|
||||
raise ExceptORM('ValidateError',
|
||||
'The value "%s" for the field "%s" ' \
|
||||
'is not in the selection' % \
|
||||
@@ -1538,8 +1539,9 @@ class ORM(object):
|
||||
'is not in the selection' % \
|
||||
(val, field))
|
||||
else:
|
||||
if val not in dict(self._columns[field].selection(
|
||||
self, cursor, user, context=context)):
|
||||
if val not in dict(getattr(self,
|
||||
self._columns[field].selection)(
|
||||
cursor, user, context=context)):
|
||||
raise ExceptORM('ValidateError',
|
||||
'The value "%s" for the field "%s" ' \
|
||||
'is not in the selection' % \
|
||||
@@ -1627,8 +1629,7 @@ class ORM(object):
|
||||
res[field]['selection'] = sel
|
||||
else:
|
||||
# call the 'dynamic selection' function
|
||||
res[field]['selection'] = self._columns[field].selection(
|
||||
self, cursor, user, context)
|
||||
res[field]['selection'] = self._columns[field].selection
|
||||
if res[field]['type'] in (
|
||||
'one2many',
|
||||
'many2many',
|
||||
|
||||
+9
-10
@@ -7,14 +7,6 @@ class Request(OSV):
|
||||
_name = 'res.request'
|
||||
_table = 'res_request'
|
||||
_description = __doc__
|
||||
|
||||
def _links_get(self, cursor, user, context=None):
|
||||
request_link_obj = self.pool.get('res.request.link')
|
||||
ids = request_link_obj.search(cursor, user, [])
|
||||
request_links = request_link_obj.browse(cursor, user, ids,
|
||||
context=context)
|
||||
return [(x.object, x.name) for x in request_links]
|
||||
|
||||
_columns = {
|
||||
'create_date': fields.DateTime('Created date', readonly=True),
|
||||
'name': fields.Char('Subject', states={
|
||||
@@ -48,11 +40,11 @@ class Request(OSV):
|
||||
# 'closed': [('readonly', True)],
|
||||
# }),
|
||||
#TODO: use one2many instead limit number of reference
|
||||
'ref_doc1': fields.Reference('Document Ref 1', selection=_links_get,
|
||||
'ref_doc1': fields.Reference('Document Ref 1', selection='links_get',
|
||||
size=128, states={
|
||||
'readonly': "state == 'closed'",
|
||||
}),
|
||||
'ref_doc2': fields.Reference('Document Ref 2', selection=_links_get,
|
||||
'ref_doc2': fields.Reference('Document Ref 2', selection='links_get',
|
||||
size=128, states={
|
||||
'readonly': "state == 'closed'",
|
||||
}),
|
||||
@@ -73,6 +65,13 @@ class Request(OSV):
|
||||
}
|
||||
_order = 'priority DESC, trigger_date, create_date DESC'
|
||||
|
||||
def links_get(self, cursor, user, context=None):
|
||||
request_link_obj = self.pool.get('res.request.link')
|
||||
ids = request_link_obj.search(cursor, user, [])
|
||||
request_links = request_link_obj.browse(cursor, user, ids,
|
||||
context=context)
|
||||
return [(x.object, x.name) for x in request_links]
|
||||
|
||||
def request_send(self, cursor, user, ids, context=None):
|
||||
request_history_obj = self.pool.get('res.request.history')
|
||||
for request in self.browse(cursor, user, ids, context=context):
|
||||
|
||||
+18
-19
@@ -62,23 +62,6 @@ class User(OSV):
|
||||
_name = "res.user"
|
||||
_log_access = False
|
||||
_description = __doc__
|
||||
|
||||
def _languages(self, cursor, user, context=None):
|
||||
lang_obj = self.pool.get('ir.lang')
|
||||
lang_ids = lang_obj.search(cursor, user, [], context=context)
|
||||
res = []
|
||||
for lang in lang_obj.browse(cursor, user, lang_ids, context=context):
|
||||
res.append([lang.code, lang.name])
|
||||
return res
|
||||
|
||||
def _timezones(self, cursor, user, context=None):
|
||||
try:
|
||||
import pytz
|
||||
res = [[x, x] for x in pytz.all_timezones]
|
||||
except ImportError:
|
||||
res = [[time.tzname[0], time.tzname[0]]]
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.Char('Name', size=64, required=True, select=1),
|
||||
'login': fields.Char('Login', size=64, required=True),
|
||||
@@ -96,8 +79,8 @@ class User(OSV):
|
||||
'rule_groups': fields.Many2Many('ir.rule.group', 'user_rule_group_rel',
|
||||
'user_id', 'rule_group_id', 'Rules',
|
||||
domain="[('global', '<>', True)]"),
|
||||
'language': fields.Selection(_languages, 'Language'),
|
||||
'timezone': fields.Selection(_timezones, 'Timezone'),
|
||||
'language': fields.Selection('languages', 'Language'),
|
||||
'timezone': fields.Selection('timezones', 'Timezone'),
|
||||
}
|
||||
_sql_constraints = [
|
||||
('login_key', 'UNIQUE (login)',
|
||||
@@ -214,6 +197,22 @@ class User(OSV):
|
||||
res['fields'] = fields
|
||||
return res
|
||||
|
||||
def languages(self, cursor, user, context=None):
|
||||
lang_obj = self.pool.get('ir.lang')
|
||||
lang_ids = lang_obj.search(cursor, user, [], context=context)
|
||||
res = []
|
||||
for lang in lang_obj.browse(cursor, user, lang_ids, context=context):
|
||||
res.append([lang.code, lang.name])
|
||||
return res
|
||||
|
||||
def timezones(self, cursor, user, context=None):
|
||||
try:
|
||||
import pytz
|
||||
res = [[x, x] for x in pytz.all_timezones]
|
||||
except ImportError:
|
||||
res = [[time.tzname[0], time.tzname[0]]]
|
||||
return res
|
||||
|
||||
User()
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user