diff --git a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.js b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.js index 6958beabfa7..33b620bc66e 100644 --- a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.js +++ b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.js @@ -4,13 +4,33 @@ frappe.ui.form.on('Employee Loan Application', { refresh: function(frm) { frm.trigger("toggle_fields") + frm.trigger("add_toolbar_buttons") }, repayment_method: function(frm) { + frm.doc.repayment_amount = frm.doc.repayment_periods = "" frm.trigger("toggle_fields") }, - toggle_fields: function(frm) { frm.toggle_enable("repayment_amount", frm.doc.repayment_method=="Repay Fixed Amount per Period") frm.toggle_enable("repayment_periods", frm.doc.repayment_method=="Repay Over Number of Periods") + }, + add_toolbar_buttons: function(frm) { + if (frm.doc.status == "Approved") { + frm.add_custom_button(__('Employee Loan'), function() { + frappe.call({ + type: "GET", + method: "erpnext.hr.doctype.employee_loan_application.employee_loan_application.make_employee_loan", + args: { + "source_name": frm.doc.name + }, + callback: function(r) { + if(!r.exc) { + var doc = frappe.model.sync(r.message); + frappe.set_route("Form", r.message.doctype, r.message.name); + } + } + }); + }) + } } }); diff --git a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.json b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.json index f6a9c02da11..29617dd059b 100644 --- a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.json +++ b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.json @@ -146,9 +146,9 @@ "in_standard_filter": 0, "label": "Status", "length": 0, - "no_copy": 0, + "no_copy": 1, "options": "Open\nApproved\nRejected", - "permlevel": 0, + "permlevel": 1, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, @@ -639,7 +639,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-02-22 04:27:36.144540", + "modified": "2017-02-27 04:52:39.344524", "modified_by": "Administrator", "module": "HR", "name": "Employee Loan Application", @@ -685,6 +685,46 @@ "share": 1, "submit": 1, "write": 1 + }, + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 0, + "create": 0, + "delete": 1, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 1 + }, + { + "amend": 0, + "apply_user_permissions": 0, + "cancel": 0, + "create": 0, + "delete": 0, + "email": 1, + "export": 1, + "if_owner": 0, + "import": 0, + "permlevel": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Employee", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 0 } ], "quick_entry": 0, diff --git a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py index 15dbd4e5e40..74a65e2b571 100644 --- a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py +++ b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import frappe, math from frappe import _ from frappe.utils import flt +from frappe.model.mapper import get_mapped_doc from frappe.model.document import Document from erpnext.hr.doctype.employee_loan.employee_loan import get_monthly_repayment_amount, check_repayment_method @@ -18,7 +19,7 @@ class EmployeeLoanApplication(Document): def validate_loan_amount(self): maximum_loan_limit = frappe.db.get_value('Loan Type', self.loan_type, 'maximum_loan_amount') - if self.loan_amount > maximum_loan_limit: + if maximum_loan_limit and self.loan_amount > maximum_loan_limit: frappe.throw(_("Loan Amount cannot exceed Maximum Loan Amount of {0}").format(maximum_loan_limit)) def get_repayment_details(self): @@ -31,4 +32,17 @@ class EmployeeLoanApplication(Document): (self.loan_amount*monthly_interest_rate)))/(math.log(1+monthly_interest_rate))) self.total_payable_amount = self.repayment_amount * self.repayment_periods - self.total_payable_interest = self.total_payable_amount - self.loan_amount \ No newline at end of file + self.total_payable_interest = self.total_payable_amount - self.loan_amount + +@frappe.whitelist() +def make_employee_loan(source_name, target_doc = None): + doclist = get_mapped_doc("Employee Loan Application", source_name, { + "Employee Loan Application": { + "doctype": "Employee Loan", + "validation": { + "docstatus": ["=", 1] + } + } + }, target_doc) + + return doclist \ No newline at end of file diff --git a/erpnext/hr/doctype/loan_type/loan_type.json b/erpnext/hr/doctype/loan_type/loan_type.json index f9441ea1a28..3809fc15474 100644 --- a/erpnext/hr/doctype/loan_type/loan_type.json +++ b/erpnext/hr/doctype/loan_type/loan_type.json @@ -23,6 +23,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Loan Name", @@ -51,6 +52,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Maximum Loan Amount", @@ -79,6 +81,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Rate of Interest (%) Yearly", @@ -107,6 +110,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "length": 0, @@ -135,6 +139,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Disabled", @@ -164,6 +169,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Description", @@ -192,7 +198,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-12-29 15:54:17.716285", + "modified": "2017-02-27 04:53:51.949600", "modified_by": "Administrator", "module": "HR", "name": "Loan Type", @@ -209,7 +215,6 @@ "export": 1, "if_owner": 0, "import": 0, - "is_custom": 0, "permlevel": 0, "print": 1, "read": 1, @@ -224,7 +229,9 @@ "quick_entry": 0, "read_only": 0, "read_only_onload": 0, + "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", + "track_changes": 0, "track_seen": 0 } \ No newline at end of file