[fix] remove first row on mapping, fixes #5707

This commit is contained in:
Rushabh Mehta
2016-07-14 17:43:48 +05:30
parent 62fcaa7900
commit 176b63b354
18 changed files with 99 additions and 40 deletions

View File

@@ -120,6 +120,65 @@ $.extend(erpnext.utils, {
}
});
erpnext.utils.map_current_doc = function(opts) {
if(opts.get_query_filters) {
opts.get_query = function() {
return {filters: opts.get_query_filters};
}
}
var _map = function() {
// remove first item row if empty
if($.isArray(cur_frm.doc.items)) {
if(!cur_frm.doc.items[0].item_code) {
cur_frm.doc.items = cur_frm.doc.items.splice(1);
}
}
return frappe.call({
// Sometimes we hit the limit for URL length of a GET request
// as we send the full target_doc. Hence this is a POST request.
type: "POST",
method: opts.method,
args: {
"source_name": opts.source_name,
"target_doc": cur_frm.doc
},
callback: function(r) {
if(!r.exc) {
var doc = frappe.model.sync(r.message);
cur_frm.refresh();
}
}
});
}
if(opts.source_doctype) {
var d = new frappe.ui.Dialog({
title: __("Get From ") + __(opts.source_doctype),
fields: [
{
fieldtype: "Link",
label: __(opts.source_doctype),
fieldname: opts.source_doctype,
options: opts.source_doctype,
get_query: opts.get_query,
reqd:1
},
]
});
d.set_primary_action(__('Get Items'), function() {
var values = d.get_values();
if(!values)
return;
opts.source_name = values[opts.source_doctype];
d.hide();
_map();
})
d.show();
} else if(opts.source_name) {
_map();
}
}
// add description on posting time
$(document).on('app_ready', function() {
if(!frappe.datetime.is_timezone_same()) {