fix(patch): handle duplicate entry error while inserting account (#22745)

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 8889056..06331d7 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
@@ -100,8 +100,10 @@
 				tax_type = None
 			else:
 				company = get_company(parts[-1], parenttype, parent)
-				parent_account = frappe.db.get_value("Account",
-					filters={"account_type": "Tax", "root_type": "Liability", "is_group": 0, "company": company}, fieldname="parent_account")
+				parent_account = frappe.get_value("Account", {"account_name": account_name, "company": company}, "parent_account")
+				if not parent_account:
+					parent_account = frappe.db.get_value("Account",
+						filters={"account_type": "Tax", "root_type": "Liability", "is_group": 0, "company": company}, fieldname="parent_account")
 				if not parent_account:
 					parent_account = frappe.db.get_value("Account",
 						filters={"account_type": "Tax", "root_type": "Liability", "is_group": 1, "company": company})
@@ -115,8 +117,11 @@
 				if not tax_type:
 					account = frappe.new_doc("Account")
 					account.update(filters)
-					account.insert()
-					tax_type = account.name
+					try:
+						account.insert()
+						tax_type = account.name
+					except frappe.DuplicateEntryError:
+						tax_type = frappe.db.get_value("Account", {"account_name": account_name, "company": company}, "name")
 
 		account_type = frappe.get_cached_value("Account", tax_type, "account_type")