From b9f330a1589baa03acc60ba08fbda9874e5bc9b5 Mon Sep 17 00:00:00 2001 From: diptanilsaha Date: Wed, 1 Jul 2026 08:02:45 +0530 Subject: [PATCH] fix: gross profit calculation with rate adjustment entries --- erpnext/accounts/report/gross_profit/gross_profit.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 61968d603ad..af209a67f25 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -562,7 +562,12 @@ class GrossProfitGenerator: row.base_amount = packed_item.base_amount # get buying amount - if row.item_code in product_bundles: + if row.is_debit_note: + # Rate adjustment debit notes have no stock movement, so buying amount is zero + if not grouped_by_invoice: + row.qty = 0 + row.buying_amount = 0 + elif row.item_code in product_bundles: row.buying_amount = flt( self.get_buying_amount_from_product_bundle(row, product_bundles[row.item_code]), self.currency_precision, @@ -960,6 +965,7 @@ class GrossProfitGenerator: SalesInvoice.customer_group, SalesInvoice.customer_name, SalesInvoice.territory, + SalesInvoice.is_debit_note, SalesInvoiceItem.item_code, SalesInvoice.base_net_total.as_("invoice_base_net_total"), SalesInvoiceItem.item_name, @@ -1140,6 +1146,7 @@ class GrossProfitGenerator: "posting_time": row.posting_time, "project": row.project, "update_stock": row.update_stock, + "is_debit_note": row.is_debit_note, "customer": row.customer, "customer_group": row.customer_group, "customer_name": row.customer_name, @@ -1178,6 +1185,7 @@ class GrossProfitGenerator: "description": item.description, "warehouse": item.warehouse or row.warehouse, "update_stock": row.update_stock, + "is_debit_note": row.is_debit_note, "item_group": "", "brand": "", "dn_detail": row.dn_detail,