[MERGE] ir.values: make sure we return the user-specific default value.

bzr revid: vmt@openerp.com-20110523120940-9kgn9wxkzwbymrso
This commit is contained in:
Vo Minh Thu
2011-05-23 14:09:40 +02:00
3 changed files with 36 additions and 3 deletions
+2 -1
View File
@@ -94,7 +94,8 @@
'test/bug_lp541545.xml',
'test/test_osv_expression.yml',
'test/test_ir_rule.yml', # <-- These tests modify/add/delete ir_rules.
'test/test_config_users.yml'
'test/test_config_users.yml',
'test/test_ir_values.yml',
],
'installable': True,
'active': True,
+9 -2
View File
@@ -172,8 +172,15 @@ class ir_values(osv.osv):
else:
where.append('res_id=%s')
params.append(res_id)
where.append('(user_id=%s or (user_id IS NULL)) order by id')
order = 'id'
if key == 'default':
# Make sure we get first the values for specific users, then
# the global values. The map/filter below will retain the first
# value for any given name. The 'order by' will put the null
# values last; this may be postgres specific (it is the
# behavior in postgres at least since 8.2).
order = 'user_id'
where.append('(user_id=%s or (user_id IS NULL)) order by '+ order)
params.append(uid)
clause = ' and '.join(where)
cr.execute('select id,name,value,object,meta, key from ir_values where ' + clause, params)
@@ -0,0 +1,25 @@
-
Create some default value for some (non-existing) model, for all users.
-
!python {model: ir.values }: |
self.set(cr, uid, 'default', False, 'my_test_ir_value',['unexisting_model'], 'global value')
-
Retrieve it.
-
!python {model: ir.values }: |
# d is a list of triple (id, name, value)
d = self.get(cr, uid, 'default', False, ['unexisting_model'])
assert d[0][1] == u'my_test_ir_value', "Can't retrieve the created default value."
assert d[0][2] == 'global value', "Can't retrieve the created default value."
-
Do it again but for a specific user.
-
!python {model: ir.values }: |
self.set(cr, uid, 'default', False, 'my_test_ir_value',['unexisting_model'], 'specific value', preserve_user=True)
-
Retrieve it and check it is the one for the current user.
-
!python {model: ir.values }: |
d = self.get(cr, uid, 'default', False, ['unexisting_model'])
assert d[0][1] == u'my_test_ir_value', "Can't retrieve the created default value."
assert d[0][2] == 'specific value', "Can't retrieve the created default value."