[Fix] Set default value for current login user
lp bug: https://launchpad.net/bugs/780418 fixed bzr revid: vmt@openerp.com-20110517140410-1f3rlewsa5f4238r
This commit is contained in:
commit
6a189e8c96
|
@ -94,6 +94,7 @@
|
|||
'test/bug_lp541545.xml',
|
||||
'test/test_osv_expression.yml',
|
||||
'test/test_ir_rule.yml', # <-- These tests modify/add/delete ir_rules.
|
||||
'test/test_ir_values.yml',
|
||||
],
|
||||
'installable': True,
|
||||
'active': True,
|
||||
|
|
|
@ -172,8 +172,13 @@ 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.
|
||||
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,24 @@
|
|||
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[1] == 'my_test_ir_value'
|
||||
assert d[2] == 'global_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[1] == 'my_test_ir_value'
|
||||
assert d[2] == 'specific_value'
|
Loading…
Reference in New Issue