import logging
import openupgradelib
_logger = logging.getLogger(__name__)

def migrate(cr, version):
    _logger.info('Migrating account_check from version %s' % version)

    cr.execute("""
INSERT INTO account_check (
 id, create_uid, create_date, write_date, write_uid,
 state, number, issue_date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, type,
 source_partner_id, destiny_partner_id,
 payment_date
)
SELECT id, create_uid, create_date, write_date, write_uid,
 state, CAST(number AS INT), date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, 'third',
 source_partner_id, destiny_partner_id,
 clearing_date
FROM account_third_check
        """)
    pass

import logging
import openupgradelib
_logger = logging.getLogger(__name__)

def migrate(cr, version):
    _logger.info('Migrating account_check from version %s' % version)

    cr.execute("""
INSERT INTO account_check (
 id, create_uid, create_date, write_date, write_uid,
 state, number, issue_date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, type,
 source_partner_id, destiny_partner_id,
 payment_date
)
SELECT id, create_uid, create_date, write_date, write_uid,
 state, CAST(number AS INT), date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, 'third',
 source_partner_id, destiny_partner_id,
 clearing_date
FROM account_third_check
        """)

    cr.execute("select max(id) FROM account_check")
    take_last_check = cr.fetchall()[0][0]
    cr.execute("ALTER SEQUENCE account_check_id_seq RESTART WITH %s;", (take_last_check,))

    pass

Set last id in sequence
[FIX] Set last id in sequence

  import logging
  import openupgradelib
  _logger = logging.getLogger(__name__)
  
  def migrate(cr, version):
      _logger.info('Migrating account_check from version %s' % version)
  
      cr.execute("""
  INSERT INTO account_check (
   id, create_uid, create_date, write_date, write_uid,
   state, number, issue_date, amount, company_id, user_id, voucher_id,
   clearing, bank_id, vat, type,
   source_partner_id, destiny_partner_id,
   payment_date
  )
  SELECT id, create_uid, create_date, write_date, write_uid,
   state, CAST(number AS INT), date, amount, company_id, user_id, voucher_id,
   clearing, bank_id, vat, 'third',
   source_partner_id, destiny_partner_id,
   clearing_date
  FROM account_third_check
          """)
+ 
+     cr.execute("select max(id) FROM account_check")
+     take_last_check = cr.fetchall()[0][0]
+     cr.execute("ALTER SEQUENCE account_check_id_seq RESTART WITH %s;", (take_last_check,))
+ 
      pass
  
Set last id in sequence
## Code Before:
import logging
import openupgradelib
_logger = logging.getLogger(__name__)

def migrate(cr, version):
    _logger.info('Migrating account_check from version %s' % version)

    cr.execute("""
INSERT INTO account_check (
 id, create_uid, create_date, write_date, write_uid,
 state, number, issue_date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, type,
 source_partner_id, destiny_partner_id,
 payment_date
)
SELECT id, create_uid, create_date, write_date, write_uid,
 state, CAST(number AS INT), date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, 'third',
 source_partner_id, destiny_partner_id,
 clearing_date
FROM account_third_check
        """)
    pass

## Instruction:
Set last id in sequence
## Code After:
import logging
import openupgradelib
_logger = logging.getLogger(__name__)

def migrate(cr, version):
    _logger.info('Migrating account_check from version %s' % version)

    cr.execute("""
INSERT INTO account_check (
 id, create_uid, create_date, write_date, write_uid,
 state, number, issue_date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, type,
 source_partner_id, destiny_partner_id,
 payment_date
)
SELECT id, create_uid, create_date, write_date, write_uid,
 state, CAST(number AS INT), date, amount, company_id, user_id, voucher_id,
 clearing, bank_id, vat, 'third',
 source_partner_id, destiny_partner_id,
 clearing_date
FROM account_third_check
        """)

    cr.execute("select max(id) FROM account_check")
    take_last_check = cr.fetchall()[0][0]
    cr.execute("ALTER SEQUENCE account_check_id_seq RESTART WITH %s;", (take_last_check,))

    pass
