From d8ddd1e2ec0228ed9f795a88dd3ecb93fb554173 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 22 Oct 2019 14:03:27 +0530 Subject: [PATCH] fix: not able to select the zero qty batch while making the sales return entry --- erpnext/controllers/queries.py | 39 ++++++++++++-------- erpnext/public/js/controllers/transaction.js | 5 +++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 19dea080b1..2f6b59f0fb 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -280,22 +280,31 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters): "page_len": page_len } + having_clause = "having sum(sle.actual_qty) > 0" + if filters.get("is_return"): + having_clause = "" + if args.get('warehouse'): - batch_nos = frappe.db.sql("""select sle.batch_no, round(sum(sle.actual_qty),2), sle.stock_uom, concat('MFG-',batch.manufacturing_date), concat('EXP-',batch.expiry_date) - from `tabStock Ledger Entry` sle - INNER JOIN `tabBatch` batch on sle.batch_no = batch.name - where - batch.disabled = 0 - and sle.item_code = %(item_code)s - and sle.warehouse = %(warehouse)s - and (sle.batch_no like %(txt)s - or batch.manufacturing_date like %(txt)s) - and batch.docstatus < 2 - {0} - {match_conditions} - group by batch_no having sum(sle.actual_qty) > 0 - order by batch.expiry_date, sle.batch_no desc - limit %(start)s, %(page_len)s""".format(cond, match_conditions=get_match_cond(doctype)), args) + batch_nos = frappe.db.sql("""select sle.batch_no, round(sum(sle.actual_qty),2), sle.stock_uom, + concat('MFG-',batch.manufacturing_date), concat('EXP-',batch.expiry_date) + from `tabStock Ledger Entry` sle + INNER JOIN `tabBatch` batch on sle.batch_no = batch.name + where + batch.disabled = 0 + and sle.item_code = %(item_code)s + and sle.warehouse = %(warehouse)s + and (sle.batch_no like %(txt)s + or batch.manufacturing_date like %(txt)s) + and batch.docstatus < 2 + {cond} + {match_conditions} + group by batch_no {having_clause} + order by batch.expiry_date, sle.batch_no desc + limit %(start)s, %(page_len)s""".format( + cond=cond, + match_conditions=get_match_cond(doctype), + having_clause = having_clause + ), args) return batch_nos else: diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index a9b19eddd7..57a1cc2ca1 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1652,6 +1652,11 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ 'item_code': item.item_code, 'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(), } + + if (doc.is_return) { + filters["is_return"] = 1; + } + if (item.warehouse) filters["warehouse"] = item.warehouse; return {