From 0e1314c5b5b8d3178f7f0eddc1918dcac8b3c382 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 4 Aug 2015 15:17:57 +0530 Subject: [PATCH] [fix] serial no validation in return entry --- erpnext/controllers/sales_and_purchase_return.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index f8ef4d7507..f429c67983 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -52,9 +52,13 @@ def validate_returned_items(doc): from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos valid_items = frappe._dict() - for d in frappe.db.sql("""select item_code, sum(qty) as qty, rate, serial_no, batch_no from `tab{0} Item` - where parent = %s group by item_code""".format(doc.doctype), doc.return_against, as_dict=1): - valid_items.setdefault(d.item_code, d) + + select_fields = "item_code, sum(qty) as qty, rate" if doc.doctype=="Purchase Invoice" \ + else "item_code, sum(qty) as qty, rate, serial_no, batch_no" + + for d in frappe.db.sql("""select {0} from `tab{1} Item` where parent = %s + group by item_code""".format(select_fields, doc.doctype), doc.return_against, as_dict=1): + valid_items.setdefault(d.item_code, d) if doc.doctype in ("Delivery Note", "Sales Invoice"): for d in frappe.db.sql("""select item_code, sum(qty) as qty, serial_no, batch_no from `tabPacked Item`