Merge pull request #37758 from s-aga-r/FIX-37566
fix: `PermissionError` while creating DN from SO
diff --git a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json
index 9cf2ac6..4ae8135 100644
--- a/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json
+++ b/erpnext/accounts/doctype/payment_ledger_entry/payment_ledger_entry.json
@@ -30,7 +30,8 @@
{
"fieldname": "posting_date",
"fieldtype": "Date",
- "label": "Posting Date"
+ "label": "Posting Date",
+ "search_index": 1
},
{
"fieldname": "account_type",
@@ -153,7 +154,7 @@
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2023-06-29 12:24:20.500632",
+ "modified": "2023-10-30 16:15:00.470283",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Ledger Entry",
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 310e412..16e73ea 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -5,7 +5,7 @@
from typing import Optional
import frappe
-from frappe import _, msgprint, scrub
+from frappe import _, msgprint, qb, scrub
from frappe.contacts.doctype.address.address import get_company_address, get_default_address
from frappe.core.doctype.user_permission.user_permission import get_permitted_documents
from frappe.model.utils import get_fetch_values
@@ -480,11 +480,19 @@
def get_party_gle_currency(party_type, party, company):
def generator():
- existing_gle_currency = frappe.db.sql(
- """select account_currency from `tabGL Entry`
- where docstatus=1 and company=%(company)s and party_type=%(party_type)s and party=%(party)s
- limit 1""",
- {"company": company, "party_type": party_type, "party": party},
+ gl = qb.DocType("GL Entry")
+ existing_gle_currency = (
+ qb.from_(gl)
+ .select(gl.account_currency)
+ .where(
+ (gl.docstatus == 1)
+ & (gl.company == company)
+ & (gl.party_type == party_type)
+ & (gl.party == party)
+ & (gl.is_cancelled == 0)
+ )
+ .limit(1)
+ .run()
)
return existing_gle_currency[0][0] if existing_gle_currency else None