Skip to content

Commit

Permalink
Merge pull request #1773 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
ruchamahabal committed May 16, 2024
2 parents b21a6ca + e0b8cb8 commit 8b1df60
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 179 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 @@ -93,33 +93,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
2 changes: 1 addition & 1 deletion hrms/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ hrms.patches.v14_0.update_title_in_employee_onboarding_and_separation_templates
hrms.patches.v15_0.make_hr_settings_tab_in_company_master
hrms.patches.v15_0.enable_allow_checkin_setting
hrms.patches.v15_0.set_default_asset_action_in_fnf
hrms.patches.v15_0.add_loan_docperms_to_ess
hrms.patches.v15_0.add_loan_docperms_to_ess #2024-05-14
3 changes: 2 additions & 1 deletion hrms/patches/v15_0/add_loan_docperms_to_ess.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import frappe

from hrms.setup import add_lending_docperms_to_ess
from hrms.setup import add_lending_docperms_to_ess, update_user_type_doctype_limit


def execute():
if "lending" in frappe.get_installed_apps():
update_user_type_doctype_limit()
add_lending_docperms_to_ess()
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
}
}
2 changes: 1 addition & 1 deletion hrms/payroll/doctype/salary_component/salary_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ frappe.ui.form.on("Salary Component", {
args: {
structures: structures,
field: df.toLowerCase(),
value: frm.get_field(df.toLowerCase()).value,
value: frm.get_field(df.toLowerCase()).value || "",
},
})
.then((r) => {
Expand Down
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 @@ -70,6 +70,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 @@ -60,6 +60,7 @@ frappe.ui.form.on("Salary Structure Assignment", {
}

if (frm.doc.docstatus != 1) return;

frm.add_custom_button(
__("Payroll Entry"),
() => {
Expand All @@ -71,6 +72,14 @@ frappe.ui.form.on("Salary Structure Assignment", {
__("Create"),
);
frm.page.set_inner_btn_group_as_primary(__("Create"));

frm.add_custom_button(
__("Preview Salary Slip"),
function () {
frm.trigger("preview_salary_slip");
},
__("Actions"),
);
},

employee: function (frm) {
Expand All @@ -95,6 +104,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 All @@ -106,7 +142,6 @@ frappe.ui.form.on("Salary Structure Assignment", {
});
}
},

valiadte_joining_date_and_salary_slips: function (frm) {
frappe.call({
method: "earning_and_deduction_entries_does_not_exists",
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.

Loading

0 comments on commit 8b1df60

Please sign in to comment.