fix: separation of salary creation from payroll (#24528)

* fix: separation of salary creation from payroll

* fix: removed unnecessary veriable

* fix: check existing sal slips

* fix: existing checks

* style: refactoring query
This commit is contained in:
Afshan 2021-02-02 16:24:01 +05:30 committed by GitHub
parent 8676089794
commit 10b00f9d0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 24 deletions

View File

@ -138,7 +138,6 @@ frappe.ui.form.on('Payroll Entry', {
payroll_frequency: function (frm) {
frm.trigger("set_start_end_dates").then( ()=> {
frm.events.clear_employee_table(frm);
frm.events.get_employee_with_salary_slip_and_set_query(frm);
});
},
@ -146,13 +145,17 @@ frappe.ui.form.on('Payroll Entry', {
frm.set_query('employee', 'employees', () => {
return {
filters: {
name: ["not in", emp_list]
name: ["not in", emp_list],
company: frm.doc.company
}
};
});
},
get_employee_with_salary_slip_and_set_query: function (frm) {
if (!frm.doc.company) {
frappe.throw(__("Please set a Company"));
}
frappe.db.get_list('Salary Slip', {
filters: {
start_date: frm.doc.start_date,
@ -171,6 +174,7 @@ frappe.ui.form.on('Payroll Entry', {
company: function (frm) {
frm.events.clear_employee_table(frm);
frm.events.get_employee_with_salary_slip_and_set_query(frm);
erpnext.accounts.dimensions.update_dimension(frm, frm.doctype);
},
@ -348,6 +352,9 @@ let render_employee_attendance = function (frm, data) {
frappe.ui.form.on('Payroll Employee Detail', {
employee: function(frm) {
if (!frm.doc.company) {
frappe.throw(__("Please set a Company"));
}
if (!frm.doc.payroll_frequency) {
frappe.throw(__("Please set a Payroll Frequency"));
}

View File

@ -14,7 +14,7 @@ from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
class PayrollEntry(Document):
def onload(self):
if not self.docstatus==1 or self.salary_slips_submitted:
return
return
# check if salary slips were manually submitted
entries = frappe.db.count("Salary Slip", {'payroll_entry': self.name, 'docstatus': 1}, ['name'])
@ -174,13 +174,12 @@ class PayrollEntry(Document):
"""
Returns list of salary slips based on selected criteria
"""
cond = self.get_filter_condition()
ss_list = frappe.db.sql("""
select t1.name, t1.salary_structure, t1.payroll_cost_center from `tabSalary Slip` t1
where t1.docstatus = %s and t1.start_date >= %s and t1.end_date <= %s
and (t1.journal_entry is null or t1.journal_entry = "") and ifnull(salary_slip_based_on_timesheet,0) = %s %s
""" % ('%s', '%s', '%s','%s', cond), (ss_status, self.start_date, self.end_date, self.salary_slip_based_on_timesheet), as_dict=as_dict)
where t1.docstatus = %s and t1.start_date >= %s and t1.end_date <= %s and t1.payroll_entry = %s
and (t1.journal_entry is null or t1.journal_entry = "") and ifnull(salary_slip_based_on_timesheet,0) = %s
""", (ss_status, self.start_date, self.end_date, self.name, self.salary_slip_based_on_timesheet), as_dict=as_dict)
return ss_list
def submit_salary_slips(self):
@ -332,10 +331,9 @@ class PayrollEntry(Document):
def make_payment_entry(self):
self.check_permission('write')
cond = self.get_filter_condition()
salary_slip_name_list = frappe.db.sql(""" select t1.name from `tabSalary Slip` t1
where t1.docstatus = 1 and start_date >= %s and end_date <= %s %s
""" % ('%s', '%s', cond), (self.start_date, self.end_date), as_list = True)
where t1.docstatus = 1 and start_date >= %s and end_date <= %s and t1.payroll_entry = %s
""", (self.start_date, self.end_date, self.name), as_list = True)
if salary_slip_name_list and len(salary_slip_name_list) > 0:
salary_slip_total = 0
@ -550,6 +548,7 @@ def payroll_entry_has_bank_entries(name):
def create_salary_slips_for_employees(employees, args, publish_progress=True):
salary_slips_exists_for = get_existing_salary_slips(employees, args)
count=0
salary_slips_not_created = []
for emp in employees:
if emp not in salary_slips_exists_for:
args.update({
@ -562,26 +561,18 @@ def create_salary_slips_for_employees(employees, args, publish_progress=True):
if publish_progress:
frappe.publish_progress(count*100/len(set(employees) - set(salary_slips_exists_for)),
title = _("Creating Salary Slips..."))
else:
salary_slip_name = frappe.db.sql(
'''SELECT
name
FROM `tabSalary Slip`
WHERE company=%s
AND start_date >= %s
AND end_date <= %s
AND employee = %s
''', (args.company, args.start_date, args.end_date, emp), as_dict=True)
salary_slip_doc = frappe.get_doc('Salary Slip', salary_slip_name[0].name)
salary_slip_doc.exchange_rate = args.exchange_rate
salary_slip_doc.set_totals()
salary_slip_doc.db_update()
else:
salary_slips_not_created.append(emp)
payroll_entry = frappe.get_doc("Payroll Entry", args.payroll_entry)
payroll_entry.db_set("salary_slips_created", 1)
payroll_entry.notify_update()
if salary_slips_not_created:
frappe.msgprint(_("Salary Slips already exists for employees {}, and will not be processed by this payroll.")
.format(frappe.bold(", ".join([emp for emp in salary_slips_not_created]))) , title=_("Message"), indicator="orange")
def get_existing_salary_slips(employees, args):
return frappe.db.sql_list("""
select distinct employee from `tabSalary Slip`