import xhiveframework


def execute():

	xhiveframework.reload_doctype("Opportunity")
	if xhiveframework.db.has_column("Opportunity", "enquiry_from"):
		xhiveframework.db.sql(
			""" UPDATE `tabOpportunity` set opportunity_from = enquiry_from
			where ifnull(opportunity_from, '') = '' and ifnull(enquiry_from, '') != ''"""
		)

	if xhiveframework.db.has_column("Opportunity", "lead") and xhiveframework.db.has_column(
		"Opportunity", "enquiry_from"
	):
		xhiveframework.db.sql(
			""" UPDATE `tabOpportunity` set party_name = lead
			where enquiry_from = 'Lead' and ifnull(party_name, '') = '' and ifnull(lead, '') != ''"""
		)

	if xhiveframework.db.has_column("Opportunity", "customer") and xhiveframework.db.has_column(
		"Opportunity", "enquiry_from"
	):
		xhiveframework.db.sql(
			""" UPDATE `tabOpportunity` set party_name = customer
			 where enquiry_from = 'Customer' and ifnull(party_name, '') = '' and ifnull(customer, '') != ''"""
		)
