feat: Repay advance from salary
diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.js b/erpnext/hr/doctype/employee_advance/employee_advance.js
index 3896603..c5d044a 100644
--- a/erpnext/hr/doctype/employee_advance/employee_advance.js
+++ b/erpnext/hr/doctype/employee_advance/employee_advance.js
@@ -23,6 +23,14 @@
}
};
});
+
+ frm.set_query('salary_component', function(doc) {
+ return {
+ filters: {
+ "type": "Deduction"
+ }
+ };
+ });
},
refresh: function(frm) {
@@ -47,19 +55,33 @@
}
if (frm.doc.docstatus === 1
- && (flt(frm.doc.claimed_amount) + flt(frm.doc.return_amount) < flt(frm.doc.paid_amount))
- && frappe.model.can_create("Journal Entry")) {
+ && (flt(frm.doc.claimed_amount) < flt(frm.doc.paid_amount) && flt(frm.doc.paid_amount) != flt(frm.doc.return_amount))) {
- frm.add_custom_button(__("Return"), function() {
- frm.trigger('make_return_entry');
- }, __('Create'));
+ if (frm.doc.repay_unclaimed_amount_from_salary == 0 && frappe.model.can_create("Journal Entry")){
+ frm.add_custom_button(__("Return"), function() {
+ frm.trigger('make_return_entry');
+ }, __('Create'));
+ }else if (frm.doc.repay_unclaimed_amount_from_salary == 1 && frappe.model.can_create("Additional Salary")){
+ frm.add_custom_button(__("Deduction from salary"), function() {
+ frm.events.make_deduction_via_additional_salary(frm)
+ }, __('Create'));
+ }
}
},
+ make_deduction_via_additional_salary: function(frm){
+ frappe.call({
+ method: "erpnext.hr.doctype.employee_advance.employee_advance.create_return_through_additional_salary",
+ args: {
+ doc: frm.doc
+ }
+ });
+ },
+
make_payment_entry: function(frm) {
var method = "erpnext.accounts.doctype.payment_entry.payment_entry.get_payment_entry";
if(frm.doc.__onload && frm.doc.__onload.make_payment_via_journal_entry) {
- method = "erpnext.hr.doctype.employee_advance.employee_advance.make_bank_entry"
+ method = "erpnext.hr.doctype.employee_advance.employee_advance.make_bank_entry";
}
return frappe.call({
method: method,
diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.json b/erpnext/hr/doctype/employee_advance/employee_advance.json
index d233a2b..7f599a7 100644
--- a/erpnext/hr/doctype/employee_advance/employee_advance.json
+++ b/erpnext/hr/doctype/employee_advance/employee_advance.json
@@ -10,9 +10,12 @@
"naming_series",
"employee",
"employee_name",
+ "department",
"column_break_4",
"posting_date",
- "department",
+ "repay_unclaimed_amount_from_salary",
+ "payroll_date",
+ "salary_component",
"section_break_8",
"purpose",
"column_break_11",
@@ -169,11 +172,30 @@
"label": "Returned Amount",
"options": "Company:company:default_currency",
"read_only": 1
+ },
+ {
+ "default": "0",
+ "fieldname": "repay_unclaimed_amount_from_salary",
+ "fieldtype": "Check",
+ "label": "Repay unclaimed amount from salary"
+ },
+ {
+ "depends_on": "eval:doc.repay_unclaimed_amount_from_salary == 1",
+ "fieldname": "payroll_date",
+ "fieldtype": "Date",
+ "label": "Payroll date"
+ },
+ {
+ "depends_on": "eval:doc.repay_unclaimed_amount_from_salary == 1",
+ "fieldname": "salary_component",
+ "fieldtype": "Link",
+ "label": "Salary Component",
+ "options": "Salary Component"
}
],
"is_submittable": 1,
"links": [],
- "modified": "2019-12-15 19:04:07.044505",
+ "modified": "2020-01-03 13:02:32.094099",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Advance",
@@ -210,4 +232,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
-}
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.py b/erpnext/hr/doctype/employee_advance/employee_advance.py
index f10e3b6..feedccc 100644
--- a/erpnext/hr/doctype/employee_advance/employee_advance.py
+++ b/erpnext/hr/doctype/employee_advance/employee_advance.py
@@ -133,8 +133,24 @@
return je.as_dict()
@frappe.whitelist()
-def make_return_entry(employee, company, employee_advance_name,
- return_amount, advance_account, mode_of_payment=None):
+def create_return_through_additional_salary(doc):
+ import json
+ doc = frappe._dict(json.loads(doc))
+ additional_salary = frappe.new_doc('Additional Salary')
+ additional_salary.employee = doc.employee
+ additional_salary.salary_component = doc.salary_component
+ additional_salary.amount = doc.paid_amount - doc.claimed_amount
+ additional_salary.payroll_date = doc.payroll_date
+ additional_salary.company = doc.company
+
+ additional_salary.submit()
+
+ frappe.db.set_value("Employee Advance", doc.name, "return_amount", additional_salary.amount)
+
+ return additional_salary.name
+
+@frappe.whitelist()
+def make_return_entry(employee_name, company, employee_advance_name, return_amount, mode_of_payment, advance_account):
return_account = get_default_bank_cash_account(company, account_type='Cash', mode_of_payment = mode_of_payment)
je = frappe.new_doc('Journal Entry')
je.posting_date = nowdate()