From a11dcb6e599d2094402e0555fa02d2afb9d93fe1 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Dec 2017 13:36:50 +0530 Subject: [PATCH] Pull items in Stock Entry from Purchase Invoice (#11839) --- .../purchase_invoice/purchase_invoice.py | 20 +++++++++++++++++++ erpnext/public/js/utils.js | 2 +- .../stock/doctype/stock_entry/stock_entry.js | 17 ++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 0c8bfc002cb..b1dab508f58 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -16,6 +16,7 @@ from erpnext.accounts.general_ledger import make_gl_entries, merge_similar_entri from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt from erpnext.buying.utils import check_for_closed_status from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center +from frappe.model.mapper import get_mapped_doc form_grid_templates = { "items": "templates/form_grid/item_grid.html" @@ -728,3 +729,22 @@ def get_fixed_asset_account(asset, account=None): filters={"parent": asset_category, "company_name": company}, fieldname="fixed_asset_account") return account + +@frappe.whitelist() +def make_stock_entry(source_name, target_doc=None): + doc = get_mapped_doc("Purchase Invoice", source_name, { + "Purchase Invoice": { + "doctype": "Stock Entry", + "validation": { + "docstatus": ["=", 1] + } + }, + "Purchase Invoice Item": { + "doctype": "Stock Entry Detail", + "field_map": { + "stock_qty": "transfer_qty" + }, + } + }, target_doc) + + return doc \ No newline at end of file diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 47cda19298d..c83bcd63c19 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -260,7 +260,7 @@ erpnext.utils.map_current_doc = function(opts) { action: function(selections, args) { let values = selections; if(values.length === 0){ - frappe.msgprint(__("Please select Quotations")) + frappe.msgprint(__("Please select {0}", [opts.source_doctype])) return; } opts.source_name = values; diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 853b20dd224..b089d7f77c2 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -66,6 +66,23 @@ frappe.ui.form.on('Stock Entry', { }); } + if (frm.doc.docstatus===0) { + frm.add_custom_button(__('Purchase Invoice'), function() { + erpnext.utils.map_current_doc({ + method: "erpnext.accounts.doctype.purchase_invoice.purchase_invoice.make_stock_entry", + source_doctype: "Purchase Invoice", + target: frm, + date_field: "posting_date", + setters: { + supplier: frm.doc.supplier || undefined, + }, + get_query_filters: { + docstatus: 1 + } + }) + }, __("Get items from")); + } + if(frm.doc.company) { frm.trigger("toggle_display_account_head"); }