Delete cancelled SO from sales gross profit

I want to delete cancelled SO(Sales order) from sales gross profit.I have tried the following code but it neither gives me any output nor any error.
I have to check the cancelled SO from sales order and then find the same SO in sales gross profit such that I can show some relation between SO in sales order and sales order in Sales Gross Profit and delete it.Please help

def delete_cancelled_so(name):
doc = frappe.get_doc(“Sales Gross Profit”)
doc.sales_order = name
doc_dn = frappe.get_doc(“Sales Order”, name)
for sales_order in ‘tabSales Order’
SO = frappe.db.sql(‘select ‘tabSales Order’.name from ‘tabSales Order’ where docstatus = 2’)
if (SO = doc.sales_order)
delete_sales_order = frappe.db.sql(‘delete sales_order from ‘tabSales Gross Profit’ where SO = doc.sales_order’)