fix: patches were breaking during migration (#27200)

* fix: patches were breaking during migrating

* fix: patches were breaking during migration
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 118f628..5ed4a19 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -1086,3 +1086,14 @@
 			db_or_cr_stock_adjustment_account : abs(amount)
 		}]
 	}
+
+def check_and_delete_linked_reports(report):
+	""" Check if reports are referenced in Desktop Icon """
+	icons = frappe.get_all("Desktop Icon",
+						fields = ['name'],
+						filters = {
+							"_report": report
+						})
+	if icons:
+		for icon in icons:
+			frappe.delete_doc("Desktop Icon", icon)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index ade19ff..05c385b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -299,4 +299,5 @@
 erpnext.patches.v13_0.reset_clearance_date_for_intracompany_payment_entries
 erpnext.patches.v13_0.einvoicing_deprecation_warning
 erpnext.patches.v14_0.delete_einvoicing_doctypes
-erpnext.patches.v13_0.set_operation_time_based_on_operating_cost
\ No newline at end of file
+erpnext.patches.v13_0.set_operation_time_based_on_operating_cost
+erpnext.patches.v13_0.validate_options_for_data_field
\ No newline at end of file
diff --git a/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py b/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py
index a6471eb..5c3fa59 100644
--- a/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py
+++ b/erpnext/patches/v12_0/move_item_tax_to_item_tax_template.py
@@ -91,8 +91,9 @@
 	item_tax_template.title = make_autoname("Item Tax Template-.####")
 
 	for tax_type, tax_rate in iteritems(item_tax_map):
-		account_details = frappe.db.get_value("Account", tax_type, ['name', 'account_type'], as_dict=1)
+		account_details = frappe.db.get_value("Account", tax_type, ['name', 'account_type', 'company'], as_dict=1)
 		if account_details:
+			item_tax_template.company = account_details.company
 			if account_details.account_type not in ('Tax', 'Chargeable', 'Income Account', 'Expense Account', 'Expenses Included In Valuation'):
 				frappe.db.set_value('Account', account_details.name, 'account_type', 'Chargeable')
 		else:
diff --git a/erpnext/patches/v13_0/delete_old_purchase_reports.py b/erpnext/patches/v13_0/delete_old_purchase_reports.py
index 360a82e..57620d3 100644
--- a/erpnext/patches/v13_0/delete_old_purchase_reports.py
+++ b/erpnext/patches/v13_0/delete_old_purchase_reports.py
@@ -4,6 +4,7 @@
 from __future__ import unicode_literals
 
 import frappe
+from erpnext.accounts.utils import check_and_delete_linked_reports
 
 def execute():
 	reports_to_delete = ["Requested Items To Be Ordered",
@@ -13,7 +14,7 @@
 	for report in reports_to_delete:
 		if frappe.db.exists("Report", report):
 			delete_auto_email_reports(report)
-			check_linked_reports(report)
+			check_and_delete_linked_reports(report)
 
 			frappe.delete_doc("Report", report)
 
@@ -22,13 +23,3 @@
 	auto_email_reports = frappe.db.get_values("Auto Email Report", {"report": report}, ["name"])
 	for auto_email_report in auto_email_reports:
 		frappe.delete_doc("Auto Email Report", auto_email_report[0])
-
-def check_linked_reports(report):
-	""" Check if reports are referenced in Desktop Icon """
-	icons = frappe.get_all("Desktop Icon",
-						fields = ['name'],
-						filters = {
-							"_report": report
-						})
-	if icons:
-		frappe.delete_doc("Desktop Icon", icons)
\ No newline at end of file
diff --git a/erpnext/patches/v13_0/delete_old_sales_reports.py b/erpnext/patches/v13_0/delete_old_sales_reports.py
index 69493e2..905a42c 100644
--- a/erpnext/patches/v13_0/delete_old_sales_reports.py
+++ b/erpnext/patches/v13_0/delete_old_sales_reports.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 
 import frappe
-from erpnext.patches.v13_0.delete_old_purchase_reports import check_linked_reports
+from erpnext.accounts.utils import check_and_delete_linked_reports
 
 def execute():
 	reports_to_delete = ["Ordered Items To Be Delivered", "Ordered Items To Be Billed"]
@@ -12,7 +12,7 @@
 	for report in reports_to_delete:
 		if frappe.db.exists("Report", report):
 			delete_auto_email_reports(report)
-			check_linked_reports(report)
+			check_and_delete_linked_reports(report)
 
 			frappe.delete_doc("Report", report)
 
diff --git a/erpnext/patches/v13_0/validate_options_for_data_field.py b/erpnext/patches/v13_0/validate_options_for_data_field.py
new file mode 100644
index 0000000..568d1a4
--- /dev/null
+++ b/erpnext/patches/v13_0/validate_options_for_data_field.py
@@ -0,0 +1,25 @@
+# Copyright (c) 2021, Frappe and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model import data_field_options 
+
+def execute():
+
+    for field in frappe.get_all('Custom Field', 
+                            fields = ['name'],
+                            filters = {
+                                'fieldtype': 'Data',
+                                'options': ['!=', None]
+                            }):
+
+        if field not in data_field_options:
+            frappe.db.sql("""
+                UPDATE 
+                    `tabCustom Field`
+                SET
+                    options=NULL
+                WHERE
+                    name=%s
+            """, (field))