fix: update sql function usage syntax

This commit is contained in:
Faris Ansari
2025-06-06 20:05:34 +05:30
parent 300530d35a
commit a397c1dea8
7 changed files with 13 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import frappe
from frappe import _
from frappe.model.meta import get_field_precision
from frappe.query_builder import DocType
from frappe.query_builder.functions import Abs
from frappe.utils import cint, flt, format_datetime, get_datetime
import erpnext
@@ -661,7 +662,10 @@ def get_rate_for_return(
if voucher_type in ("Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"):
select_field = "incoming_rate"
else:
select_field = "abs(stock_value_difference / actual_qty)"
StockLedgerEntry = frappe.qb.DocType("Stock Ledger Entry")
select_field = Abs(
StockLedgerEntry.stock_value_difference / StockLedgerEntry.actual_qty
)
rate = flt(frappe.db.get_value("Stock Ledger Entry", filters, select_field))
if not (rate and return_against) and voucher_type in ["Sales Invoice", "Delivery Note"]: