import xhiveframework


def execute():
	# handle type casting for is_cancelled field
	module_doctypes = (
		("stock", "Stock Ledger Entry"),
		("stock", "Serial No"),
		("accounts", "GL Entry"),
	)

	for module, doctype in module_doctypes:
		if (
			not xhiveframework.db.has_column(doctype, "is_cancelled")
			or xhiveframework.db.get_column_type(doctype, "is_cancelled").lower() == "int(1)"
		):
			continue

		xhiveframework.db.sql(
			"""
				UPDATE `tab{doctype}`
				SET is_cancelled = 0
				where is_cancelled in ('', 'No') or is_cancelled is NULL""".format(
				doctype=doctype
			)
		)
		xhiveframework.db.sql(
			"""
				UPDATE `tab{doctype}`
				SET is_cancelled = 1
				where is_cancelled = 'Yes'""".format(
				doctype=doctype
			)
		)

		xhiveframework.reload_doc(module, "doctype", xhiveframework.scrub(doctype))
