mirror of
https://github.com/frappe/erpnext.git
synced 2026-07-20 11:22:28 +00:00
fix(stock): fix sqlparse token limit in get_bundle_wise_serial_nos
(cherry picked from commit 4544a6c935)
This commit is contained in:
@@ -2477,22 +2477,24 @@ def get_serial_nos_based_on_posting_date(kwargs, ignore_serial_nos):
|
||||
|
||||
def get_bundle_wise_serial_nos(data, kwargs):
|
||||
bundle_wise_serial_nos = defaultdict(list)
|
||||
bundles = [d.serial_and_batch_bundle for d in data if d.serial_and_batch_bundle]
|
||||
bundles = list({d.serial_and_batch_bundle for d in data if d.serial_and_batch_bundle})
|
||||
if not bundles:
|
||||
return bundle_wise_serial_nos
|
||||
|
||||
filters = {"parent": ("in", bundles), "docstatus": 1, "serial_no": ("is", "set")}
|
||||
|
||||
if kwargs.get("check_serial_nos") and kwargs.get("serial_nos"):
|
||||
filters["serial_no"] = ("in", kwargs.get("serial_nos"))
|
||||
|
||||
bundle_data = frappe.get_all(
|
||||
"Serial and Batch Entry",
|
||||
fields=["serial_no", "parent"],
|
||||
filters=filters,
|
||||
sabe = frappe.qb.DocType("Serial and Batch Entry")
|
||||
query = (
|
||||
frappe.qb.from_(sabe)
|
||||
.select(sabe.serial_no, sabe.parent)
|
||||
.where(sabe.parent.isin(bundles))
|
||||
.where(sabe.docstatus == 1)
|
||||
.where(sabe.serial_no.isnotnull())
|
||||
.where(sabe.serial_no != "")
|
||||
)
|
||||
|
||||
for d in bundle_data:
|
||||
if kwargs.get("check_serial_nos") and kwargs.get("serial_nos"):
|
||||
query = query.where(sabe.serial_no.isin(kwargs.get("serial_nos")))
|
||||
|
||||
for d in query.run(as_dict=True):
|
||||
if d.parent:
|
||||
bundle_wise_serial_nos[d.parent].append(d.serial_no)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user