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:
parent
8676089794
commit
10b00f9d0d
@ -138,7 +138,6 @@ frappe.ui.form.on('Payroll Entry', {
|
|||||||
payroll_frequency: function (frm) {
|
payroll_frequency: function (frm) {
|
||||||
frm.trigger("set_start_end_dates").then( ()=> {
|
frm.trigger("set_start_end_dates").then( ()=> {
|
||||||
frm.events.clear_employee_table(frm);
|
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', () => {
|
frm.set_query('employee', 'employees', () => {
|
||||||
return {
|
return {
|
||||||
filters: {
|
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) {
|
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', {
|
frappe.db.get_list('Salary Slip', {
|
||||||
filters: {
|
filters: {
|
||||||
start_date: frm.doc.start_date,
|
start_date: frm.doc.start_date,
|
||||||
@ -171,6 +174,7 @@ frappe.ui.form.on('Payroll Entry', {
|
|||||||
|
|
||||||
company: function (frm) {
|
company: function (frm) {
|
||||||
frm.events.clear_employee_table(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);
|
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', {
|
frappe.ui.form.on('Payroll Employee Detail', {
|
||||||
employee: function(frm) {
|
employee: function(frm) {
|
||||||
|
if (!frm.doc.company) {
|
||||||
|
frappe.throw(__("Please set a Company"));
|
||||||
|
}
|
||||||
if (!frm.doc.payroll_frequency) {
|
if (!frm.doc.payroll_frequency) {
|
||||||
frappe.throw(__("Please set a Payroll Frequency"));
|
frappe.throw(__("Please set a Payroll Frequency"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -174,13 +174,12 @@ class PayrollEntry(Document):
|
|||||||
"""
|
"""
|
||||||
Returns list of salary slips based on selected criteria
|
Returns list of salary slips based on selected criteria
|
||||||
"""
|
"""
|
||||||
cond = self.get_filter_condition()
|
|
||||||
|
|
||||||
ss_list = frappe.db.sql("""
|
ss_list = frappe.db.sql("""
|
||||||
select t1.name, t1.salary_structure, t1.payroll_cost_center from `tabSalary Slip` t1
|
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
|
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 %s
|
and (t1.journal_entry is null or t1.journal_entry = "") and ifnull(salary_slip_based_on_timesheet,0) = %s
|
||||||
""" % ('%s', '%s', '%s','%s', cond), (ss_status, self.start_date, self.end_date, self.salary_slip_based_on_timesheet), as_dict=as_dict)
|
""", (ss_status, self.start_date, self.end_date, self.name, self.salary_slip_based_on_timesheet), as_dict=as_dict)
|
||||||
return ss_list
|
return ss_list
|
||||||
|
|
||||||
def submit_salary_slips(self):
|
def submit_salary_slips(self):
|
||||||
@ -332,10 +331,9 @@ class PayrollEntry(Document):
|
|||||||
def make_payment_entry(self):
|
def make_payment_entry(self):
|
||||||
self.check_permission('write')
|
self.check_permission('write')
|
||||||
|
|
||||||
cond = self.get_filter_condition()
|
|
||||||
salary_slip_name_list = frappe.db.sql(""" select t1.name from `tabSalary Slip` t1
|
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
|
where t1.docstatus = 1 and start_date >= %s and end_date <= %s and t1.payroll_entry = %s
|
||||||
""" % ('%s', '%s', cond), (self.start_date, self.end_date), as_list = True)
|
""", (self.start_date, self.end_date, self.name), as_list = True)
|
||||||
|
|
||||||
if salary_slip_name_list and len(salary_slip_name_list) > 0:
|
if salary_slip_name_list and len(salary_slip_name_list) > 0:
|
||||||
salary_slip_total = 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):
|
def create_salary_slips_for_employees(employees, args, publish_progress=True):
|
||||||
salary_slips_exists_for = get_existing_salary_slips(employees, args)
|
salary_slips_exists_for = get_existing_salary_slips(employees, args)
|
||||||
count=0
|
count=0
|
||||||
|
salary_slips_not_created = []
|
||||||
for emp in employees:
|
for emp in employees:
|
||||||
if emp not in salary_slips_exists_for:
|
if emp not in salary_slips_exists_for:
|
||||||
args.update({
|
args.update({
|
||||||
@ -562,26 +561,18 @@ def create_salary_slips_for_employees(employees, args, publish_progress=True):
|
|||||||
if publish_progress:
|
if publish_progress:
|
||||||
frappe.publish_progress(count*100/len(set(employees) - set(salary_slips_exists_for)),
|
frappe.publish_progress(count*100/len(set(employees) - set(salary_slips_exists_for)),
|
||||||
title = _("Creating Salary Slips..."))
|
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)
|
else:
|
||||||
salary_slip_doc.exchange_rate = args.exchange_rate
|
salary_slips_not_created.append(emp)
|
||||||
salary_slip_doc.set_totals()
|
|
||||||
salary_slip_doc.db_update()
|
|
||||||
|
|
||||||
payroll_entry = frappe.get_doc("Payroll Entry", args.payroll_entry)
|
payroll_entry = frappe.get_doc("Payroll Entry", args.payroll_entry)
|
||||||
payroll_entry.db_set("salary_slips_created", 1)
|
payroll_entry.db_set("salary_slips_created", 1)
|
||||||
payroll_entry.notify_update()
|
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):
|
def get_existing_salary_slips(employees, args):
|
||||||
return frappe.db.sql_list("""
|
return frappe.db.sql_list("""
|
||||||
select distinct employee from `tabSalary Slip`
|
select distinct employee from `tabSalary Slip`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user