fix: `pymysql.err.ProgrammingError`
diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py
index 3887848..79c6891 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.py
+++ b/erpnext/stock/doctype/pick_list/pick_list.py
@@ -335,47 +335,48 @@
def get_picked_items_details(self, items):
picked_items = frappe._dict()
- pi = frappe.qb.DocType("Pick List")
- pi_item = frappe.qb.DocType("Pick List Item")
- query = (
- frappe.qb.from_(pi)
- .inner_join(pi_item)
- .on(pi.name == pi_item.parent)
- .select(
- pi_item.item_code,
- pi_item.warehouse,
- pi_item.batch_no,
- Sum(pi_item.picked_qty).as_("picked_qty"),
- Replace(GROUP_CONCAT(pi_item.serial_no), ",", "\n").as_("serial_no"),
+ if items:
+ pi = frappe.qb.DocType("Pick List")
+ pi_item = frappe.qb.DocType("Pick List Item")
+ query = (
+ frappe.qb.from_(pi)
+ .inner_join(pi_item)
+ .on(pi.name == pi_item.parent)
+ .select(
+ pi_item.item_code,
+ pi_item.warehouse,
+ pi_item.batch_no,
+ Sum(pi_item.picked_qty).as_("picked_qty"),
+ Replace(GROUP_CONCAT(pi_item.serial_no), ",", "\n").as_("serial_no"),
+ )
+ .where(
+ (pi_item.item_code.isin([x.item_code for x in items]))
+ & (pi_item.docstatus != 2)
+ & (pi_item.picked_qty > 0)
+ & (pi.status != "Completed")
+ )
+ .groupby(
+ pi_item.item_code,
+ pi_item.warehouse,
+ pi_item.batch_no,
+ )
)
- .where(
- (pi_item.item_code.isin([x.item_code for x in items]))
- & (pi_item.docstatus != 2)
- & (pi_item.picked_qty > 0)
- & (pi.status != "Completed")
- )
- .groupby(
- pi_item.item_code,
- pi_item.warehouse,
- pi_item.batch_no,
- )
- )
- if self.name:
- query = query.where(pi_item.parent != self.name)
+ if self.name:
+ query = query.where(pi_item.parent != self.name)
- items_data = query.run(as_dict=True)
+ items_data = query.run(as_dict=True)
- for item_data in items_data:
- key = (item_data.warehouse, item_data.batch_no) if item_data.batch_no else item_data.warehouse
- serial_no = [x for x in item_data.serial_no.split("\n") if x] if item_data.serial_no else None
- data = {"picked_qty": item_data.picked_qty}
- if serial_no:
- data["serial_no"] = serial_no
- if item_data.item_code not in picked_items:
- picked_items[item_data.item_code] = {key: data}
- else:
- picked_items[item_data.item_code][key] = data
+ for item_data in items_data:
+ key = (item_data.warehouse, item_data.batch_no) if item_data.batch_no else item_data.warehouse
+ serial_no = [x for x in item_data.serial_no.split("\n") if x] if item_data.serial_no else None
+ data = {"picked_qty": item_data.picked_qty}
+ if serial_no:
+ data["serial_no"] = serial_no
+ if item_data.item_code not in picked_items:
+ picked_items[item_data.item_code] = {key: data}
+ else:
+ picked_items[item_data.item_code][key] = data
return picked_items