Merge pull request #6488 from rohitwaghchaure/timesheet_delete_transaction_issue

[Fix] Timesheet detail records not deleted with company transactions deletion
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 253b319..9822fc0 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -316,4 +316,5 @@
 erpnext.patches.v7_0.update_status_for_timesheet
 erpnext.patches.v7_0.set_party_name_in_payment_entry
 execute:frappe.db.sql("update `tabTimesheet` ts, `tabEmployee` emp set ts.employee_name = emp.employee_name where emp.name = ts.employee and ts.employee_name is null and ts.employee is not null")
+execute:frappe.db.sql("delete from `tabTimesheet Detail` where NOT EXISTS (select name from `tabTimesheet` where name = `tabTimesheet Detail`.parent)")
 erpnext.patches.v7_0.update_mode_of_payment_type
diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py
index 7e1681c..8f058e8 100644
--- a/erpnext/setup/doctype/company/delete_company_transactions.py
+++ b/erpnext/setup/doctype/company/delete_company_transactions.py
@@ -18,7 +18,6 @@
 			frappe.PermissionError)
 
 	delete_bins(company_name)
-	delete_time_sheets(company_name)
 	delete_lead_addresses(company_name)
 
 	for doctype in frappe.db.sql_list("""select parent from
@@ -70,14 +69,6 @@
 	frappe.db.sql("""delete from tabBin where warehouse in
 			(select name from tabWarehouse where company=%s)""", company_name)
 
-def delete_time_sheets(company_name):
-	# Delete Time Logs as it is linked to Production Order / Project / Task, which are linked to company
-	frappe.db.sql("""
-		delete from `tabTimesheet`
-		where
-			company=%(company)s
-	""", {"company": company_name})
-
 def delete_lead_addresses(company_name):
 	"""Delete addresses to which leads are linked"""
 	for lead in frappe.get_all("Lead", filters={"company": company_name}):