diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index c800a93c66d..a58c290b66c 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -1200,7 +1200,7 @@ def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0): return out -def get_purchase_voucher_details(doctype, item_code, document_name): +def get_purchase_voucher_details(doctype, item_code, document_name=None): parent_doc = frappe.qb.DocType(doctype) child_doc = frappe.qb.DocType(doctype + " Item") @@ -1219,9 +1219,11 @@ def get_purchase_voucher_details(doctype, item_code, document_name): ) .where(parent_doc.docstatus == 1) .where(child_doc.item_code == item_code) - .where(parent_doc.name != document_name) ) + if document_name: + query = query.where(parent_doc.name != document_name) + if doctype in ("Purchase Receipt", "Purchase Invoice"): query = query.select(parent_doc.posting_date, parent_doc.posting_time) query = query.orderby(