diff --git a/erpnext/accounts/report/gross_profit/gross_profit.js b/erpnext/accounts/report/gross_profit/gross_profit.js index 0ddb95fff2f..af20179d743 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.js +++ b/erpnext/accounts/report/gross_profit/gross_profit.js @@ -85,6 +85,12 @@ frappe.query_reports["Gross Profit"] = { }); }, }, + { + fieldname: "include_returned_invoices", + label: __("Include Returned Invoices (Stand-alone)"), + fieldtype: "Check", + default: 1, + }, ], tree: true, name_field: "parent", diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index baf2da6ceea..d2fe570fa3b 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -859,7 +859,10 @@ class GrossProfitGenerator: if self.filters.to_date: conditions += " and posting_date <= %(to_date)s" - conditions += " and (is_return = 0 or (is_return=1 and return_against is null))" + if self.filters.include_returned_invoices: + conditions += " and (is_return = 0 or (is_return=1 and return_against is null))" + else: + conditions += " and is_return = 0" if self.filters.item_group: conditions += f" and {get_item_group_condition(self.filters.item_group)}" diff --git a/erpnext/accounts/report/gross_profit/test_gross_profit.py b/erpnext/accounts/report/gross_profit/test_gross_profit.py index 88a614074e0..d92c16ab440 100644 --- a/erpnext/accounts/report/gross_profit/test_gross_profit.py +++ b/erpnext/accounts/report/gross_profit/test_gross_profit.py @@ -442,7 +442,11 @@ class TestGrossProfit(FrappeTestCase): sinv = sinv.save().submit() filters = frappe._dict( - company=self.company, from_date=nowdate(), to_date=nowdate(), group_by="Invoice" + company=self.company, + from_date=nowdate(), + to_date=nowdate(), + group_by="Invoice", + include_returned_invoices=1, ) columns, data = execute(filters=filters)