fix: gross profit calculation with rate adjustment entries

(cherry picked from commit b9f330a158)
This commit is contained in:
diptanilsaha
2026-07-01 08:02:45 +05:30
committed by Mergify
parent f5df9f7948
commit 17733a5641

View File

@@ -562,7 +562,12 @@ class GrossProfitGenerator:
row.base_amount = packed_item.base_amount row.base_amount = packed_item.base_amount
# get buying 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( row.buying_amount = flt(
self.get_buying_amount_from_product_bundle(row, product_bundles[row.item_code]), self.get_buying_amount_from_product_bundle(row, product_bundles[row.item_code]),
self.currency_precision, self.currency_precision,
@@ -925,6 +930,7 @@ class GrossProfitGenerator:
SalesInvoice.customer_group, SalesInvoice.customer_group,
SalesInvoice.customer_name, SalesInvoice.customer_name,
SalesInvoice.territory, SalesInvoice.territory,
SalesInvoice.is_debit_note,
SalesInvoiceItem.item_code, SalesInvoiceItem.item_code,
SalesInvoice.base_net_total.as_("invoice_base_net_total"), SalesInvoice.base_net_total.as_("invoice_base_net_total"),
SalesInvoiceItem.item_name, SalesInvoiceItem.item_name,
@@ -1104,6 +1110,7 @@ class GrossProfitGenerator:
"posting_time": row.posting_time, "posting_time": row.posting_time,
"project": row.project, "project": row.project,
"update_stock": row.update_stock, "update_stock": row.update_stock,
"is_debit_note": row.is_debit_note,
"customer": row.customer, "customer": row.customer,
"customer_group": row.customer_group, "customer_group": row.customer_group,
"customer_name": row.customer_name, "customer_name": row.customer_name,
@@ -1142,6 +1149,7 @@ class GrossProfitGenerator:
"description": item.description, "description": item.description,
"warehouse": item.warehouse or row.warehouse, "warehouse": item.warehouse or row.warehouse,
"update_stock": row.update_stock, "update_stock": row.update_stock,
"is_debit_note": row.is_debit_note,
"item_group": "", "item_group": "",
"brand": "", "brand": "",
"dn_detail": row.dn_detail, "dn_detail": row.dn_detail,