Server IP : 127.0.0.2 / Your IP : 3.144.181.40 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/odoo/addons/base/tests/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.tests.common import TransactionCase class TestIrValues(TransactionCase): def test_00(self): # Create some default value for some (non-existing) model, for all users. ir_values = self.env['ir.values'] # use the old API ir_values.set_default('unexisting_model', 'my_test_field', 'global value', condition=False) # use the new API ir_values.set_default('other_unexisting_model', 'my_other_test_field', 'conditional value', condition='foo=bar') # Retrieve them. # d is a list of triplets (id, name, value) # Old API d = ir_values.get_defaults('unexisting_model', condition=False) self.assertEqual(len(d), 1, "Only one single value should be retrieved for this model") self.assertEqual(d[0][1], 'my_test_field', "Can't retrieve the created default value. (1)") self.assertEqual(d[0][2], 'global value', "Can't retrieve the created default value. (2)") # New API, Conditional version d = ir_values.get_defaults('other_unexisting_model') self.assertEqual(len(d), 0, "No value should be retrieved, the condition is not met") d = ir_values.get_defaults('other_unexisting_model', condition="foo=eggs") self.assertEqual(len(d), 0, 'Condition is not met either, no defaults should be returned') d = ir_values.get_defaults('other_unexisting_model', condition="foo=bar") self.assertEqual(len(d), 1, "Only one single value should be retrieved") self.assertEqual(d[0][1], 'my_other_test_field', "Can't retrieve the created default value. (5)") self.assertEqual(d[0][2], 'conditional value', "Can't retrieve the created default value. (6)") # Do it again but for a specific user. ir_values.set_default('unexisting_model', 'my_test_field', 'specific value', for_all_users=False, condition=False) # Retrieve it and check it is the one for the current user. d = ir_values.get_defaults('unexisting_model', condition=False) self.assertEqual(len(d), 1, "Only one default must be returned per field") self.assertEqual(d[0][1], 'my_test_field', "Can't retrieve the created default value.") self.assertEqual(d[0][2], 'specific value', "Can't retrieve the created default value.") # Create some action bindings for a non-existing model. act_id_1 = self.ref('base.act_values_form_action') act_id_2 = self.ref('base.act_values_form_defaults') act_id_3 = self.ref('base.action_res_company_form') ir_values.set_action('OnDblClick Action', action_slot='tree_but_open', model='unexisting_model', action='ir.actions.act_window,%d' % act_id_1, res_id=False) ir_values.set_action('OnDblClick Action 2', action_slot='tree_but_open', model='unexisting_model', action='ir.actions.act_window,%d' % act_id_2, res_id=False) ir_values.set_action('Side Wizard', action_slot='client_action_multi', model='unexisting_model', action='ir.actions.act_window,%d' % act_id_3, res_id=False) reports = self.env['ir.actions.report.xml'].search([]) report_id = next(report.id for report in reports if not report.groups_id) ir_values.set_action('Nice Report', action_slot='client_print_multi', model='unexisting_model', action='ir.actions.report.xml,%d' % report_id, res_id=False) # Replace one action binding to set a new name. ir_values.set_action('OnDblClick Action New', action_slot='tree_but_open', model='unexisting_model', action='ir.actions.act_window,%d' % act_id_1, res_id=False) # Retrieve the action bindings and check they're correct actions = ir_values.get_actions(action_slot='tree_but_open', model='unexisting_model', res_id=False) self.assertEqual(len(actions), 2, "Mismatching number of bound actions") #first action self.assertEqual(len(actions[0]), 3, "Malformed action definition") self.assertEqual(actions[0][1], 'OnDblClick Action 2', 'Bound action does not match definition') self.assertTrue(isinstance(actions[0][2], dict) and actions[0][2]['id'] == act_id_2, 'Bound action does not match definition') #second action - this ones comes last because it was re-created with a different name self.assertEqual(len(actions[1]), 3, "Malformed action definition") self.assertEqual(actions[1][1], 'OnDblClick Action New', 'Re-Registering an action should replace it') self.assertTrue(isinstance(actions[1][2], dict) and actions[1][2]['id'] == act_id_1, 'Bound action does not match definition') actions = ir_values.get_actions(action_slot='client_action_multi', model='unexisting_model', res_id=False) self.assertEqual(len(actions), 1, "Mismatching number of bound actions") self.assertEqual(len(actions[0]), 3, "Malformed action definition") self.assertEqual(actions[0][1], 'Side Wizard', 'Bound action does not match definition') self.assertTrue(isinstance(actions[0][2], dict) and actions[0][2]['id'] == act_id_3, 'Bound action does not match definition') actions = ir_values.get_actions(action_slot='client_print_multi', model='unexisting_model', res_id=False) self.assertEqual(len(actions), 1, "Mismatching number of bound actions") self.assertEqual(len(actions[0]), 3, "Malformed action definition") self.assertEqual(actions[0][1], 'Nice Report', 'Bound action does not match definition') self.assertTrue(isinstance(actions[0][2], dict) and actions[0][2]['id'] == report_id, 'Bound action does not match definition')