import sys


def migrate(cr, version):
    reload(sys)
    sys.setdefaultencoding('UTF8')

    if not version:
        return
    delay_dict = {'annual': 12, 'biannual': 6, 'fourmonthly': 4,
                  'quarterly': 3, 'bimonthly': 2, 'monthly': 1}
    cr.execute(
        '''
        SELECT id, advance_billing FROM recurring_contract_group
        '''
    )

    contract_groups = cr.fetchall()

    for contract_group in contract_groups:
        delay = delay_dict[contract_group[1]] or 1
        cr.execute(
            '''
            UPDATE recurring_contract_group
            SET recurring_value = {0}, advance_billing_months = {0}
            WHERE id = {1}
            '''.format(delay, contract_group[0])

        )

import sys


def migrate(cr, version):
    reload(sys)
    sys.setdefaultencoding('UTF8')

    if not version:
        return
    delay_dict = {'annual': 12, 'biannual': 6, 'fourmonthly': 4,
                  'quarterly': 3, 'bimonthly': 2, 'monthly': 1}
    cr.execute(
        '''
        SELECT id, advance_billing FROM recurring_contract_group
        '''
    )

    contract_groups = cr.fetchall()

    for contract_group in contract_groups:
        delay = delay_dict[contract_group[1]] or 1
        cr.execute(
            '''
            UPDATE recurring_contract_group
            SET advance_billing_months = {0}
            WHERE id = {1}
            '''.format(delay, contract_group[0])

        )

Remove wrong migration of contracts.
Remove wrong migration of contracts.

  import sys
  
  
  def migrate(cr, version):
      reload(sys)
      sys.setdefaultencoding('UTF8')
  
      if not version:
          return
      delay_dict = {'annual': 12, 'biannual': 6, 'fourmonthly': 4,
                    'quarterly': 3, 'bimonthly': 2, 'monthly': 1}
      cr.execute(
          '''
          SELECT id, advance_billing FROM recurring_contract_group
          '''
      )
  
      contract_groups = cr.fetchall()
  
      for contract_group in contract_groups:
          delay = delay_dict[contract_group[1]] or 1
          cr.execute(
              '''
              UPDATE recurring_contract_group
-             SET recurring_value = {0}, advance_billing_months = {0}
+             SET advance_billing_months = {0}
              WHERE id = {1}
              '''.format(delay, contract_group[0])
  
          )
  
Remove wrong migration of contracts.
## Code Before:
import sys


def migrate(cr, version):
    reload(sys)
    sys.setdefaultencoding('UTF8')

    if not version:
        return
    delay_dict = {'annual': 12, 'biannual': 6, 'fourmonthly': 4,
                  'quarterly': 3, 'bimonthly': 2, 'monthly': 1}
    cr.execute(
        '''
        SELECT id, advance_billing FROM recurring_contract_group
        '''
    )

    contract_groups = cr.fetchall()

    for contract_group in contract_groups:
        delay = delay_dict[contract_group[1]] or 1
        cr.execute(
            '''
            UPDATE recurring_contract_group
            SET recurring_value = {0}, advance_billing_months = {0}
            WHERE id = {1}
            '''.format(delay, contract_group[0])

        )

## Instruction:
Remove wrong migration of contracts.
## Code After:
import sys


def migrate(cr, version):
    reload(sys)
    sys.setdefaultencoding('UTF8')

    if not version:
        return
    delay_dict = {'annual': 12, 'biannual': 6, 'fourmonthly': 4,
                  'quarterly': 3, 'bimonthly': 2, 'monthly': 1}
    cr.execute(
        '''
        SELECT id, advance_billing FROM recurring_contract_group
        '''
    )

    contract_groups = cr.fetchall()

    for contract_group in contract_groups:
        delay = delay_dict[contract_group[1]] or 1
        cr.execute(
            '''
            UPDATE recurring_contract_group
            SET advance_billing_months = {0}
            WHERE id = {1}
            '''.format(delay, contract_group[0])

        )
