From 9f87c441b04d50aeee9c123580d8c29286132f16 Mon Sep 17 00:00:00 2001 From: Alchez Date: Tue, 13 Nov 2018 12:20:05 +0530 Subject: [PATCH] feat(delivery_trip): Create a Delivery Trip by selecting multiple Delivery Notes in list view (#15706) --- .../delivery_note/delivery_note_list.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note_list.js b/erpnext/stock/doctype/delivery_note/delivery_note_list.js index 9ec2a387ec..9631264f20 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note_list.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note_list.js @@ -10,5 +10,47 @@ frappe.listview_settings['Delivery Note'] = { } else if (doc.grand_total === 0 || flt(doc.per_billed, 2) == 100) { return [__("Completed"), "green", "per_billed,=,100"]; } + }, + onload: function (doclist) { + const action = () => { + const selected_docs = doclist.get_checked_items(); + const docnames = doclist.get_checked_items(true); + + if (selected_docs.length > 0) { + for (let doc of selected_docs) { + if (!doc.docstatus) { + frappe.throw(__("Cannot create a Delivery Trip from Draft documents.")); + } + }; + + frappe.new_doc("Delivery Trip") + .then(() => { + // Empty out the child table before inserting new ones + cur_frm.set_value("delivery_stops", []); + + // We don't want to use `map_current_doc` since it brings up + // the dialog to select more items. We just want the mapper + // function to be called. + frappe.call({ + type: "POST", + method: "frappe.model.mapper.map_docs", + args: { + "method": "erpnext.stock.doctype.delivery_note.delivery_note.make_delivery_trip", + "source_names": docnames, + "target_doc": cur_frm.doc + }, + callback: function (r) { + if (!r.exc) { + frappe.model.sync(r.message); + cur_frm.dirty(); + cur_frm.refresh(); + } + } + }); + }) + }; + }; + + doclist.page.add_actions_menu_item(__('Create Delivery Trip'), action, false); } };