Skip to content

Commit

Permalink
fix: error/warning message
Browse files Browse the repository at this point in the history
(cherry picked from commit 3410862)
  • Loading branch information
krantheman authored and mergify[bot] committed Dec 7, 2023
1 parent 4079dec commit 8a80dc4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion hrms/hr/doctype/hr_settings/hr_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"column_break_hyec",
"sender",
"sender_email",
"shift_management_settings_section",
"shift_settings_section",
"allow_multiple_shift_assignments",
"leave_and_expense_claim_settings",
"send_leave_notification",
Expand Down
21 changes: 15 additions & 6 deletions hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,38 @@ def validate(self):
def validate_overlapping_shifts(self):
overlapping_dates = self.get_overlapping_dates()
if len(overlapping_dates):
self.validate_same_date_multiple_shifts()
self.validate_same_date_multiple_shifts(overlapping_dates)
# if dates are overlapping, check if timings are overlapping, else allow
overlapping_timings = has_overlapping_timings(self.shift_type, overlapping_dates[0].shift_type)
if overlapping_timings:
self.throw_overlap_error(overlapping_dates[0])

def validate_same_date_multiple_shifts(self):
def validate_same_date_multiple_shifts(self, overlapping_dates):
allow_multiple_shift_assignments = frappe.db.get_single_value(
"HR Settings", "allow_multiple_shift_assignments"
)
if not allow_multiple_shift_assignments:
frappe.throw(
title=_("Multiple Shift Assignments"),
msg=_(
"Multiple shift assignments for the same date has been disabled. Please enable this feature under {0}."
).format(get_link_to_form("HR Settings", "HR Settings")),
"{0} already has an active Shift Assignment {1} for some/all of these dates. To allow this, enable 'Allow Multiple Shift Assignments for Same Date' under {2}."
).format(
self.employee,
get_link_to_form("Shift Assignment", overlapping_dates[0].name),
get_link_to_form("HR Settings", "HR Settings"),
),
exc=MultipleShiftError,
)

if not self.docstatus:
frappe.msgprint(
_(
"Note: You have already assigned different Shifts to {0} for some/all of these dates. Multiple Shift Assignments for the same date can be disabled under {1}."
).format(self.employee, get_link_to_form("HR Settings", "HR Settings"))
"Warning: {0} already has an active Shift Assignment {1} for some/all of these dates. 'Allow Multiple Shift Assignments for Same Date' can be disabled under {2}."
).format(
self.employee,
get_link_to_form("Shift Assignment", overlapping_dates[0].name),
get_link_to_form("HR Settings", "HR Settings"),
)
)

def get_overlapping_dates(self):
Expand Down

0 comments on commit 8a80dc4

Please sign in to comment.