|
|
@@ -8,6 +8,8 @@ from frappe.config import get_modules_from_all_apps_for_user |
|
|
|
from frappe.model.document import Document |
|
|
|
from frappe.model.naming import append_number_if_name_exists |
|
|
|
from frappe.modules.export_file import export_to_files |
|
|
|
from frappe.query_builder import Criterion |
|
|
|
from frappe.query_builder.utils import DocType |
|
|
|
from frappe.utils import cint |
|
|
|
|
|
|
|
|
|
|
@@ -190,36 +192,18 @@ def get_cards_for_user(doctype, txt, searchfield, start, page_len, filters): |
|
|
|
if not frappe.db.exists("DocType", doctype): |
|
|
|
return |
|
|
|
|
|
|
|
numberCard = DocType("Number Card") |
|
|
|
|
|
|
|
if txt: |
|
|
|
for field in searchfields: |
|
|
|
search_conditions.append( |
|
|
|
"`tab{doctype}`.`{field}` like %(txt)s".format(field=field, doctype=doctype, txt=txt) |
|
|
|
) |
|
|
|
search_conditions = [numberCard[field].like("%{txt}%".format(txt=txt)) for field in searchfields] |
|
|
|
|
|
|
|
search_conditions = " or ".join(search_conditions) |
|
|
|
|
|
|
|
search_conditions = "and (" + search_conditions + ")" if search_conditions else "" |
|
|
|
conditions, values = frappe.db.build_conditions(filters) |
|
|
|
values["txt"] = "%" + txt + "%" |
|
|
|
|
|
|
|
return frappe.db.sql( |
|
|
|
"""select |
|
|
|
`tabNumber Card`.name, `tabNumber Card`.label, `tabNumber Card`.document_type |
|
|
|
from |
|
|
|
`tabNumber Card` |
|
|
|
where |
|
|
|
{conditions} and |
|
|
|
(`tabNumber Card`.owner = '{user}' or |
|
|
|
`tabNumber Card`.is_public = 1) |
|
|
|
{search_conditions} |
|
|
|
""".format( |
|
|
|
filters=filters, |
|
|
|
user=frappe.session.user, |
|
|
|
search_conditions=search_conditions, |
|
|
|
conditions=conditions, |
|
|
|
), |
|
|
|
values, |
|
|
|
) |
|
|
|
condition_query = frappe.db.query.build_conditions(doctype, filters) |
|
|
|
|
|
|
|
return ( |
|
|
|
condition_query.select(numberCard.name, numberCard.label, numberCard.document_type) |
|
|
|
.where((numberCard.owner == frappe.session.user) | (numberCard.is_public == 1)) |
|
|
|
.where(Criterion.any(search_conditions)) |
|
|
|
).run() |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist() |
|
|
|