# Copyright (c) 2019, Xhiveframework and Contributors
# License: GNU General Public License v3. See license.txt


import xhiveframework


def execute():

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

	if xhiveframework.db.has_column("Bank", "branch_code") and xhiveframework.db.has_column(
		"Bank Account", "branch_code"
	):
		xhiveframework.db.sql(
			"""UPDATE `tabBank` b, `tabBank Account` ba
			SET ba.branch_code = b.branch_code
			WHERE ba.bank = b.name AND
			ifnull(b.branch_code, '') != '' AND ifnull(ba.branch_code, '') = ''"""
		)
