import influxframework


def execute():

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

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

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