Пример #1
0
    def __register__(cls, module_name):
        super(Inventory, cls).__register__(module_name)
        cursor = Transaction().cursor

        # Add index on create_date
        table = TableHandler(cursor, cls, module_name)
        table.index_action('create_date', action='add')
Пример #2
0
    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')
Пример #3
0
 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)
Пример #4
0
    def __register__(cls, module_name):
        Location = Pool().get("stock.location")
        cursor = Transaction().cursor

        table = TableHandler(cursor, cls, module_name)
        migrate_warehouse = not table.column_exist("warehouse") and table.column_exist("location")

        super(Forecast, cls).__register__(module_name)

        # Add index on create_date
        table = TableHandler(cursor, cls, module_name)
        table.index_action("create_date", action="add")

        if migrate_warehouse:
            location2warehouse = {}

            def find_warehouse(location):
                if location.type == "warehouse":
                    return location.id
                elif location.parent:
                    return find_warehouse(location.parent)

            cursor.execute('SELECT id, location FROM "%s"' % cls._table)
            for forecast_id, location_id in cursor.fetchall():
                warehouse_id = location_id  # default fallback
                if location_id in location2warehouse:
                    warehouse_id = location2warehouse[location_id]
                else:
                    location = Location(location_id)
                    warehouse_id = find_warehouse(location) or location_id
                    location2warehouse[location_id] = warehouse_id
                cursor.execute(
                    'UPDATE "%s" SET warehouse = %%s ' "WHERE id = %%s" % cls._table, (warehouse_id, forecast_id)
                )
            table.not_null_action("warehouse", action=cls.warehouse.required and "add" or "remove")
            table.drop_column("location", True)

        # Migration from 2.0 delete stock moves
        forecasts = cls.search([])
        cls.delete_moves(forecasts)
Пример #5
0
    def __register__(cls, module_name):
        super(ViewTreeExpandedState, cls).__register__(module_name)

        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)
        table.index_action(['model', 'domain', 'user', 'child_name'], 'add')
Пример #6
0
    def init(self, module_name):
        super(ViewTreeExpandedState, self).init(module_name)

        cursor = Transaction().cursor
        table = TableHandler(cursor, self, module_name)
        table.index_action(['model', 'domain', 'user', 'child_name'], 'add')
Пример #7
0
    def __register__(cls, module_name):
        super(Location, cls).__register__(module_name)
        cursor = Transaction().cursor

        table = TableHandler(cursor, cls, module_name)
        table.index_action(['left', 'right'], 'add')
Пример #8
0
    def __register__(cls, module_name):
        super(ViewTreeExpandedState, cls).__register__(module_name)

        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)
        table.index_action(["model", "domain", "user", "child_name"], "add")