From d1defa5fc7c9de4324dded90c82ad78b8a0023a8 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 30 Oct 2017 17:50:02 +0530 Subject: [PATCH] set salary components --- .../hr/doctype/payroll_entry/payroll_entry.js | 8 +-- .../hr/doctype/payroll_entry/payroll_entry.py | 54 ++++++++-------- .../test_set_salary_components.js | 61 +++++++++++++++++++ erpnext/tests/ui/tests.txt | 1 + 4 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 erpnext/hr/doctype/payroll_entry/test_set_salary_components.js diff --git a/erpnext/hr/doctype/payroll_entry/payroll_entry.js b/erpnext/hr/doctype/payroll_entry/payroll_entry.js index cc10d7081d3..7f4769c9b0d 100644 --- a/erpnext/hr/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/hr/doctype/payroll_entry/payroll_entry.js @@ -104,9 +104,9 @@ frappe.ui.form.on('Payroll Entry', { frm.set_value('end_date', r.message.end_date); } } - }) + }); }, -}) +}); // Create salary slips @@ -119,7 +119,7 @@ cur_frm.cscript.custom_before_submit = function (doc) { let submit_salary_slip = function (frm) { var doc = frm.doc; return $c('runserverobj', { 'method': 'submit_salary_slips', 'docs': doc }); -} +}; let make_bank_entry = function (frm) { var doc = frm.doc; @@ -136,4 +136,4 @@ let make_bank_entry = function (frm) { } else { frappe.msgprint(__("Company, From Date and To Date is mandatory")); } -} +}; diff --git a/erpnext/hr/doctype/payroll_entry/payroll_entry.py b/erpnext/hr/doctype/payroll_entry/payroll_entry.py index a77df95180f..b36afa3299b 100644 --- a/erpnext/hr/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/hr/doctype/payroll_entry/payroll_entry.py @@ -47,9 +47,6 @@ class PayrollEntry(Document): and t1.name = t2.employee %s """% cond, {"sal_struct": sal_struct}) return emp_list - else: - frappe.msgprint(_("No active or default Salary Structure found for employee {0} for the given dates") - .format(self .employee), title=_('Salary Structure Missing')) def get_filter_condition(self): self.check_mandatory() @@ -107,14 +104,9 @@ class PayrollEntry(Document): ss_dict = {} ss_dict["Employee Name"] = ss.employee_name ss_dict["Total Pay"] = fmt_money(ss.rounded_total,currency = frappe.defaults.get_global_default("currency")) - ss_dict["Salary Slip"] = self.format_as_links(ss.name)[0] + ss_dict["Salary Slip"] = format_as_links(ss.name)[0] ss_list.append(ss_dict) - return self.create_log(ss_list) - - def create_log(self, ss_list): - if not ss_list or len(ss_list) < 1: - frappe.throw(_("No employee for the above selected criteria OR salary slip already created")) - return + return create_log(ss_list) def get_sal_slip_list(self, ss_status, as_dict=False): """ @@ -146,8 +138,8 @@ class PayrollEntry(Document): ss_dict = {} ss_dict["Employee Name"] = ss_obj.employee_name ss_dict["Total Pay"] = fmt_money(ss_obj.net_pay, - currency = frappe.defaults.get_global_default("currency")) - ss_dict["Salary Slip"] = self.format_as_links(ss_obj.name)[0] + currency = frappe.defaults.get_global_default("currency")) + ss_dict["Salary Slip"] = format_as_links(ss_obj.name)[0] if ss_obj.net_pay<0: not_submitted_ss.append(ss_dict) @@ -162,21 +154,7 @@ class PayrollEntry(Document): jv_name = self.make_accural_jv_entry() frappe.msgprint(_("Salary Slip submitted from {0} to {1}").format(ss_obj.start_date, ss_obj.end_date)) - return self.create_submit_log(submitted_ss, not_submitted_ss, jv_name) - - def create_submit_log(self, submitted_ss, not_submitted_ss, jv_name): - - if not submitted_ss and not not_submitted_ss: - frappe.msgprint("No salary slip found to submit for the above selected criteria OR salary slip already submitted") - - if not_submitted_ss: - frappe.msgprint("Not submitted Salary Slip
\ - Possible reasons:
\ - 1. Net pay is less than 0.
\ - 2. Company Email Address specified in employee master is not valid.
") - return - def format_as_links(self, salary_slip): - return ['{0}'.format(salary_slip)] + return create_submit_log(submitted_ss, not_submitted_ss, jv_name) def get_total_salary_and_loan_amounts(self): """ @@ -229,7 +207,7 @@ class PayrollEntry(Document): account = self.get_salary_component_account(s) account_dict[account] = account_dict.get(account, 0) + a return account_dict - + def get_default_payroll_payable_account(self): payroll_payable_account = frappe.db.get_value("Company", {"company_name": self.company}, "default_payroll_payable_account") @@ -433,4 +411,22 @@ def get_month_details(year, month): 'month_days': month_days }) else: - frappe.throw(_("Fiscal Year {0} not found").format(year)) \ No newline at end of file + frappe.throw(_("Fiscal Year {0} not found").format(year)) + +def create_log(ss_list): + if not ss_list or len(ss_list) < 1: + frappe.throw(_("No employee for the above selected criteria OR salary slip already created")) + +def format_as_links(salary_slip): + return ['{0}'.format(salary_slip)] + +def create_submit_log(submitted_ss, not_submitted_ss, jv_name): + + if not submitted_ss and not not_submitted_ss: + frappe.msgprint("No salary slip found to submit for the above selected criteria OR salary slip already submitted") + + if not_submitted_ss: + frappe.msgprint("Not submitted Salary Slip
\ + Possible reasons:
\ + 1. Net pay is less than 0.
\ + 2. Company Email Address specified in employee master is not valid.
") \ No newline at end of file diff --git a/erpnext/hr/doctype/payroll_entry/test_set_salary_components.js b/erpnext/hr/doctype/payroll_entry/test_set_salary_components.js new file mode 100644 index 00000000000..8ff55151f6f --- /dev/null +++ b/erpnext/hr/doctype/payroll_entry/test_set_salary_components.js @@ -0,0 +1,61 @@ +QUnit.module('HR'); + +QUnit.test("test: Set Salary Components", function (assert) { + assert.expect(5); + let done = assert.async(); + + frappe.run_serially([ + () => frappe.set_route('Form', 'Salary Component', 'Leave Encashment'), + () => { + var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts"); + row.company = 'For Testing'; + row.default_account = 'Salary - FT'; + }, + + () => cur_frm.save(), + () => frappe.timeout(2), + () => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'), + + () => frappe.set_route('Form', 'Salary Component', 'Basic'), + () => { + var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts"); + row.company = 'For Testing'; + row.default_account = 'Salary - FT'; + }, + + () => cur_frm.save(), + () => frappe.timeout(2), + () => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'), + + () => frappe.set_route('Form', 'Salary Component', 'Income Tax'), + () => { + var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts"); + row.company = 'For Testing'; + row.default_account = 'Salary - FT'; + }, + + () => cur_frm.save(), + () => frappe.timeout(2), + () => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'), + + () => frappe.set_route('Form', 'Salary Component', 'Arrear'), + () => { + var row = frappe.model.add_child(cur_frm.doc, "Salary Component Account", "accounts"); + row.company = 'For Testing'; + row.default_account = 'Salary - FT'; + }, + + () => cur_frm.save(), + () => frappe.timeout(2), + () => assert.equal(cur_frm.doc.accounts[0].default_account, 'Salary - FT'), + + () => frappe.set_route('Form', 'Company', 'For Testing'), + () => cur_frm.set_value('default_payroll_payable_account', 'Payroll Payable - FT'), + () => cur_frm.save(), + () => frappe.timeout(2), + () => assert.equal(cur_frm.doc.default_payroll_payable_account, 'Payroll Payable - FT'), + + () => done() + + ]); +}); diff --git a/erpnext/tests/ui/tests.txt b/erpnext/tests/ui/tests.txt index a5dcbcb5cc9..08fc9c31d42 100644 --- a/erpnext/tests/ui/tests.txt +++ b/erpnext/tests/ui/tests.txt @@ -78,6 +78,7 @@ erpnext/hr/doctype/training_feedback/test_training_feedback.js erpnext/hr/doctype/loan_type/test_loan_type.js erpnext/hr/doctype/employee_loan_application/test_employee_loan_application.js erpnext/hr/doctype/employee_loan/test_employee_loan.js +erpnext/hr/doctype/payroll_entry/test_set_salary_components.js erpnext/hr/doctype/payroll_entry/test_payroll_entry.js erpnext/buying/doctype/supplier/test_supplier.js erpnext/buying/doctype/request_for_quotation/tests/test_request_for_quotation.js