mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-25 09:38:31 +00:00
fix: support translated search in get_party_type and refactor raw sql to qb (backport #53191) (#53832)
* fix: support translated search in get_party_type and refactor raw sql to qb
(cherry picked from commit d987688058)
# Conflicts:
# erpnext/setup/doctype/party_type/party_type.py
* fix: resolve merge conflicts in party_type.py
---------
Co-authored-by: Shllokkk <140623894+Shllokkk@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.query_builder import DocType
|
||||||
|
|
||||||
|
|
||||||
class PartyType(Document):
|
class PartyType(Document):
|
||||||
@@ -24,29 +25,36 @@ class PartyType(Document):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
def get_party_type(doctype, txt, searchfield, start, page_len, filters):
|
def get_party_type(doctype: str, txt: str, searchfield: str, start: int, page_len: int, filters: dict):
|
||||||
cond = ""
|
PartyType = DocType("Party Type")
|
||||||
account_type = None
|
get_party_type_query = frappe.qb.from_(PartyType).select(PartyType.name).orderby(PartyType.name)
|
||||||
|
|
||||||
|
condition_list = []
|
||||||
|
|
||||||
if filters and filters.get("account"):
|
if filters and filters.get("account"):
|
||||||
account_type = frappe.db.get_value("Account", filters.get("account"), "account_type")
|
account_type = frappe.db.get_value("Account", filters.get("account"), "account_type")
|
||||||
if account_type:
|
if account_type:
|
||||||
if account_type in ["Receivable", "Payable"]:
|
if account_type in ["Receivable", "Payable"]:
|
||||||
# Include Employee regardless of its configured account_type, but still respect the text filter
|
# Include Employee regardless of its configured account_type, but still respect the text filter
|
||||||
cond = "and (account_type = %(account_type)s or name = 'Employee')"
|
condition_list.append(
|
||||||
|
(PartyType.account_type == account_type) | (PartyType.name == "Employee")
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
cond = "and account_type = %(account_type)s"
|
condition_list.append(PartyType.account_type == account_type)
|
||||||
|
|
||||||
# Build parameters dictionary
|
for condition in condition_list:
|
||||||
params = {"txt": "%" + txt + "%", "start": start, "page_len": page_len}
|
get_party_type_query = get_party_type_query.where(condition)
|
||||||
if account_type:
|
|
||||||
params["account_type"] = account_type
|
|
||||||
|
|
||||||
result = frappe.db.sql(
|
if frappe.local.lang == "en":
|
||||||
f"""select name from `tabParty Type`
|
get_party_type_query = get_party_type_query.where(getattr(PartyType, searchfield).like(f"%{txt}%"))
|
||||||
where `{searchfield}` LIKE %(txt)s {cond}
|
get_party_type_query = get_party_type_query.limit(page_len)
|
||||||
order by name limit %(page_len)s offset %(start)s""",
|
get_party_type_query = get_party_type_query.offset(start)
|
||||||
params,
|
|
||||||
)
|
result = get_party_type_query.run()
|
||||||
|
else:
|
||||||
|
result = get_party_type_query.run()
|
||||||
|
test_str = txt.lower()
|
||||||
|
result = [row for row in result if test_str in frappe._(row[0]).lower()]
|
||||||
|
result = result[start : start + page_len]
|
||||||
|
|
||||||
return result or []
|
return result or []
|
||||||
|
|||||||
Reference in New Issue
Block a user