Create some default value for some (non-existing) model, for all users.
-
!python {model: ir.values }: |
+ # use the old API
self.set(cr, uid, 'default', False, 'my_test_field',['unexisting_model'], 'global value')
+ # use the new API
+ self.set_default(cr, uid, 'other_unexisting_model', 'my_other_test_field', 'conditional value', condition='foo=bar')
-
- Retrieve it.
+ Retrieve them.
-
!python {model: ir.values }: |
- # d is a list of triple (id, name, value)
+ # d is a list of triplets (id, name, value)
+ # Old API
d = self.get(cr, uid, 'default', False, ['unexisting_model'])
- assert d[0][1] == 'my_test_field', "Can't retrieve the created default value."
- assert d[0][2] == 'global value', "Can't retrieve the created default value."
+ assert len(d) == 1, "Only one single value should be retrieved for this model"
+ assert d[0][1] == 'my_test_field', "Can't retrieve the created default value. (1)"
+ assert d[0][2] == 'global value', "Can't retrieve the created default value. (2)"
+
+ # New API, Conditional version
+ d = self.get_defaults(cr, uid, 'other_unexisting_model')
+ assert len(d) == 0, "No value should be retrieved, the condition is not met"
+ d = self.get_defaults(cr, uid, 'other_unexisting_model', condition="foo=eggs")
+ assert len(d) == 0, 'Condition is not met either, no defaults should be returned'
+ d = self.get_defaults(cr, uid, 'other_unexisting_model', condition="foo=bar")
+ assert len(d) == 1, "Only one single value should be retrieved"
+ assert d[0][1] == 'my_other_test_field', "Can't retrieve the created default value. (5)"
+ assert d[0][2] == 'conditional value', "Can't retrieve the created default value. (6)"
-
Do it again but for a specific user.
-