diff --git a/westech_r2/page/pallet-list/pallet-list.py b/westech_r2/page/pallet-list/pallet-list.py index 82aa5e7..4c19e61 100644 --- a/westech_r2/page/pallet-list/pallet-list.py +++ b/westech_r2/page/pallet-list/pallet-list.py @@ -6,35 +6,37 @@ def get_pallets(page=1, page_size=100, sort_field="pallet_number", sort_dir="des page_size = int(page_size) offset = (page - 1) * page_size - # Only pallets with dates (filters empty rows) - conditions = ["pallet_number IS NOT NULL", "pallet_number != ", "date_reserved IS NOT NULL"] + conditions = ["pallet_number IS NOT NULL", "pallet_number != ''", "date_reserved IS NOT NULL"] # Junk filter (same as EIM) - junk = ["", "0", "0000", "N/A", "TBD", "null"] - conditions.append("pallet_number NOT IN ( + , .join(junk) + )") + junk = ["", "0", "0000", "N/A", "TBD", "null", "999990", "999995"] + junk_list = "', '".join(junk) + conditions.append("pallet_number NOT IN ('" + junk_list + "')") + + # Exclude test numbers + conditions.append("pallet_number NOT LIKE '999%'") + + # Must start with digit + conditions.append("pallet_number REGEXP '^[0-9]'") if status_filter: - conditions.append("status = {0}".format(frappe.db.escape(status_filter))) + conditions.append("status = '" + frappe.db.escape(status_filter) + "'") if search: - conditions.append("pallet_number LIKE %{0}%".format(frappe.db.escape(search))) + conditions.append("pallet_number LIKE '%" + frappe.db.escape(search) + "%'") where_clause = " AND ".join(conditions) - # Get total - total = frappe.db.sql("""SELECT COUNT(*) FROM tabPallet WHERE {0}""".format(where_clause))[0][0] + total = frappe.db.sql("SELECT COUNT(*) FROM tabPallet WHERE " + where_clause)[0][0] - # Get pallets - convert pallet_number to unsigned int for numeric sort - # Use natural sort: convert to int for proper numeric ordering pallets = frappe.db.sql(""" SELECT name, pallet_number, date_reserved, received_date, customer_number, inbound_weight, tester, description, qty_to_sales, weight_to_sales, finish_date, notes, status FROM tabPallet - WHERE {0} - ORDER BY CAST(pallet_number AS UNSIGNED) {1} - LIMIT {2} OFFSET {3} - """.format(where_clause, sort_dir, page_size, offset), as_dict=True) + WHERE """ + where_clause + """ + ORDER BY CAST(pallet_number AS UNSIGNED) """ + sort_dir + """ + LIMIT """ + str(page_size) + """ OFFSET """ + str(offset), as_dict=True) return { "pallets": pallets,