def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 1.2: packing renamed into shipment table = TableHandler(cursor, cls, module_name) table.drop_constraint('check_packing') for suffix in ('in', 'out', 'in_return', 'out_return', 'internal'): old_column = 'packing_%s' % suffix new_column = 'shipment_%s' % suffix if table.column_exist(old_column): table.index_action(old_column, action='remove') table.drop_fk(old_column) table.column_rename(old_column, new_column) # Migration from 1.8: new field internal_quantity internal_quantity_exist = table.column_exist('internal_quantity') super(Move, cls).__register__(module_name) # Migration from 1.8: fill new field internal_quantity if not internal_quantity_exist: offset = 0 limit = cursor.IN_MAX moves = True while moves: moves = cls.search([], offset=offset, limit=limit) offset += limit for move in moves: internal_quantity = cls._get_internal_quantity( move.quantity, move.uom, move.product) cursor.execute( 'UPDATE "' + cls._table + '" ' 'SET internal_quantity = %s ' 'WHERE id = %s', (internal_quantity, move.id)) table = TableHandler(cursor, cls, module_name) table.not_null_action('internal_quantity', action='add') # Migration from 1.0 check_packing_in_out has been removed table = TableHandler(cursor, cls, module_name) table.drop_constraint('check_packing_in_out') # Migration from 2.6: merge all shipments table.drop_constraint('check_shipment') shipments = { 'shipment_in': 'stock.shipment.in', 'shipment_out': 'stock.shipment.out', 'shipment_out_return': 'stock.shipment.out.return', 'shipment_in_return': 'stock.shipment.in.return', 'shipment_internal': 'stock.shipment.internal', } for column, model in shipments.iteritems(): if table.column_exist(column): cursor.execute('UPDATE "' + cls._table + '" ' 'SET shipment = \'' + model + ',\' || "' + column + '" ' 'WHERE "' + column + '" IS NOT NULL') table.drop_column(column) # Add index on create_date table.index_action('create_date', action='add')
def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 1.6 product renamed into category table = TableHandler(cursor, cls) if table.column_exist('product'): table.index_action('product', action='remove') table.drop_fk('product') table.column_rename('product', 'category') super(CategorySupplierTax, cls).__register__(module_name)