import frappe

def execute():
    """Remove old won_lost_html field if it exists"""

    # Remove old HTML field
    if frappe.db.exists("Custom Field", {"dt": "Sales Invoice", "fieldname": "won_lost_html"}):
        try:
            custom_field_name = frappe.db.get_value("Custom Field",
                {"dt": "Sales Invoice", "fieldname": "won_lost_html"}, "name")
            frappe.delete_doc("Custom Field", custom_field_name)
            frappe.db.commit()
            print("Deleted old won_lost_html field")
        except Exception as e:
            print(f"Failed to delete won_lost_html: {e}")

    print("Cleanup completed")
