From 4601fdd98d616050b11117473f272734ea3b5e72 Mon Sep 17 00:00:00 2001 From: KanchanChauhan Date: Fri, 30 Dec 2016 16:26:55 +0530 Subject: [PATCH] Better Salary Slip logs in Process Payroll (#7322) --- .../process_payroll/process_payroll.py | 62 +++++++++++-------- .../templates/includes/salary_slip_log.html | 19 ++++++ 2 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 erpnext/templates/includes/salary_slip_log.html diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.py b/erpnext/hr/doctype/process_payroll/process_payroll.py index 45030cba13..e2f7ca26f0 100644 --- a/erpnext/hr/doctype/process_payroll/process_payroll.py +++ b/erpnext/hr/doctype/process_payroll/process_payroll.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import frappe -from frappe.utils import cint, flt, nowdate, add_days, getdate +from frappe.utils import cint, flt, nowdate, add_days, getdate, fmt_money from frappe import _ from erpnext.accounts.utils import get_fiscal_year @@ -103,17 +103,23 @@ class ProcessPayroll(Document): "posting_date": self.posting_date }) ss.insert() - ss_list.append(ss.name) + 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_list.append(ss_dict) return self.create_log(ss_list) def create_log(self, ss_list): - log = "

" + _("No employee for the above selected criteria OR salary slip already created") + "

" - if ss_list: - log = "" + _("Salary Slip Created") + "\ -

%s" % '
'.join(self.format_as_links(ss_list)) - return log - + if not ss_list: + log = "

" + _("No employee for the above selected criteria OR salary slip already created") + "

" + else: + log = frappe.render_template("templates/includes/salary_slip_log.html", + dict(ss_list=ss_list, + keys=sorted(ss_list[0].keys()), + title=_('Created Salary Slips'))) + return log def get_sal_slip_list(self, ss_status, as_dict=False): """ @@ -136,44 +142,50 @@ class ProcessPayroll(Document): self.check_permission('write') ss_list = self.get_sal_slip_list(ss_status=0) + submitted_ss = [] not_submitted_ss = [] for ss in ss_list: ss_obj = frappe.get_doc("Salary Slip",ss[0]) + ss_dict = {} + ss_dict["Employee Name"] = ss_obj.employee_name + ss_dict["Total Pay"] = fmt_money(ss_obj.rounded_total,currency = frappe.defaults.get_global_default("currency")) + ss_dict["Salary Slip"] = self.format_as_links(ss_obj.name)[0] if ss_obj.net_pay<0: - not_submitted_ss.append(ss[0]) + not_submitted_ss.append(ss_dict) else: try: ss_obj.submit() + submitted_ss.append(ss_dict) except frappe.ValidationError: - not_submitted_ss.append(ss[0]) + not_submitted_ss.append(ss_dict) - return self.create_submit_log(ss_list, not_submitted_ss) + return self.create_submit_log(submitted_ss, not_submitted_ss) - def create_submit_log(self, all_ss, not_submitted_ss): + def create_submit_log(self, submitted_ss, not_submitted_ss): log = '' - if not all_ss: + if not submitted_ss and not not_submitted_ss: log = "No salary slip found to submit for the above selected criteria" - else: - all_ss = [d[0] for d in all_ss] - submitted_ss = self.format_as_links(list(set(all_ss) - set(not_submitted_ss))) if submitted_ss: - log = """ - Salary Slips Submitted:

%s - """ % ('
'.join(submitted_ss)) + log = frappe.render_template("templates/includes/salary_slip_log.html", + dict(ss_list=submitted_ss, + keys=sorted(submitted_ss[0].keys()), + title=_('Submitted Salary Slips'))) if not_submitted_ss: + log += frappe.render_template(self.get_log_template(), + dict(ss_list=not_submitted_ss, + keys=sorted(not_submitted_ss[0].keys()), + title=_('Not Submitted Salary Slips'))) log += """ - Not Submitted Salary Slips: \ -

%s

\ Possible reasons:
\ 1. Net pay is less than 0
- 2. Company email id specified in employee master is not valid.
\ - """% ('
'.join(not_submitted_ss)) + 2. Company email id specified in employee master is not valid.
+ """ return log - def format_as_links(self, ss_list): - return ['{0}'.format(s) for s in ss_list] + def format_as_links(self, salary_slip): + return ['{0}'.format(salary_slip)] def get_total_salary(self): diff --git a/erpnext/templates/includes/salary_slip_log.html b/erpnext/templates/includes/salary_slip_log.html new file mode 100644 index 0000000000..107df51dd8 --- /dev/null +++ b/erpnext/templates/includes/salary_slip_log.html @@ -0,0 +1,19 @@ + + + + + {% for key in keys %} + + {% endfor %} + + + + {% for ss_dict in ss_list %} + + {% for key, value in ss_dict.iteritems()|sort %} + + {% endfor %} + + {% endfor %} + +
{{title}}
{{ key }}
{{value}}
\ No newline at end of file