Fix permissions, holiday, hours, visibility and scheduling bugs

- customer_options is now covered by the add/edit permissions, so
  non-admin staff get the vehicle/estimate dropdowns
- create_issues is now a POST member route with its own permission,
  checks add_issues on the target project, no longer redirects to a
  missing route, and has a button on the appointment page
- "Last" week-of-month holidays (e.g. Memorial Day) now match every year
- Cancelled and Call Out appointments no longer count toward hours
- Calendar only shows appointments to users with View customer
  appointments, and only loads those near the displayed month
- due_date skips weekends and holidays, matching the calendar layout
- Subjects keep their casing; only the first letter is capitalized

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-28 17:14:13 -04:00
1 parent 21538ad95b
commit 73115da2b9
10 files changed
+130 -17

No files matched your search

@@ -34,7 +34,20 @@ module RedmineQboCalendar
log "events: #{events.inspect}"
appointments = CustomerAppointment.visible(User.current)
# Only users with "View customer appointments" see appointments on the calendar
appointments = CustomerAppointment.visible(User.current).includes(:customer, :vehicle, :user, :project)
# Only load appointments that can appear in the displayed range. Multi-day appointments
# can start before the range, so look back far enough to cover the longest one
# (working days only, so allow ~2x calendar days plus slack for holidays).
max_duration = [appointments.maximum(:duration).to_i, 1].max
range_start = (@calendar.startdt - (max_duration * 2 + 14)).beginning_of_day
range_end = @calendar.enddt.end_of_day
appointments = appointments.where(date: range_start..range_end).to_a
# Hand the list to the calendar view directly, so appointments that span the whole
# displayed range (neither starting nor ending in it) still render
@qbo_calendar_appointments = appointments
log "appointments: #{appointments.inspect}"
+45
View File
@@ -0,0 +1,45 @@
#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module RedmineQboCalendar
# Working-day arithmetic that respects Redmine's non-working week days and Holidays.
module WorkingDays
# Upper bound on how far we'll walk the calendar, so bad data can't loop forever.
MAX_SCAN_DAYS = 3660
module_function
def non_working_week_days
Setting.non_working_week_days || []
end
def non_working?(date, holidays: Holiday.all.to_a, week_days: non_working_week_days)
week_days.include?(date.cwday.to_s) || holidays.any? { |h| h.occurs_on?(date) }
end
# Returns the date of the Nth working day, counting start_date itself if it is a working day.
# e.g. a 3-day job starting Friday ends on Tuesday (Fri, Mon, Tue).
def nth_working_day(start_date, count, holidays: Holiday.all.to_a, week_days: non_working_week_days)
return nil if start_date.nil?
count = [count.to_i, 1].max
cursor = start_date
worked = 0
MAX_SCAN_DAYS.times do
worked += 1 unless non_working?(cursor, holidays: holidays, week_days: week_days)
return cursor if worked >= count
cursor += 1
end
cursor
end
end
end