Try ERPNext Buy Support Partners Foundation

Delete sales order(SO) from sales gross profit

How do I delete cancelled SO(sales order) from sales gross profit??

Hi,

-Gross Profit is report which shows Invoice data not Order data. from where you want to delete SO.

Thank you for your reply @shraddha. I want to delete the cancelled SO from sales gross profit list and not from sales order list.

Okay. so is your query get solved or not ??

No. I am trying to figure out. Can you help me??

Okay.Can you share screenshot?

Do I need to create a .py file for the same??

I want to check the cancelled SO from sales order list and delete the same from sales gross profit.How do I match the SO in sales order list and sales gross profit list whether same or not and then delete the SO from sales gross profit list. I have written the following py file but not working. Can someone tell me where exactly do i need to write this py file??
current file path: cd home/frappe/frappe-bench/apps/erpnext/erpnext/selling/report/sales_order/sales_order.py
Please help.

from future import unicode_literals
import frappe
from frappe import _

frappe.db.exists({
‘doctype’ : ‘Sales Order’,
‘status’ : ‘Cancelled’
})

def execute():
if status.get(“Cancelled” and sales_gross_profit.sales_order = sales_order.name) :
frappe.db.sql("""
DELETE
sales_gross_profit.sales_order
FROM
‘tabSales Gross Profit’
WHERE
sales_gross_profit.docstatus = 0
“”")

Try this
def execute():
frappe.db.sql('Delete sales_order from tabSales Gross Profit where sales_order in (select name from tabSales Order where docstatus = 2 ) ')

Its neither giving me any error nor any output.