refactor: convert query to ORM

This commit is contained in:
Ankush Menat 2022-01-10 16:09:43 +05:30
parent 0faa116f97
commit cbaa8fdade

View File

@ -27,6 +27,7 @@ def execute():
broken_serial_nos = set() broken_serial_nos = set()
# patch SLEs
for sle in broken_sles: for sle in broken_sles:
serial_no_list = get_serial_nos(sle.serial_no) serial_no_list = get_serial_nos(sle.serial_no)
correct_sr_no = "\n".join(serial_no_list) correct_sr_no = "\n".join(serial_no_list)
@ -40,13 +41,16 @@ def execute():
if not broken_serial_nos: if not broken_serial_nos:
return return
broken_sr_no_records = [sr[0] for sr in frappe.db.sql(""" # Patch serial No documents if they don't have purchase info
select name # Purchase info is used for fetching incoming rate
from `tabSerial No` broken_sr_no_records = frappe.get_list("Serial No",
where status='Active' filters={
and coalesce(purchase_document_type, '') = '' "status":"Active",
and name in %s """, (list(broken_serial_nos),) "name": ("in", broken_serial_nos),
)] "purchase_document_type": ("is", "not set")
},
pluck="name",
)
frappe.db.MAX_WRITES_PER_TRANSACTION += len(broken_sr_no_records) frappe.db.MAX_WRITES_PER_TRANSACTION += len(broken_sr_no_records)