[Fix] Disallow same items to be fetched multiple times in sales invoice

This commit is contained in:
bhupen 2016-11-30 14:32:11 +05:30
parent 7f3da5dbb1
commit 3c7e70ffb3

View File

@ -143,7 +143,34 @@ erpnext.utils.map_current_doc = function(opts) {
if(!cur_frm.doc.items[0].item_code) {
cur_frm.doc.items = cur_frm.doc.items.splice(1);
}
// find the doctype of the items table
var items_doctype = frappe.meta.get_docfield(cur_frm.doctype, 'items').options;
// find the link fieldname from items table for the given
// source_doctype
var link_fieldname = null;
frappe.get_meta(items_doctype).fields.forEach(function(d) {
if(d.options===opts.source_doctype) link_fieldname = d.fieldname; });
// search in existing items if the source_name is already set
var already_set = false;
$.each(cur_frm.doc.items, function(i, d) {
if(d[link_fieldname]==opts.source_name) {
already_set = true;
return false;
}
});
if(already_set) {
frappe.msgprint(__("You have already selected items from {0} {1}",
[opts.source_doctype, opts.source_name]));
return;
}
}
return frappe.call({
// Sometimes we hit the limit for URL length of a GET request