From c1f25ff9e302b2f0036d6394175b9cf8519cd496 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Thu, 22 Aug 2019 09:53:44 +0530 Subject: [PATCH] fix: Add option to select qty of finished goods Item --- erpnext/stock/doctype/pick_list/pick_list.js | 31 ++++++++++++++----- .../stock/doctype/pick_list/pick_list.json | 13 ++++++-- erpnext/stock/doctype/pick_list/pick_list.py | 7 ++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/erpnext/stock/doctype/pick_list/pick_list.js b/erpnext/stock/doctype/pick_list/pick_list.js index 08a388872d..e3064fe757 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.js +++ b/erpnext/stock/doctype/pick_list/pick_list.js @@ -36,10 +36,30 @@ frappe.ui.form.on('Pick List', { }, work_order: (frm) => { frm.clear_table('items'); - erpnext.utils.map_current_doc({ - method: 'erpnext.manufacturing.doctype.work_order.work_order.create_pick_list', - target: frm, - source_name: frm.doc.work_order + frappe.db.get_value('Work Order', + frm.doc.work_order, + ['qty', 'produced_qty'] + ).then(data => { + let qty_data = data.message; + let max = qty_data.qty - qty_data.produced_qty; + frappe.prompt({ + fieldtype: 'Float', + label: __('Qty'), + fieldname: 'qty', + description: __('Max: {0}', [max]), + default: max + }, (data) => { + frm.set_value('qty', data.qty); + if (data.qty > max) { + frappe.msgprint(__('Quantity must not be more than {0}', [max])); + return; + } + erpnext.utils.map_current_doc({ + method: 'erpnext.manufacturing.doctype.work_order.work_order.create_pick_list', + target: frm, + source_name: frm.doc.work_order + }); + }, __("Select Quantity"), __('Get Items')); }); }, items_based_on: (frm) => { @@ -52,11 +72,8 @@ frappe.ui.form.on('Pick List', { }); }, create_stock_entry(frm) { - // TODO: show dialog for qty - frappe.xcall('erpnext.stock.doctype.pick_list.pick_list.create_stock_entry', { 'pick_list': frm.doc, - 'qty': 1 }).then(stock_entry => { frappe.model.sync(stock_entry); frappe.set_route("Form", 'Stock Entry', stock_entry.name); diff --git a/erpnext/stock/doctype/pick_list/pick_list.json b/erpnext/stock/doctype/pick_list/pick_list.json index 1a33622167..e321a0bf5b 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.json +++ b/erpnext/stock/doctype/pick_list/pick_list.json @@ -8,6 +8,7 @@ "items_based_on", "customer", "work_order", + "qty", "column_break_4", "parent_warehouse", "company", @@ -59,8 +60,7 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Customer", - "options": "Customer", - "reqd": 1 + "options": "Customer" }, { "depends_on": "eval:doc.items_based_on===\"Work Order\"", @@ -81,9 +81,16 @@ "fieldtype": "Table", "label": "Item Locations", "options": "Pick List Item" + }, + { + "depends_on": "work_order", + "description": "Qty of raw materials will be decided based on the qty of the Finished Goods Item", + "fieldname": "qty", + "fieldtype": "Float", + "label": "Qty of Finished Goods Item" } ], - "modified": "2019-08-20 16:57:11.006221", + "modified": "2019-08-22 09:50:01.099449", "modified_by": "Administrator", "module": "Stock", "name": "Pick List", diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 34f1ab5895..d7f420d8f6 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -231,12 +231,9 @@ def set_delivery_note_missing_values(target): @frappe.whitelist() -def create_stock_entry(pick_list, qty): +def create_stock_entry(pick_list): pick_list = frappe.get_doc(json.loads(pick_list)) work_order = frappe.get_doc("Work Order", pick_list.get('work_order')) - if not qty: - qty = work_order.qty - work_order.material_transferred_for_manufacturing - if not qty: return stock_entry = frappe.new_doc('Stock Entry') stock_entry.purpose = 'Material Transfer For Manufacture' @@ -246,7 +243,7 @@ def create_stock_entry(pick_list, qty): stock_entry.from_bom = 1 stock_entry.bom_no = work_order.bom_no stock_entry.use_multi_level_bom = work_order.use_multi_level_bom - stock_entry.fg_completed_qty = (flt(work_order.qty) - flt(work_order.produced_qty)) + stock_entry.fg_completed_qty = pick_list.qty if work_order.bom_no: stock_entry.inspection_required = frappe.db.get_value('BOM', work_order.bom_no, 'inspection_required')