def __register__(cls, module): connection = Transaction().connection cursor = connection.cursor() super().__register__(module) table_h = cls.__table_handler__(module) template_lot_type_table_name = config.get( 'table', 'product.template-stock.lot.type', default='product.template-stock.lot.type'.replace('.', '_')) lot_type_table_name = config.get('table', 'stock.lot.type', default='stock.lot.type'.replace( '.', '_')) # Migration from 5.2: fill lot_required if (table_h.table_exist(template_lot_type_table_name) and table_h.table_exist(lot_type_table_name)): table = cls.__table__() template_lot_type = Table(template_lot_type_table_name) lot_type = Table(lot_type_table_name) cursor_select = connection.cursor() cursor_select.execute(*template_lot_type.select( template_lot_type.template, distinct_on=template_lot_type.template)) for template_id, in cursor_select: cursor.execute(*template_lot_type.join( lot_type, condition=template_lot_type.type == lot_type.id ).select(lot_type.code, where=template_lot_type.template == template_id)) value = cls.lot_required.sql_format([t for t, in cursor]) cursor.execute(*table.update([table.lot_required], [value], where=table.id == template_id)) table_h.drop_table('product.template-stock.lot.type', template_lot_type_table_name) table_h.drop_table('stock.lot.type', lot_type_table_name)
def setup_model(cls): connection = Transaction().connection if backend.Database().get_version(connection) < (9, 2): return pool = Pool() for model in ['test.multi_selection', 'test.multi_selection_required']: Model = pool.get(model) cursor = connection.cursor() for name, field in Model._fields.items(): if field._type == 'multiselection': cursor.execute('ALTER TABLE "%s" ' 'ALTER COLUMN %s TYPE json USING %s::json' % (Model._table, name, name)) Transaction().commit()
def _deactivate_extension(cls): connection = Transaction().connection cursor = connection.cursor() cursor.execute('DROP EXTENSION "unaccent"') connection.commit() cls._clear_unaccent_cache()
def _activate_extension(cls): connection = Transaction().connection cursor = connection.cursor() cursor.execute('CREATE EXTENSION "%s"' % cls.extension) connection.commit() cls._clear_cache()