fix(patch): check if column is present while fixing reverse linking (#30737)

diff --git a/erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py b/erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py
index edd0a97..45acf49 100644
--- a/erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py
+++ b/erpnext/patches/v13_0/patch_to_fix_reverse_linking_in_additional_salary_encashment_and_incentive.py
@@ -10,54 +10,58 @@
 
 	frappe.reload_doc("hr", "doctype", "Leave Encashment")
 
-	additional_salaries = frappe.get_all(
-		"Additional Salary",
-		fields=["name", "salary_slip", "type", "salary_component"],
-		filters={"salary_slip": ["!=", ""]},
-		group_by="salary_slip",
-	)
-	leave_encashments = frappe.get_all(
-		"Leave Encashment",
-		fields=["name", "additional_salary"],
-		filters={"additional_salary": ["!=", ""]},
-	)
-	employee_incentives = frappe.get_all(
-		"Employee Incentive",
-		fields=["name", "additional_salary"],
-		filters={"additional_salary": ["!=", ""]},
-	)
-
-	for incentive in employee_incentives:
-		frappe.db.sql(
-			""" UPDATE `tabAdditional Salary`
-			SET ref_doctype = 'Employee Incentive', ref_docname = %s
-			WHERE name = %s
-		""",
-			(incentive["name"], incentive["additional_salary"]),
+	if frappe.db.has_column("Leave Encashment", "additional_salary"):
+		leave_encashments = frappe.get_all(
+			"Leave Encashment",
+			fields=["name", "additional_salary"],
+			filters={"additional_salary": ["!=", ""]},
 		)
-
-	for leave_encashment in leave_encashments:
-		frappe.db.sql(
-			""" UPDATE `tabAdditional Salary`
-			SET ref_doctype = 'Leave Encashment', ref_docname = %s
-			WHERE name = %s
-		""",
-			(leave_encashment["name"], leave_encashment["additional_salary"]),
-		)
-
-	salary_slips = [sal["salary_slip"] for sal in additional_salaries]
-
-	for salary in additional_salaries:
-		comp_type = "earnings" if salary["type"] == "Earning" else "deductions"
-		if salary["salary_slip"] and salary_slips.count(salary["salary_slip"]) == 1:
+		for leave_encashment in leave_encashments:
 			frappe.db.sql(
-				"""
-				UPDATE `tabSalary Detail`
-				SET additional_salary = %s
-				WHERE parenttype = 'Salary Slip'
-					and parentfield = %s
-					and parent = %s
-					and salary_component = %s
+				""" UPDATE `tabAdditional Salary`
+				SET ref_doctype = 'Leave Encashment', ref_docname = %s
+				WHERE name = %s
 			""",
-				(salary["name"], comp_type, salary["salary_slip"], salary["salary_component"]),
+				(leave_encashment["name"], leave_encashment["additional_salary"]),
 			)
+
+	if frappe.db.has_column("Employee Incentive", "additional_salary"):
+		employee_incentives = frappe.get_all(
+			"Employee Incentive",
+			fields=["name", "additional_salary"],
+			filters={"additional_salary": ["!=", ""]},
+		)
+
+		for incentive in employee_incentives:
+			frappe.db.sql(
+				""" UPDATE `tabAdditional Salary`
+				SET ref_doctype = 'Employee Incentive', ref_docname = %s
+				WHERE name = %s
+			""",
+				(incentive["name"], incentive["additional_salary"]),
+			)
+
+	if frappe.db.has_column("Additional Salary", "salary_slip"):
+		additional_salaries = frappe.get_all(
+			"Additional Salary",
+			fields=["name", "salary_slip", "type", "salary_component"],
+			filters={"salary_slip": ["!=", ""]},
+			group_by="salary_slip",
+		)
+
+		salary_slips = [sal["salary_slip"] for sal in additional_salaries]
+
+		for salary in additional_salaries:
+			comp_type = "earnings" if salary["type"] == "Earning" else "deductions"
+			if salary["salary_slip"] and salary_slips.count(salary["salary_slip"]) == 1:
+				frappe.db.sql(
+					"""
+					UPDATE `tabSalary Detail`
+					SET additional_salary = %s
+					WHERE parenttype = 'Salary Slip'
+						and parentfield = %s
+						and parent = %s
+						and salary_component = %s
+				""",
+					(salary["name"], comp_type, salary["salary_slip"], salary["salary_component"]),
+				)