refactor: rewrite query in QB
(cherry picked from commit 2f145f99129503359b9a79c247fe69e30ac1bf8e)
This commit is contained in:
parent
f4779df9b3
commit
3ca9d53d1b
@ -10,6 +10,8 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.model.mapper import map_child_doc
|
from frappe.model.mapper import map_child_doc
|
||||||
|
from frappe.query_builder import Case
|
||||||
|
from frappe.query_builder.functions import Locate
|
||||||
from frappe.utils import cint, floor, flt, today
|
from frappe.utils import cint, floor, flt, today
|
||||||
from frappe.utils.nestedset import get_descendants_of
|
from frappe.utils.nestedset import get_descendants_of
|
||||||
|
|
||||||
@ -686,32 +688,22 @@ def create_stock_entry(pick_list):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_pending_work_orders(doctype, txt, searchfield, start, page_length, filters, as_dict):
|
def get_pending_work_orders(doctype, txt, searchfield, start, page_length, filters, as_dict):
|
||||||
return frappe.db.sql(
|
wo = frappe.qb.DocType("Work Order")
|
||||||
"""
|
return (
|
||||||
SELECT
|
frappe.qb.from_(wo)
|
||||||
`name`, `company`, `planned_start_date`
|
.select(wo.name, wo.company, wo.planned_start_date)
|
||||||
FROM
|
.where(
|
||||||
`tabWork Order`
|
(wo.status.notin(["Completed", "Stopped"]))
|
||||||
WHERE
|
& (wo.qty > wo.material_transferred_for_manufacturing)
|
||||||
`status` not in ('Completed', 'Stopped')
|
& (wo.docstatus == 1)
|
||||||
AND `qty` > `material_transferred_for_manufacturing`
|
& (wo.company == filters.get("company"))
|
||||||
AND `docstatus` = 1
|
& (wo.name.like("%{0}%".format(txt)))
|
||||||
AND `company` = %(company)s
|
)
|
||||||
AND `name` like %(txt)s
|
.orderby(Case().when(Locate(txt, wo.name) > 0, Locate(txt, wo.name)).else_(99999))
|
||||||
ORDER BY
|
.orderby(wo.name)
|
||||||
(case when locate(%(_txt)s, name) > 0 then locate(%(_txt)s, name) else 99999 end),
|
.limit(cint(page_length))
|
||||||
name
|
.offset(start)
|
||||||
LIMIT
|
).run(as_dict=as_dict)
|
||||||
%(start)s, %(page_length)s""",
|
|
||||||
{
|
|
||||||
"txt": "%%%s%%" % txt,
|
|
||||||
"_txt": txt.replace("%", ""),
|
|
||||||
"start": start,
|
|
||||||
"page_length": frappe.utils.cint(page_length),
|
|
||||||
"company": filters.get("company"),
|
|
||||||
},
|
|
||||||
as_dict=as_dict,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user