From 1cf9fa9662e5657d3172dc839f0a713e506d28cc Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 17 Apr 2019 09:45:46 +0530 Subject: [PATCH] fix: Refactor Upload Attendance (#17241) New API frappe.ui.FileUploader https://github.com/frappe/frappe/pull/7253 --- .../upload_attendance/upload_attendance.js | 29 ++++++------------- .../upload_attendance/upload_attendance.py | 4 +-- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/erpnext/hr/doctype/upload_attendance/upload_attendance.js b/erpnext/hr/doctype/upload_attendance/upload_attendance.js index 776fd3c13b..277c060d6a 100644 --- a/erpnext/hr/doctype/upload_attendance/upload_attendance.js +++ b/erpnext/hr/doctype/upload_attendance/upload_attendance.js @@ -29,19 +29,12 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({ }); }, - show_upload: function() { - var me = this; + show_upload() { var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty(); - - // upload - frappe.upload.make({ - parent: $wrapper, - 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) { + new frappe.ui.FileUploader({ + wrapper: $wrapper, + method: 'erpnext.hr.doctype.upload_attendance.upload_attendance.upload', + on_success(file_doc, r) { var $log_wrapper = $(cur_frm.fields_dict.import_log.wrapper).empty(); if(!r.messages) r.messages = []; @@ -59,10 +52,10 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({ }); r.messages = ["

"+__("Import Failed!")+"

"] - .concat(r.messages) + .concat(r.messages); } else { - r.messages = ["

"+__("Import Successful!")+"

"]. - concat(r.message.messages) + r.messages = ["

"+__("Import Successful!")+"

"] + .concat(r.message.messages); } $.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}); diff --git a/erpnext/hr/doctype/upload_attendance/upload_attendance.py b/erpnext/hr/doctype/upload_attendance/upload_attendance.py index db74b102a7..6a4ea6a570 100644 --- a/erpnext/hr/doctype/upload_attendance/upload_attendance.py +++ b/erpnext/hr/doctype/upload_attendance/upload_attendance.py @@ -116,10 +116,10 @@ def upload(): if not frappe.has_permission("Attendance", "create"): 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 - 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)) if not rows: msg = [_("Please select a csv file")]