fix: Refactor Upload Attendance (#17241)
New API frappe.ui.FileUploader https://github.com/frappe/frappe/pull/7253
This commit is contained in:
parent
1ddc123dbf
commit
1cf9fa9662
@ -29,19 +29,12 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
show_upload: function() {
|
show_upload() {
|
||||||
var me = this;
|
|
||||||
var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty();
|
var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty();
|
||||||
|
new frappe.ui.FileUploader({
|
||||||
// upload
|
wrapper: $wrapper,
|
||||||
frappe.upload.make({
|
method: 'erpnext.hr.doctype.upload_attendance.upload_attendance.upload',
|
||||||
parent: $wrapper,
|
on_success(file_doc, r) {
|
||||||
args: {
|
|
||||||
method: 'erpnext.hr.doctype.upload_attendance.upload_attendance.upload'
|
|
||||||
},
|
|
||||||
no_socketio: true,
|
|
||||||
sample_url: "e.g. http://example.com/somefile.csv",
|
|
||||||
callback: function(attachment, r) {
|
|
||||||
var $log_wrapper = $(cur_frm.fields_dict.import_log.wrapper).empty();
|
var $log_wrapper = $(cur_frm.fields_dict.import_log.wrapper).empty();
|
||||||
|
|
||||||
if(!r.messages) r.messages = [];
|
if(!r.messages) r.messages = [];
|
||||||
@ -59,10 +52,10 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
r.messages = ["<h4 style='color:red'>"+__("Import Failed!")+"</h4>"]
|
r.messages = ["<h4 style='color:red'>"+__("Import Failed!")+"</h4>"]
|
||||||
.concat(r.messages)
|
.concat(r.messages);
|
||||||
} else {
|
} else {
|
||||||
r.messages = ["<h4 style='color:green'>"+__("Import Successful!")+"</h4>"].
|
r.messages = ["<h4 style='color:green'>"+__("Import Successful!")+"</h4>"]
|
||||||
concat(r.message.messages)
|
.concat(r.message.messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each(r.messages, function(i, v) {
|
$.each(r.messages, function(i, v) {
|
||||||
@ -79,11 +72,7 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
},
|
||||||
// rename button
|
|
||||||
$wrapper.find('form input[type="submit"]')
|
|
||||||
.attr('value', 'Upload and Import')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
cur_frm.cscript = new erpnext.hr.AttendanceControlPanel({frm: cur_frm});
|
cur_frm.cscript = new erpnext.hr.AttendanceControlPanel({frm: cur_frm});
|
||||||
|
@ -116,10 +116,10 @@ def upload():
|
|||||||
if not frappe.has_permission("Attendance", "create"):
|
if not frappe.has_permission("Attendance", "create"):
|
||||||
raise frappe.PermissionError
|
raise frappe.PermissionError
|
||||||
|
|
||||||
from frappe.utils.csvutils import read_csv_content_from_uploaded_file
|
from frappe.utils.csvutils import read_csv_content
|
||||||
from frappe.modules import scrub
|
from frappe.modules import scrub
|
||||||
|
|
||||||
rows = read_csv_content_from_uploaded_file()
|
rows = read_csv_content(frappe.local.uploaded_file)
|
||||||
rows = list(filter(lambda x: x and any(x), rows))
|
rows = list(filter(lambda x: x and any(x), rows))
|
||||||
if not rows:
|
if not rows:
|
||||||
msg = [_("Please select a csv file")]
|
msg = [_("Please select a csv file")]
|
||||||
|
Loading…
Reference in New Issue
Block a user