From 20daae4de975be6db46679eb675c0e956fae77fb Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 6 May 2024 12:07:33 +0530 Subject: [PATCH] fix: incorrect query for Purchase Invoice rate in GP (cherry picked from commit bd8382c59259a9115fdd2c04ccfc297c89946d5d) --- erpnext/accounts/report/gross_profit/gross_profit.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 4e14c8aa325..c8c8dd9b494 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -720,20 +720,22 @@ class GrossProfitGenerator: frappe.qb.from_(purchase_invoice_item) .inner_join(purchase_invoice) .on(purchase_invoice.name == purchase_invoice_item.parent) - .select(purchase_invoice_item.base_rate / purchase_invoice_item.conversion_factor) + .select( + purchase_invoice.name, + purchase_invoice_item.base_rate / purchase_invoice_item.conversion_factor, + ) .where(purchase_invoice.docstatus == 1) .where(purchase_invoice.posting_date <= self.filters.to_date) .where(purchase_invoice_item.item_code == item_code) ) if row.project: - query.where(purchase_invoice_item.project == row.project) + query = query.where(purchase_invoice_item.project == row.project) if row.cost_center: - query.where(purchase_invoice_item.cost_center == row.cost_center) + query = query.where(purchase_invoice_item.cost_center == row.cost_center) - query.orderby(purchase_invoice.posting_date, order=frappe.qb.desc) - query.limit(1) + query = query.orderby(purchase_invoice.posting_date, order=frappe.qb.desc).limit(1) last_purchase_rate = query.run() return flt(last_purchase_rate[0][0]) if last_purchase_rate else 0