import xhiveframework
from xhiveframework.utils import cint


def execute():
	"""Get 'Disable CWIP Accounting value' from Asset Settings, set it in 'Enable Capital Work in Progress Accounting' field
	in Company, delete Asset Settings"""

	if xhiveframework.db.exists("DocType", "Asset Settings"):
		xhiveframework.reload_doctype("Asset Category")
		cwip_value = xhiveframework.db.get_single_value("Asset Settings", "disable_cwip_accounting")

		xhiveframework.db.sql("""UPDATE `tabAsset Category` SET enable_cwip_accounting = %s""", cint(cwip_value))

		xhiveframework.db.sql("""DELETE FROM `tabSingles` where doctype = 'Asset Settings'""")
		xhiveframework.delete_doc_if_exists("DocType", "Asset Settings")
