Beispiel #1
0
    def test_in(self):
        for in_ in [
                In(self.table.c1, [self.table.c2, 1, Null]),
                ~NotIn(self.table.c1, [self.table.c2, 1, Null]),
                ~~In(self.table.c1, [self.table.c2, 1, Null])
        ]:
            self.assertEqual(str(in_), '("c1" IN ("c2", %s, %s))')
            self.assertEqual(in_.params, (1, None))

        t2 = Table('t2')
        in_ = In(self.table.c1, t2.select(t2.c2))
        self.assertEqual(str(in_),
                         '("c1" IN (SELECT "a"."c2" FROM "t2" AS "a"))')
        self.assertEqual(in_.params, ())

        in_ = In(self.table.c1, t2.select(t2.c2) | t2.select(t2.c3))
        self.assertEqual(
            str(in_), '("c1" IN (SELECT "a"."c2" FROM "t2" AS "a" '
            'UNION SELECT "a"."c3" FROM "t2" AS "a"))')
        self.assertEqual(in_.params, ())

        in_ = In(self.table.c1, array('l', range(10)))
        self.assertEqual(str(in_),
                         '("c1" IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s))')
        self.assertEqual(in_.params, tuple(range(10)))
Beispiel #2
0
 def uninstall(cls, modules):
     pool = Pool()
     Module = pool.get('ir.module')
     Dependency = pool.get('ir.module.dependency')
     module_table = Module.__table__()
     dep_table = Dependency.__table__()
     cursor = Transaction().connection.cursor()
     for module in modules:
         cursor.execute(*dep_table.join(module_table,
                 condition=(dep_table.module == module_table.id)
                 ).select(module_table.state, module_table.name,
                 where=(dep_table.name == module.name)
                 & NotIn(module_table.state, ['uninstalled', 'to remove'])))
         res = cursor.fetchall()
         if res:
             cls.raise_user_error('uninstall_dep',
                     error_description='\n'.join(
                         '\t%s: %s' % (x[0], x[1]) for x in res))
     cls.write(modules, {'state': 'to remove'})
Beispiel #3
0
 def deactivate(cls, modules):
     pool = Pool()
     Module = pool.get('ir.module')
     Dependency = pool.get('ir.module.dependency')
     module_table = Module.__table__()
     dep_table = Dependency.__table__()
     cursor = Transaction().connection.cursor()
     for module in modules:
         cursor.execute(*dep_table.join(module_table,
                 condition=(dep_table.module == module_table.id)
                 ).select(module_table.state, module_table.name,
                 where=(dep_table.name == module.name)
                 & NotIn(
                     module_table.state, ['not activated', 'to remove'])))
         res = cursor.fetchall()
         if res:
             raise DeactivateDependencyError(
                 gettext('ir.msg_module_deactivate_dependency'),
                 '\n'.join('\t%s: %s' % (x[0], x[1]) for x in res))
     cls.write(modules, {'state': 'to remove'})