import xhiveframework


def execute():
	xhiveframework.reload_doc("accounts", "doctype", "bank", force=1)

	if (
		xhiveframework.db.table_exists("Bank")
		and xhiveframework.db.table_exists("Bank Account")
		and xhiveframework.db.has_column("Bank Account", "swift_number")
	):
		try:
			xhiveframework.db.sql(
				"""
				UPDATE `tabBank` b, `tabBank Account` ba
				SET b.swift_number = ba.swift_number WHERE b.name = ba.bank
			"""
			)
		except Exception as e:
			xhiveframework.log_error("Bank to Bank Account patch migration failed")

	xhiveframework.reload_doc("accounts", "doctype", "bank_account")
	xhiveframework.reload_doc("accounts", "doctype", "payment_request")
