Better Salary Slip logs in Process Payroll (#7322)
This commit is contained in:
parent
ce5f942678
commit
4601fdd98d
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
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 frappe import _
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
@ -103,17 +103,23 @@ class ProcessPayroll(Document):
|
|||||||
"posting_date": self.posting_date
|
"posting_date": self.posting_date
|
||||||
})
|
})
|
||||||
ss.insert()
|
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)
|
return self.create_log(ss_list)
|
||||||
|
|
||||||
|
|
||||||
def create_log(self, ss_list):
|
def create_log(self, ss_list):
|
||||||
log = "<p>" + _("No employee for the above selected criteria OR salary slip already created") + "</p>"
|
if not ss_list:
|
||||||
if ss_list:
|
log = "<p>" + _("No employee for the above selected criteria OR salary slip already created") + "</p>"
|
||||||
log = "<b>" + _("Salary Slip Created") + "</b>\
|
else:
|
||||||
<br><br>%s" % '<br>'.join(self.format_as_links(ss_list))
|
log = frappe.render_template("templates/includes/salary_slip_log.html",
|
||||||
return log
|
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):
|
def get_sal_slip_list(self, ss_status, as_dict=False):
|
||||||
"""
|
"""
|
||||||
@ -136,44 +142,50 @@ class ProcessPayroll(Document):
|
|||||||
self.check_permission('write')
|
self.check_permission('write')
|
||||||
|
|
||||||
ss_list = self.get_sal_slip_list(ss_status=0)
|
ss_list = self.get_sal_slip_list(ss_status=0)
|
||||||
|
submitted_ss = []
|
||||||
not_submitted_ss = []
|
not_submitted_ss = []
|
||||||
for ss in ss_list:
|
for ss in ss_list:
|
||||||
ss_obj = frappe.get_doc("Salary Slip",ss[0])
|
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:
|
if ss_obj.net_pay<0:
|
||||||
not_submitted_ss.append(ss[0])
|
not_submitted_ss.append(ss_dict)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
ss_obj.submit()
|
ss_obj.submit()
|
||||||
|
submitted_ss.append(ss_dict)
|
||||||
except frappe.ValidationError:
|
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 = ''
|
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"
|
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:
|
if submitted_ss:
|
||||||
log = """
|
log = frappe.render_template("templates/includes/salary_slip_log.html",
|
||||||
<b>Salary Slips Submitted:</b> <br><br>%s
|
dict(ss_list=submitted_ss,
|
||||||
""" % ('<br>'.join(submitted_ss))
|
keys=sorted(submitted_ss[0].keys()),
|
||||||
|
title=_('Submitted Salary Slips')))
|
||||||
|
|
||||||
if not_submitted_ss:
|
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 += """
|
log += """
|
||||||
<b>Not Submitted Salary Slips: </b>\
|
|
||||||
<br><br> %s <br><br> \
|
|
||||||
Possible reasons: <br>\
|
Possible reasons: <br>\
|
||||||
1. Net pay is less than 0 <br>
|
1. Net pay is less than 0 <br>
|
||||||
2. Company email id specified in employee master is not valid. <br> \
|
2. Company email id specified in employee master is not valid. <br>
|
||||||
"""% ('<br>'.join(not_submitted_ss))
|
"""
|
||||||
return log
|
return log
|
||||||
|
|
||||||
def format_as_links(self, ss_list):
|
def format_as_links(self, salary_slip):
|
||||||
return ['<a href="#Form/Salary Slip/{0}">{0}</a>'.format(s) for s in ss_list]
|
return ['<a href="#Form/Salary Slip/{0}">{0}</a>'.format(salary_slip)]
|
||||||
|
|
||||||
|
|
||||||
def get_total_salary(self):
|
def get_total_salary(self):
|
||||||
|
19
erpnext/templates/includes/salary_slip_log.html
Normal file
19
erpnext/templates/includes/salary_slip_log.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<table class='table table-bordered'>
|
||||||
|
<caption>{{title}}</caption>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
{% for key in keys %}
|
||||||
|
<th {% if key == "Total Pay"%} style="text-align: right;" {% endif %}> {{ key }} </th>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for ss_dict in ss_list %}
|
||||||
|
<tr>
|
||||||
|
{% for key, value in ss_dict.iteritems()|sort %}
|
||||||
|
<td {% if key == "Total Pay"%} align = "right" {% endif %}> {{value}} </td>
|
||||||
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
Loading…
x
Reference in New Issue
Block a user