Pull items in Stock Entry from Purchase Invoice (#11839)

This commit is contained in:
Nabin Hait 2017-12-04 13:36:50 +05:30 committed by GitHub
parent 3bac586ee2
commit a11dcb6e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View File

@ -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.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
from erpnext.buying.utils import check_for_closed_status from erpnext.buying.utils import check_for_closed_status
from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center
from frappe.model.mapper import get_mapped_doc
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "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") filters={"parent": asset_category, "company_name": company}, fieldname="fixed_asset_account")
return 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

View File

@ -260,7 +260,7 @@ erpnext.utils.map_current_doc = function(opts) {
action: function(selections, args) { action: function(selections, args) {
let values = selections; let values = selections;
if(values.length === 0){ if(values.length === 0){
frappe.msgprint(__("Please select Quotations")) frappe.msgprint(__("Please select {0}", [opts.source_doctype]))
return; return;
} }
opts.source_name = values; opts.source_name = values;

View File

@ -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) { if(frm.doc.company) {
frm.trigger("toggle_display_account_head"); frm.trigger("toggle_display_account_head");
} }