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


import influxframework


def execute():

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

	if influxframework.db.has_column("Bank", "branch_code") and influxframework.db.has_column(
		"Bank Account", "branch_code"
	):
		influxframework.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, '') = ''"""
		)
