Skip to content

Commit

Permalink
Merge pull request #1777 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
ruchamahabal authored May 16, 2024
2 parents 77bb054 + 2f9ff31 commit f34c033
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 170 deletions.
25 changes: 2 additions & 23 deletions hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,12 @@ def get_overlapping_dates(self):
& (shift.docstatus == 1)
& (shift.name != self.name)
& (shift.status == "Active")
& ((shift.end_date >= self.start_date) | (shift.end_date.isnull()))
)
)

if self.end_date:
query = query.where(
Criterion.any(
[
Criterion.any(
[
shift.end_date.isnull(),
((self.start_date >= shift.start_date) & (self.start_date <= shift.end_date)),
]
),
Criterion.any(
[
((self.end_date >= shift.start_date) & (self.end_date <= shift.end_date)),
shift.start_date.between(self.start_date, self.end_date),
]
),
]
)
)
else:
query = query.where(
shift.end_date.isnull()
| ((self.start_date >= shift.start_date) & (self.start_date <= shift.end_date))
)
query = query.where(shift.start_date <= self.end_date)

return query.run(as_dict=True)

Expand Down
64 changes: 10 additions & 54 deletions hrms/hr/doctype/shift_assignment/test_shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,18 @@ def setUp(self):
frappe.db.delete("Shift Assignment")
frappe.db.delete("Shift Type")

def test_make_shift_assignment(self):
setup_shift_type(shift_type="Day Shift")
shift_assignment = frappe.get_doc(
{
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date": nowdate(),
}
).insert()
shift_assignment.submit()

self.assertEqual(shift_assignment.docstatus, 1)

def test_overlapping_for_ongoing_shift(self):
# shift should be Ongoing if Only start_date is present and status = Active
setup_shift_type(shift_type="Day Shift")
shift_assignment_1 = frappe.get_doc(
{
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date": nowdate(),
"status": "Active",
}
).insert()
shift_assignment_1.submit()
make_shift_assignment("Day Shift", "_T-Employee-00001", nowdate())

self.assertEqual(shift_assignment_1.docstatus, 1)
# shift ends before ongoing shift starts
non_overlapping_shift = make_shift_assignment(
"Day Shift", "_T-Employee-00001", add_days(nowdate(), -1), add_days(nowdate(), -1)
)
self.assertEqual(non_overlapping_shift.docstatus, 1)

shift_assignment = frappe.get_doc(
overlapping_shift = frappe.get_doc(
{
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
Expand All @@ -64,23 +43,11 @@ def test_overlapping_for_ongoing_shift(self):
"start_date": add_days(nowdate(), 2),
}
)

self.assertRaises(OverlappingShiftError, shift_assignment.save)
self.assertRaises(OverlappingShiftError, overlapping_shift.save)

def test_multiple_shift_assignments_for_same_date(self):
setup_shift_type(shift_type="Day Shift")
shift_assignment_1 = frappe.get_doc(
{
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date": nowdate(),
"end_date": add_days(nowdate(), 30),
"status": "Active",
}
).insert()
shift_assignment_1.submit()
make_shift_assignment("Day Shift", "_T-Employee-00001", nowdate(), add_days(nowdate(), 30))

setup_shift_type(shift_type="Night Shift", start_time="19:00:00", end_time="23:00:00")
shift_assignment_2 = frappe.get_doc(
Expand All @@ -103,18 +70,7 @@ def test_multiple_shift_assignments_for_same_date(self):
def test_overlapping_for_fixed_period_shift(self):
# shift should is for Fixed period if Only start_date and end_date both are present and status = Active
setup_shift_type(shift_type="Day Shift")
shift_assignment_1 = frappe.get_doc(
{
"doctype": "Shift Assignment",
"shift_type": "Day Shift",
"company": "_Test Company",
"employee": "_T-Employee-00001",
"start_date": nowdate(),
"end_date": add_days(nowdate(), 30),
"status": "Active",
}
).insert()
shift_assignment_1.submit()
make_shift_assignment("Day Shift", "_T-Employee-00001", nowdate(), add_days(nowdate(), 30))

# it should not allowed within period of any shift.
shift_assignment_3 = frappe.get_doc(
Expand Down
31 changes: 7 additions & 24 deletions hrms/hr/doctype/shift_request/shift_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,16 @@ def get_overlapping_dates(self):
query = (
frappe.qb.from_(shift)
.select(shift.name, shift.shift_type)
.where((shift.employee == self.employee) & (shift.docstatus < 2) & (shift.name != self.name))
.where(
(shift.employee == self.employee)
& (shift.docstatus < 2)
& (shift.name != self.name)
& ((shift.to_date >= self.from_date) | (shift.to_date.isnull()))
)
)

if self.to_date:
query = query.where(
Criterion.any(
[
Criterion.any(
[
shift.to_date.isnull(),
((self.from_date >= shift.from_date) & (self.from_date <= shift.to_date)),
]
),
Criterion.any(
[
((self.to_date >= shift.from_date) & (self.to_date <= shift.to_date)),
shift.from_date.between(self.from_date, self.to_date),
]
),
]
)
)
else:
query = query.where(
shift.to_date.isnull()
| ((self.from_date >= shift.from_date) & (self.from_date <= shift.to_date))
)
query = query.where(shift.from_date <= self.to_date)

return query.run(as_dict=True)

Expand Down
32 changes: 31 additions & 1 deletion hrms/payroll/doctype/payroll_period/payroll_period.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,35 @@
// For license information, please see license.txt

frappe.ui.form.on("Payroll Period", {
refresh: function (frm) {},
onload: function (frm) {
frm.trigger("set_start_date");
},

set_start_date: function (frm) {
if (!frm.doc.__islocal) return;

frappe.db
.get_list("Payroll Period", {
fields: ["end_date"],
order_by: "end_date desc",
limit: 1,
})
.then((result) => {
// set start date based on end date of the last payroll period if found
// else set it based on the current fiscal year's start date
if (result.length) {
const last_end_date = result[0].end_date;
frm.set_value("start_date", frappe.datetime.add_days(last_end_date, 1));
} else {
frm.set_value("start_date", frappe.defaults.get_default("year_start_date"));
}
});
},

start_date: function (frm) {
frm.set_value(
"end_date",
frappe.datetime.add_days(frappe.datetime.add_months(frm.doc.start_date, 12), -1),
);
},
});
7 changes: 3 additions & 4 deletions hrms/payroll/doctype/payroll_period/payroll_period.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}
],
"links": [],
"modified": "2024-05-05 14:50:12.419714",
"modified": "2024-05-07 17:27:51.903593",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll Period",
Expand Down Expand Up @@ -105,8 +105,7 @@
"write": 1
}
],
"quick_entry": 1,
"sort_field": "modified",
"sort_field": "creation",
"sort_order": "DESC",
"track_changes": 1
}
}
1 change: 1 addition & 0 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self, *args, **kwargs):
"float": float,
"long": int,
"round": round,
"rounded": rounded,
"date": date,
"getdate": getdate,
"ceil": ceil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ frappe.ui.form.on("Salary Structure Assignment", {
frm.doc.__onload.earning_and_deduction_entries_does_not_exists;
frm.trigger("set_earnings_and_taxation_section_visibility");
}

if (frm.doc.docstatus === 1)
frm.add_custom_button(
__("Preview Salary Slip"),
function () {
frm.trigger("preview_salary_slip");
},
__("Actions"),
);
},

