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')
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')
def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 2.2 table = TableHandler(cursor, cls, module_name) table.drop_constraint('check_min_max_quantity') super(OrderPoint, cls).__register__(module_name)
def __register__(cls, module_name): table = TableHandler(Transaction().cursor, cls, module_name) # Migrate from 2.2 remove name table.drop_column('name') super(ModuleConfigWizardItem, cls).__register__(module_name)
def init(self, module_name): table = TableHandler(Transaction().cursor, self, module_name) # Migrate from 2.2 remove name table.drop_column('name') super(ModuleConfigWizardItem, self).init(module_name)
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')
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")
def init(self, module_name): super(ProjectWork, self).init(module_name) cursor = Transaction().cursor table = TableHandler(cursor, self, module_name) log.debug(table) if table.column_exist('billable'): log.debug("drop billable from table") table.drop_column('billable', exception=True)
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')
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')
def __register__(cls, module_name): super(Surgery, cls).__register__(module_name) cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Rename the date column to surgery_surgery_date if table.column_exist('date'): table.column_rename('date', 'surgery_date')
def __register__(cls, module_name): cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) if not table.column_exist('uuid'): table.add_raw_column('uuid', FIELDS[cls.uuid._type].sql_type(cls.uuid), FIELDS[cls.uuid._type].sql_format, None, None) cursor.execute('SELECT id FROM "' + cls._table + '"') for id, in cursor.fetchall(): cursor.execute('UPDATE "' + cls._table + '" ' 'SET "uuid" = %s WHERE id = %s', (cls.default_uuid(), id)) super(Party, cls).__register__(module_name)
def __register__(cls, module_name): cursor = Transaction().cursor super(TodoAlarm, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.alarm if table.column_exist('calendar_alarm'): cursor.execute('UPDATE "' + cls._table + '" AS t ' 'SET valarm = (SELECT a.valarm ' 'FROM calendar_alarm AS a ' 'WHERE a.id = t.calendar_alarm)') table.drop_column('calendar_alarm', True)
def __register__(cls, module_name): super(Journal, cls).__register__(module_name) cursor = Transaction().cursor table = TableHandler(cursor, cls, module_name) # Migration from 1.0 sequence Many2One change into Property if table.column_exist('sequence'): Property = Pool().get('ir.property') cursor.execute('SELECT id, sequence FROM "' + cls._table + '"') with Transaction().set_user(0): for journal_id, sequence_id in cursor.fetchall(): Property.set('sequence', cls._name, journal_id, (sequence_id and 'ir.sequence,' + str(sequence_id) or False)) table.drop_column('sequence', exception=True)
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'))
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)
def __register__(cls, module_name): cursor = Transaction().cursor super(TodoAttendee, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.attendee if table.column_exist('calendar_attendee'): cursor.execute('UPDATE "' + cls._table + '" AS e ' 'SET email = (SELECT a.email ' 'FROM calendar_attendee AS a ' 'WHERE a.id = e.calendar_attendee), ' 'status = (SELECT a.status ' 'FROM calendar_attendee AS a ' 'WHERE a.id = e.calendar_attendee)') table.drop_column('calendar_attendee', True)
def __register__(cls, module_name): cursor = Transaction().cursor super(TodoRRule, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.rrule if table.column_exist('calendar_rrule'): for field in (f for f in dir(RRuleMixin) if isinstance(f, fields.Field)): cursor.execute(('UPDATE "' + cls._table + '" AS e ' 'SET "%(field)s" = (SELECT a."%(field)s" ' 'FROM calendar_rrule AS r ' 'WHERE r.id = e.calendar_rrule)') % {'field': field}) table.drop_column('calendar_rrule', True)
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')
def __register__(cls, module_name): cursor = Transaction().cursor super(InvoiceLine, cls).__register__(module_name) # Migration from 2.6: remove sale_lines rel_table = 'sale_line_invoice_lines_rel' if TableHandler.table_exist(cursor, rel_table): cursor.execute('SELECT sale_line, invoice_line ' 'FROM "' + rel_table + '"') for sale_line, invoice_line in cursor.fetchall(): cursor.execute('UPDATE "' + cls._table + '" ' 'SET origin = %s ' 'WHERE id = %s', ('sale.line,%s' % sale_line, invoice_line)) TableHandler.drop_table(cursor, 'sale.line-account.invoice.line', rel_table)
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)
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')
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)
def init(self, module_name): cursor = Transaction().cursor super(BalanceProductGoodsBalance, self).init(module_name) table = TableHandler(cursor, self, module_name) # Проверяем счетчик cursor.execute("SELECT last_value, increment_by FROM %s"%table.sequence_name) last_value, increment_by = cursor.fetchall()[0] # Устанавливаем счетчик if str(last_value)[len(str(last_value))-1] != str(_ID_TABLES_BALANCES_PERIOD[self._table]): cursor.execute("SELECT setval('"+table.sequence_name+"', %s, true)"%_ID_TABLES_BALANCES_PERIOD[self._table]) if increment_by != 10: cursor.execute("ALTER SEQUENCE "+table.sequence_name+" INCREMENT 10")
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")
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')
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')
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")
def __register__(cls, module_name): cursor = Transaction().cursor # Migration from 1.4: calendar_rdate renamed to calendar_date table = TableHandler(cursor, cls, module_name) old_column = 'calendar_rdate' if table.column_exist(old_column): table.column_rename(old_column, 'calendar_date') super(TodoRDate, cls).__register__(module_name) table = TableHandler(cursor, cls, module_name) # Migration from 2.6: Remove inherits calendar.date if table.column_exist('calendar_date'): cursor.execute('UPDATE "' + cls._table + '" AS e ' 'SET date = (SELECT a.date ' 'FROM calendar_date AS a ' 'WHERE a.id = e.calendar_date), ' 'datetime = (SELECT a.datetime ' 'FROM calendar_date AS a ' 'WHERE a.id = e.calendar_date)') table.drop_column('calendar_date', True)
def init(self, module_name): super(PaymentTermLine, self).init(module_name) cursor = Transaction().cursor table = TableHandler(cursor, self, module_name)
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')
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')
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')
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')