Пример #1
0
    def __register__(cls, module_name):
        """Migrations

        :param module_name: Module Name (Automatically passed by caller)
        """
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        # Drop the required index on methods
        table.not_null_action('methods', action="remove")

        # Rename methods to old_methods
        table.column_rename('methods', 'old_methods')

        # Check if the new boolean fields exist
        http_method_fields_exists = table.column_exist('http_method_get')

        super(URLRule, cls).__register__(module_name)

        if not http_method_fields_exists:
            # if the http method fields did not exist before this method
            # should transition old_methods to the boolean fields
            rules = cls.search([])
            for rule in rules:
                cls.set_methods([rule.id], 'methods', rule.old_methods)
Пример #2
0
    def __register__(cls, module_name):
        TimesheetWork = Pool().get('timesheet.work')
        cursor = Transaction().cursor
        table_project_work = TableHandler(cursor, cls, module_name)
        table_timesheet_work = TableHandler(cursor, TimesheetWork, module_name)
        migrate_sequence = (not table_project_work.column_exist('sequence')
            and table_timesheet_work.column_exist('sequence'))

        super(Work, cls).__register__(module_name)

        # Migration from 2.0: copy sequence from timesheet to project
        if migrate_sequence:
            cursor.execute(
                'SELECT t.sequence, t.id '
                'FROM "%s" AS t '
                'JOIN "%s" AS p ON (p.work = t.id)' % (
                    TimesheetWork._table, cls._table))
            for sequence, id_ in cursor.fetchall():
                sql = ('UPDATE "%s" '
                    'SET sequence = %%s '
                    'WHERE work = %%s' % cls._table)
                cursor.execute(sql, (sequence, id_))

        # Migration from 2.4: drop required on sequence
        table_project_work.not_null_action('sequence', action='remove')
Пример #3
0
    def __register__(cls, module_name):
        """Migrations

        :param module_name: Module Name (Automatically passed by caller)
        """
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        # Drop the required index on methods
        table.not_null_action('methods', action="remove")

        # Rename methods to old_methods
        table.column_rename('methods', 'old_methods')

        # Check if the new boolean fields exist
        http_method_fields_exists = table.column_exist('http_method_get')

        super(URLRule, cls).__register__(module_name)

        if not http_method_fields_exists:
            # if the http method fields did not exist before this method
            # should transition old_methods to the boolean fields
            rules = cls.search([])
            for rule in rules:
                cls.set_methods([rule.id], 'methods', rule.old_methods)
Пример #4
0
    def __register__(cls, module_name):
        super(User, cls).__register__(module_name)
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        # Migration from 1.6
        table.not_null_action('dashboard_layout', action='remove')
Пример #5
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        super(DashboardAction, cls).__register__(module_name)

        # Migration from 2.4: drop required on sequence
        table.not_null_action('sequence', action='remove')
Пример #6
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        super(SaleOpportunityLine, cls).__register__(module_name)

        # Migration from 2.4: drop required on sequence
        table.not_null_action('sequence', action='remove')
Пример #7
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        super(ProductLocation, cls).__register__(module_name)

        # Migration from 2.4: drop required on sequence
        table.not_null_action("sequence", action="remove")
Пример #8
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor

        super(Period, cls).__register__(module_name)

        table = TableHandler(cursor, cls, module_name)
        # Migration from 2.6: post_move_sequence is no longer required
        table.not_null_action('post_move_sequence', 'remove')
Пример #9
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')
Пример #10
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor

        super(Template, cls).__register__(module_name)

        table = TableHandler(cursor, cls, module_name)
        # Migration from 2.2: category is no more required
        table.not_null_action('category', 'remove')

        # Migration from 2.2: new types
        cursor.execute('UPDATE "' + cls._table + '" '
            'SET consumable = %s WHERE type = %s', (True, 'consumable'))
        cursor.execute('UPDATE "' + cls._table + '" '
            'SET type = %s WHERE type IN (%s, %s)',
            ('goods', 'stockable', 'consumable'))
Пример #11
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        # Migration from 2.4 arch moved into data
        if table.column_exist("arch"):
            table.column_rename("arch", "data")

        super(View, cls).__register__(module_name)

        # Migration from 1.0 arch no more required
        table.not_null_action("arch", action="remove")

        # Migration from 2.4 model no more required
        table.not_null_action("model", action="remove")
Пример #12
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        # Migration from 2.4 arch moved into data
        if table.column_exist('arch'):
            table.column_rename('arch', 'data')

        super(View, cls).__register__(module_name)

        # Migration from 1.0 arch no more required
        table.not_null_action('arch', action='remove')

        # Migration from 2.4 model no more required
        table.not_null_action('model', action='remove')
Пример #13
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor
        reference_exists = True
        if TableHandler.table_exist(cursor, cls._table):
            table = TableHandler(cursor, cls, module_name)
            reference_exists = table.column_exist('reference')
        super(SaleOpportunity, cls).__register__(module_name)
        table = TableHandler(cursor, cls, module_name)

        # Migration from 2.8: make party not required and add reference as
        # required
        table.not_null_action('party', action='remove')
        if not reference_exists:
            cursor.execute('UPDATE "' + cls._table +
                           '" SET reference=id WHERE '
                           'reference IS NULL')
            table.not_null_action('reference', action='add')
Пример #14
0
    def __register__(cls, module_name):
        super(PaymentTermLine, cls).__register__(module_name)
        cursor = Transaction().cursor
        table = TableHandler(cursor, cls, module_name)

        # Migration from 1.0 percent change into percentage
        if table.column_exist("percent"):
            cursor.execute('UPDATE "' + cls._table + '" ' "SET percentage = percent * 100")
            table.drop_column("percent", exception=True)

        # Migration from 2.2
        if table.column_exist("delay"):
            cursor.execute('UPDATE "' + cls._table + '" SET day = 31 ' "WHERE delay = 'end_month'")
            table.drop_column("delay", exception=True)
            lines = cls.search([])
            for line in lines:
                if line.percentage:
                    cls.write([line], {"divisor": cls.round(Decimal("100.0") / line.percentage, cls.divisor.digits[1])})

        # Migration from 2.4: drop required on sequence
        table.not_null_action("sequence", action="remove")
Пример #15
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)
Пример #16
0
    def __register__(cls, module_name):
        cursor = Transaction().cursor

        # Migration from 1.8: new field company
        table = TableHandler(cursor, cls, module_name)
        company_exist = table.column_exist('company')

        super(Statement, cls).__register__(module_name)

        # Migration from 1.8: fill new field company
        if not company_exist:
            offset = 0
            limit = cursor.IN_MAX
            statements = True
            while statements:
                statements = cls.search([], offset=offset, limit=limit)
                offset += limit
                for statement in statements:
                    cls.write([statement], {
                            'company': statement.journal.company.id,
                            })
            table = TableHandler(cursor, cls, module_name)
            table.not_null_action('company', action='add')
Пример #17
0
    def init(self, module_name):
        super(View, self).init(module_name)
        table = TableHandler(Transaction().cursor, self, module_name)

        # Migration from 1.0 arch no more required
        table.not_null_action('arch', action='remove')