employee: function (frm) {
Expand All @@ -82,6 +91,33 @@ frappe.ui.form.on("Salary Structure Assignment", {
}
},

preview_salary_slip: function (frm) {
frappe.db.get_value(
"Salary Structure",
frm.doc.salary_structure,
"salary_slip_based_on_timesheet",
(r) => {
const print_format = r.salary_slip_based_on_timesheet
? "Salary Slip based on Timesheet"
: "Salary Slip Standard";
frappe.call({
method: "hrms.payroll.doctype.salary_structure.salary_structure.make_salary_slip",
args: {
source_name: frm.doc.salary_structure,
employee: frm.doc.employee,
as_print: 1,
print_format: print_format,
for_preview: 1,
},
callback: function (r) {
const new_window = window.open();
new_window.document.write(r.message);
},
});
},
);
},

set_payroll_cost_centers: function (frm) {
if (frm.doc.payroll_cost_centers && frm.doc.payroll_cost_centers.length < 1) {
frappe.call({
Expand Down
12 changes: 3 additions & 9 deletions hrms/payroll/module_onboarding/payroll/payroll.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@
"creation": "2020-06-01 12:10:52.560472",
"docstatus": 0,
"doctype": "Module Onboarding",
"documentation_url": "https://docs.erpnext.com/docs/user/manual/en/human-resources/payroll-entry",
"documentation_url": "https://frappehr.com/docs/v14/en/payroll-entry",
"idx": 0,
"is_complete": 0,
"modified": "2020-07-08 14:06:13.994310",
"modified": "2024-05-07 17:44:05.258878",
"modified_by": "Administrator",
"module": "Payroll",
"name": "Payroll",
"owner": "Administrator",
"steps": [
{
"step": "Create Employee"
},
{
"step": "Create Salary Component"
},
Expand All @@ -32,10 +29,7 @@
"step": "Create Income Tax Slab"
},
{
"step": "Create Salary Structure"
},
{
"step": "Assign Salary Structure"
"step": "Create & Assign Salary Structure"
},
{
"step": "Create Salary Slip"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"action": "Create Entry",
"creation": "2020-06-01 11:57:54.527808",
"creation": "2024-01-11 13:25:28.533290",
"docstatus": 0,
"doctype": "Onboarding Step",
"idx": 0,
"is_complete": 0,
"is_mandatory": 1,
"is_single": 0,
"is_skipped": 0,
"modified": "2020-06-01 11:57:54.527808",
"modified": "2024-05-07 17:34:43.473732",
"modified_by": "Administrator",
"name": "Create Salary Structure",
"name": "Create & Assign Salary Structure",
"owner": "Administrator",
"reference_document": "Salary Structure",
"show_form_tour": 0,
"show_full_form": 1,
"title": "Create Salary Structure",
"title": "Create & Assign Salary Structure",
"validate_action": 1
}
19 changes: 0 additions & 19 deletions hrms/payroll/onboarding_step/create_employee/create_employee.json

This file was deleted.

Loading

0 comments on commit f34c033

Please sign in to comment.