from odoo import api, SUPERUSER_ID
from openupgradelib import openupgrade


def _rename_cagnotte(env):
    columns = {
        "sale_order_line": [
            ("account_cagnotte_id", "account_wallet_id"),
        ],
    }
    openupgrade.rename_columns(env.cr, columns)


def pre_init_hook(cr):
    with api.Environment.manage():
        env = api.Environment(cr, SUPERUSER_ID, {})
        _rename_cagnotte(env)

from odoo import api, SUPERUSER_ID
from openupgradelib import openupgrade


def _rename_cagnotte(env):
    if not openupgrade.column_exists(
            env.cr, "sale_order_line", "account_cagnotte_id"):
        return
    columns = {
        "sale_order_line": [
            ("account_cagnotte_id", "account_wallet_id"),
        ],
    }
    openupgrade.rename_columns(env.cr, columns)


def pre_init_hook(cr):
    with api.Environment.manage():
        env = api.Environment(cr, SUPERUSER_ID, {})
        _rename_cagnotte(env)

Migrate only if former column exist
[14.0][IMP] account_wallet_sale: Migrate only if former column exist

  from odoo import api, SUPERUSER_ID
  from openupgradelib import openupgrade
  
  
  def _rename_cagnotte(env):
+     if not openupgrade.column_exists(
+             env.cr, "sale_order_line", "account_cagnotte_id"):
+         return
      columns = {
          "sale_order_line": [
              ("account_cagnotte_id", "account_wallet_id"),
          ],
      }
      openupgrade.rename_columns(env.cr, columns)
  
  
  def pre_init_hook(cr):
      with api.Environment.manage():
          env = api.Environment(cr, SUPERUSER_ID, {})
          _rename_cagnotte(env)
  
Migrate only if former column exist
## Code Before:
from odoo import api, SUPERUSER_ID
from openupgradelib import openupgrade


def _rename_cagnotte(env):
    columns = {
        "sale_order_line": [
            ("account_cagnotte_id", "account_wallet_id"),
        ],
    }
    openupgrade.rename_columns(env.cr, columns)


def pre_init_hook(cr):
    with api.Environment.manage():
        env = api.Environment(cr, SUPERUSER_ID, {})
        _rename_cagnotte(env)

## Instruction:
Migrate only if former column exist
## Code After:
from odoo import api, SUPERUSER_ID
from openupgradelib import openupgrade


def _rename_cagnotte(env):
    if not openupgrade.column_exists(
            env.cr, "sale_order_line", "account_cagnotte_id"):
        return
    columns = {
        "sale_order_line": [
            ("account_cagnotte_id", "account_wallet_id"),
        ],
    }
    openupgrade.rename_columns(env.cr, columns)


def pre_init_hook(cr):
    with api.Environment.manage():
        env = api.Environment(cr, SUPERUSER_ID, {})
        _rename_cagnotte(env)
