From b4de1c771b867f353961d502c39262d36da109c9 Mon Sep 17 00:00:00 2001 From: pratu16x7 Date: Sun, 7 May 2017 11:47:06 +0530 Subject: [PATCH] WIP --- erpnext/stock/doctype/batch/batch.py | 6 +++ .../stock/doctype/stock_entry/stock_entry.js | 42 +++++++++++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 4a0e89ad82..6428835498 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -123,4 +123,10 @@ def get_batch_no(item_code, warehouse, qty): frappe.msgprint(_('Please select a Batch for Item {0}. Unable to find a single batch that fulfills this requirement').format(frappe.bold(item_code))) if throw: raise UnableToSelectBatchError + # oldest_expiry_date = min([batch.expiry_date for batch in batches]) + + # for batch in batches: + # if batch.expiry_date == oldest_expiry_date: + # batch_no = batch.batch_no + return batch_no \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 83c6139651..e43325f290 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -43,6 +43,7 @@ frappe.ui.form.on('Stock Entry', { }); }, refresh: function(frm) { + erpnext.select_batch_and_serial_no(frm); if(!frm.doc.docstatus) { frm.add_custom_button(__('Make Material Request'), function() { frappe.model.with_doctype('Material Request', function() { @@ -76,6 +77,10 @@ frappe.ui.form.on('Stock Entry', { frm.fields_dict.items.grid.refresh(); frm.cscript.toggle_related_fields(frm.doc); }, + before_save: function(frm) { + console.log("before_save"); + erpnext.select_batch_and_serial_no(frm); + }, company: function(frm) { if(frm.doc.company) { var company_doc = frappe.get_doc(":Company", frm.doc.company); @@ -544,33 +549,54 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ }); erpnext.select_batch_and_serial_no = (frm) => { - frm.items.forEach(function(d) { - if(d.has_batch_no && !d.batch_no) { - show_modal(item_code, qty); - } - }); let show_modal = (item_code, qty) => { let d = new frappe.ui.Dialog({ fields: [ {fieldname: 'item_code', read_only: 1, fieldtype:'Link', options: 'Item', label: __('Item Code'), 'default': item_code}, + {fieldtype:'Column Break'}, {fieldname: 'qty', fieldtype:'Float', label: __('Qty'), 'default': qty}, + {fieldtype:'Section Break'}, {fieldname: 'batches', fieldtype: 'Table', fields: [ - {fieldtype:'Link', fieldname:'batch_no', options: 'Batch', reqd: 1, + {fieldtype:'Link', fieldname:'batch_no', options: 'Batch', label: __('Select Batch'), in_list_view:1, get_query: function(doc) { return {filters: {item: item_code }}; }}, - {fieldtype:'Float', fieldname:'available_qty', reqd: 1, + {fieldtype:'Float', fieldname:'available_qty', label: __('Available'), in_list_view:1}, - {fieldtype:'Float', fieldname:'selected_qty', reqd: 1, + {fieldtype:'Float', fieldname:'selected_qty', label: __('Qty'), in_list_view:1}, ], + get_data: function() { + console.log("in get data"); + return [ + { + + }, + { + + }, + { + + } + ] + } } ] }); + + d.show(); } + show_modal("_Test FG Item", 1); + + // frm.doc.items.forEach(function(d) { + // if(d.has_batch_no && !d.batch_no) { + // show_modal(d.item_code, d.qty); + // } + // }); + } \ No newline at end of file