From 07339fc69e99ee3801c56c1b586d090a4a4d2584 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 22 Apr 2014 15:30:05 +0530 Subject: [PATCH] Fixes in Setup Wizard and Attachments --- .../upload_attendance/upload_attendance.js | 18 +++++------ .../setup/page/setup_wizard/setup_wizard.js | 9 +++++- .../setup/page/setup_wizard/setup_wizard.py | 17 ++++++---- erpnext/stock/doctype/item/item.py | 9 ------ .../stock_reconciliation.js | 32 +++++++++---------- .../doctype/rename_tool/rename_tool.js | 10 +++--- 6 files changed, 48 insertions(+), 47 deletions(-) diff --git a/erpnext/hr/doctype/upload_attendance/upload_attendance.js b/erpnext/hr/doctype/upload_attendance/upload_attendance.js index 7606289f22..d74fb8d139 100644 --- a/erpnext/hr/doctype/upload_attendance/upload_attendance.js +++ b/erpnext/hr/doctype/upload_attendance/upload_attendance.js @@ -10,28 +10,28 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({ this.frm.set_value("att_fr_date", get_today()); this.frm.set_value("att_to_date", get_today()); }, - + refresh: function() { this.show_upload(); }, - + get_template:function() { if(!this.frm.doc.att_fr_date || !this.frm.doc.att_to_date) { msgprint(__("Attendance From Date and Attendance To Date is mandatory")); return; } - window.location.href = repl(frappe.request.url + + window.location.href = repl(frappe.request.url + '?cmd=%(cmd)s&from_date=%(from_date)s&to_date=%(to_date)s', { cmd: "erpnext.hr.doctype.upload_attendance.upload_attendance.get_template", from_date: this.frm.doc.att_fr_date, to_date: this.frm.doc.att_to_date, }); }, - + show_upload: function() { var me = this; var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty(); - + // upload frappe.upload.make({ parent: $wrapper, @@ -39,7 +39,7 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({ method: 'erpnext.hr.doctype.upload_attendance.upload_attendance.upload' }, sample_url: "e.g. http://example.com/somefile.csv", - callback: function(fid, filename, r) { + callback: function(attachment, r) { var $log_wrapper = $(cur_frm.fields_dict.import_log.wrapper).empty(); if(!r.messages) r.messages = []; @@ -62,7 +62,7 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({ r.messages = ["

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

"]. concat(r.message.messages) } - + $.each(r.messages, function(i, v) { var $p = $('

').html(v).appendTo($log_wrapper); if(v.substr(0,5)=='Error') { @@ -77,11 +77,11 @@ 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}); \ No newline at end of file +cur_frm.cscript = new erpnext.hr.AttendanceControlPanel({frm: cur_frm}); diff --git a/erpnext/setup/page/setup_wizard/setup_wizard.js b/erpnext/setup/page/setup_wizard/setup_wizard.js index bd7a3bf195..629a41200e 100644 --- a/erpnext/setup/page/setup_wizard/setup_wizard.js +++ b/erpnext/setup/page/setup_wizard/setup_wizard.js @@ -106,6 +106,13 @@ frappe.pages['setup-wizard'].onload = function(wrapper) { slide.form.fields_dict.first_name.set_input(frappe.boot.user.first_name); slide.form.fields_dict.last_name.set_input(frappe.boot.user.last_name); + var user_image = frappe.get_cookie("user_image"); + if(user_image) { + var $attach_user = slide.form.fields_dict.attach_user.$wrapper; + $attach_user.find(".missing-image").toggle(false); + $attach_user.find("img").attr("src", user_image).toggle(true); + } + delete slide.form.fields_dict.email; delete slide.form.fields_dict.password; } @@ -226,7 +233,7 @@ frappe.pages['setup-wizard'].onload = function(wrapper) { slide.fields = slide.fields.concat([ {fieldtype:"Data", fieldname:"tax_"+ i, label:__("Tax") + " " + i, placeholder:__("e.g. VAT")}, {fieldtype:"Column Break"}, - {fieldtype:"Data", fieldname:"tax_rate_i", label:__("Rate (%)"), placeholder:__("e.g. 5")}, + {fieldtype:"Data", fieldname:"tax_rate_" + i, label:__("Rate (%)"), placeholder:__("e.g. 5")}, {fieldtype:"Section Break"}, ]); } diff --git a/erpnext/setup/page/setup_wizard/setup_wizard.py b/erpnext/setup/page/setup_wizard/setup_wizard.py index 718019a834..3dd93bc89f 100644 --- a/erpnext/setup/page/setup_wizard/setup_wizard.py +++ b/erpnext/setup/page/setup_wizard/setup_wizard.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe, json -from frappe.utils import cstr, getdate +from frappe.utils import cstr, flt, getdate from frappe import _ from frappe.utils.file_manager import save_file from frappe.translate import set_default_language, get_dict, get_lang_dict @@ -15,8 +15,8 @@ import install_fixtures @frappe.whitelist() def setup_account(args=None): - # if frappe.db.sql("select name from tabCompany"): - # frappe.throw(_("Setup Already Complete!!")) + if frappe.db.sql("select name from tabCompany"): + frappe.throw(_("Setup Already Complete!!")) if not args: args = frappe.local.form_dict @@ -67,7 +67,7 @@ def setup_account(args=None): frappe.db.set_default('desktop:home_page', 'desktop') - website_maker(args.company_name, args.company_tagline, args.email) + website_maker(args.company_name, args.company_tagline, args.name) frappe.clear_cache() frappe.db.commit() @@ -259,6 +259,9 @@ def get_fy_details(fy_start_date, fy_end_date): def create_taxes(args): for i in xrange(1,6): if args.get("tax_" + str(i)): + # replace % in case someone also enters the % symbol + tax_rate = (args.get("tax_rate_" + str(i)) or "").replace("%", "") + frappe.get_doc({ "doctype":"Account", "company": args.get("company_name"), @@ -267,7 +270,7 @@ def create_taxes(args): "group_or_ledger": "Ledger", "report_type": "Balance Sheet", "account_type": "Tax", - "tax_rate": args.get("tax_rate_" + str(i)) + "tax_rate": flt(tax_rate) if tax_rate else None }).insert() def create_items(args): @@ -290,7 +293,7 @@ def create_items(args): if args.get("item_img_" + str(i)): filename, filetype, content = args.get("item_img_" + str(i)).split(",") - fileurl = save_file(filename, content, "Item", item, decode=True).file_name + fileurl = save_file(filename, content, "Item", item, decode=True).file_url frappe.db.set_value("Item", item, "image", fileurl) for i in xrange(1,6): @@ -311,7 +314,7 @@ def create_items(args): if args.get("item_img_" + str(i)): filename, filetype, content = args.get("item_img_" + str(i)).split(",") - fileurl = save_file(filename, content, "Item", item, decode=True).file_name + fileurl = save_file(filename, content, "Item", item, decode=True).file_url frappe.db.set_value("Item", item, "image", fileurl) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 26d827f8c9..a894ac1aab 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -204,15 +204,6 @@ class Item(WebsiteGenerator): def get_tax_rate(self, tax_type): return { "tax_rate": frappe.db.get_value("Account", tax_type, "tax_rate") } - def get_file_details(self, arg = ''): - file = frappe.db.sql("select file_group, description from tabFile where name = %s", eval(arg)['file_name'], as_dict = 1) - - ret = { - 'file_group' : file and file[0]['file_group'] or '', - 'description' : file and file[0]['description'] or '' - } - return ret - def on_trash(self): super(Item, self).on_trash() frappe.db.sql("""delete from tabBin where item_code=%s""", self.item_code) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js index aff3b2eb4f..bafa42983d 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -7,16 +7,16 @@ frappe.provide("erpnext.stock"); erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ onload: function() { this.set_default_expense_account(); - }, - + }, + set_default_expense_account: function() { var me = this; - + if (sys_defaults.auto_accounting_for_stock && !this.frm.doc.expense_account) { return this.frm.call({ method: "erpnext.accounts.utils.get_company_default", args: { - "fieldname": "stock_adjustment_account", + "fieldname": "stock_adjustment_account", "company": this.frm.doc.company }, callback: function(r) { @@ -25,13 +25,13 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ }); } }, - + setup: function() { var me = this; if (sys_defaults.auto_accounting_for_stock) { this.frm.add_fetch("company", "stock_adjustment_account", "expense_account"); this.frm.add_fetch("company", "cost_center", "cost_center"); - + this.frm.fields_dict["expense_account"].get_query = function() { return { "filters": { @@ -50,7 +50,7 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ } } }, - + refresh: function() { if(this.frm.doc.docstatus===0) { this.show_download_template(); @@ -70,7 +70,7 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ this.show_reconciliation_data(); this.show_download_reconciliation_data(); }, - + show_download_template: function() { var me = this; this.frm.add_custom_button(__("Download Template"), function() { @@ -90,11 +90,11 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ return false; }, "icon-download"); }, - + show_upload: function() { var me = this; var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty(); - + // upload frappe.upload.make({ parent: $wrapper, @@ -102,7 +102,7 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ method: 'erpnext.stock.doctype.stock_reconciliation.stock_reconciliation.upload' }, sample_url: "e.g. http://example.com/somefile.csv", - callback: function(fid, filename, r) { + callback: function(attachment, r) { me.frm.set_value("reconciliation_json", JSON.stringify(r.message)); me.show_reconciliation_data(); me.frm.save(); @@ -114,7 +114,7 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ .attr('value', 'Upload') }, - + show_download_reconciliation_data: function() { var me = this; if(this.frm.doc.reconciliation_json) { @@ -125,7 +125,7 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ }, "icon-download"); } }, - + show_reconciliation_data: function() { var $wrapper = $(cur_frm.fields_dict.reconciliation_html.wrapper).empty(); if(this.frm.doc.reconciliation_json) { @@ -133,11 +133,11 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ var _make = function(data, header) { var result = ""; - + var _render = header ? function(col) { return "" + col + ""; } : function(col) { return "" + col + ""; }; - + $.each(data, function(i, row) { result += "" + $.map(row, _render).join("") @@ -145,7 +145,7 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ }); return result; }; - + var $reconciliation_table = $("

\ \ " + _make([reconciliation_data[0]], true) + "\ diff --git a/erpnext/utilities/doctype/rename_tool/rename_tool.js b/erpnext/utilities/doctype/rename_tool/rename_tool.js index 42ae34005f..54fddf00d4 100644 --- a/erpnext/utilities/doctype/rename_tool/rename_tool.js +++ b/erpnext/utilities/doctype/rename_tool/rename_tool.js @@ -8,7 +8,7 @@ cur_frm.cscript.refresh = function(doc) { cur_frm.set_df_property("select_doctype", "options", r.message); cur_frm.cscript.setup_upload(); } - }); + }); } cur_frm.cscript.select_doctype = function() { @@ -31,14 +31,14 @@ cur_frm.cscript.setup_upload = function() { select_doctype: cur_frm.doc.select_doctype }, sample_url: "e.g. http://example.com/somefile.csv", - callback: function(fid, filename, r) { + callback: function(attachment, r) { $log.empty().html("
"); $.each(r.message, function(i, v) { $("
" + v + "
").appendTo($log); }); } }); - + // rename button $wrapper.find('form input[type="submit"]') .click(function() { @@ -46,5 +46,5 @@ cur_frm.cscript.setup_upload = function() { }) .addClass("btn-info") .attr('value', 'Upload and Rename') - -} \ No newline at end of file + +}