Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hrms/hr/doctype/leave_allocation/leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def set_total_leaves_allocated(self):
not self.total_leaves_allocated
and not frappe.db.get_value("Leave Type", self.leave_type, "is_earned_leave")
and not frappe.db.get_value("Leave Type", self.leave_type, "is_compensatory")
and not frappe.db.get_value("Leave Type", self.leave_type, "allow_negative")
):
frappe.throw(_("Total leaves allocated is mandatory for Leave Type {0}").format(self.leave_type))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ def create_leave_allocation(self, annual_allocation, leave_details, date_of_join
else []
)

if new_leaves_allocated == 0 and not leave_details.is_earned_leave:
if (
new_leaves_allocated == 0
and not leave_details.is_earned_leave
and not leave_details.allow_negative
):
text = _(
"Leave allocation is skipped for {0}, because number of leaves to be allocated is 0."
).format(frappe.bold(leave_details.name))
Expand Down Expand Up @@ -507,6 +511,7 @@ def get_leave_type_details():
"is_lwp",
"is_earned_leave",
"is_compensatory",
"allow_negative",
"allocate_on_day",
"is_carry_forward",
"expire_carry_forwarded_leaves_after_days",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def test_skip_zero_allocation_leaves(self):
sick = create_leave_type(
leave_type_name="_Test Sick Leave", non_encashable_leaves=0, max_leaves_allowed=2
)
sick.allow_negative = 1
sick.save()
casual = create_leave_type(
leave_type_name="_Test Casual Leave", non_encashable_leaves=0, max_leaves_allowed=12
)
Expand Down Expand Up @@ -304,17 +306,18 @@ def test_skip_zero_allocation_leaves(self):
fields=["content"],
)

self.assertEqual(len(comments), 2)
self.assertEqual(len(comments), 1)
self.assertIn(casual.name, comments[0]["content"])
self.assertIn(sick.name, comments[1]["content"])

allocations = frappe.get_all(
"Leave Allocation",
filters={"leave_policy_assignment": assignment.name},
fields=["leave_type", "new_leaves_allocated"],
fields=["leave_type", "new_leaves_allocated", "total_leaves_allocated"],
)
allocations = {allocation["leave_type"]: allocation for allocation in allocations}

self.assertEqual(allocations[0]["leave_type"], compoff.name)
self.assertEqual(allocations[0]["new_leaves_allocated"], 3)
self.assertEqual(allocations[1]["leave_type"], annual.name)
self.assertEqual(allocations[1]["new_leaves_allocated"], 3)
self.assertEqual(allocations[sick.name]["new_leaves_allocated"], 0)
self.assertEqual(allocations[sick.name]["total_leaves_allocated"], 0)
self.assertEqual(allocations[compoff.name]["new_leaves_allocated"], 3)
self.assertEqual(allocations[annual.name]["new_leaves_allocated"], 3)
self.assertNotIn(casual.name, allocations)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import frappe
from frappe import _
from frappe.query_builder import DocType
from frappe.query_builder.functions import Extract

import erpnext

Expand Down Expand Up @@ -65,28 +67,26 @@ def get_columns(filters):


def get_conditions(filters):
conditions = [""]
SalarySlip = DocType("Salary Slip")
filter_clauses = []

if filters.get("department"):
conditions.append("department = '%s' " % (filters["department"]))

filter_clauses.append(SalarySlip.department == filters["department"])
if filters.get("branch"):
conditions.append("branch = '%s' " % (filters["branch"]))

filter_clauses.append(SalarySlip.branch == filters["branch"])
if filters.get("company"):
conditions.append("company = '%s' " % (filters["company"]))

filter_clauses.append(SalarySlip.company == filters["company"])
if filters.get("month"):
conditions.append("month(start_date) = '%s' " % (filters["month"]))

filter_clauses.append(Extract("month", SalarySlip.start_date) == int(filters["month"]))
if filters.get("year"):
conditions.append("year(start_date) = '%s' " % (filters["year"]))
filter_clauses.append(Extract("year", SalarySlip.start_date) == int(filters["year"]))

return " and ".join(conditions)
return filter_clauses


def get_data(filters):
data = []
SalarySlip = DocType("Salary Slip")
filter_clauses = get_conditions(filters)

fields = ["employee", "branch", "bank_name", "bank_ac_no", "salary_mode"]
if erpnext.get_region() == "India":
Expand All @@ -108,16 +108,19 @@ def get_data(filters):
},
)

conditions = get_conditions(filters)
base_where = SalarySlip.docstatus == 1
for clause in filter_clauses:
base_where = base_where & clause

entry = frappe.db.sql(
""" select employee, employee_name, gross_pay, net_pay
from `tabSalary Slip`
where docstatus = 1 %s """
% (conditions),
as_dict=1,
entry = (
frappe.qb.from_(SalarySlip)
.select(SalarySlip.employee, SalarySlip.employee_name, SalarySlip.gross_pay, SalarySlip.net_pay)
.where(base_where)
.run(as_dict=True)
)

data = []

for d in entry:
employee = {
"branch": employee_data_dict.get(d.employee).get("branch"),
Expand Down
5 changes: 5 additions & 0 deletions hrms/public/js/erpnext/employee.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ frappe.ui.form.on("Employee", {
});
}
frm.set_df_property("holiday_list", "hidden", 1);

// hide naming series field based on hr settings
frappe.db.get_single_value("HR Settings", "emp_created_by").then((value) => {
frm.toggle_display("naming_series", value === "Naming Series");
});
},

date_of_birth(frm) {
Expand Down
Loading