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

+6 -1
View File
@@ -15,7 +15,9 @@
all_holidays = Holiday.all
# Safely collect all unique CustomerAppointments across the entire calendar date range
all_appointments = (calendar.startdt..calendar.enddt).flat_map { |date|
# Prefer the list loaded by CalendarsControllerPatch; fall back to the calendar's own events
# (e.g. if this partial is rendered somewhere else)
all_appointments = @qbo_calendar_appointments || (calendar.startdt..calendar.enddt).flat_map { |date|
calendar.events_on(date)
}.select { |e| e.is_a?(CustomerAppointment) }.uniq
@@ -62,6 +64,9 @@
calculate_event_hours = lambda do |event, target_day|
if event.is_a?(Issue)
event.estimated_hours.to_f
elsif event.is_a?(CustomerAppointment) && !event.counts_toward_hours?
# Cancelled / call-out appointments stay on the calendar but don't use scheduled time
0.0
elsif event.is_a?(CustomerAppointment)
if event.duration.to_i > 1
app_total_hours = if event.respond_to?(:estimated_hours) && event.estimated_hours.present?
@@ -14,6 +14,13 @@
<% end %>
<% end %>
<% if @appointment.estimate && User.current.allowed_to?(:create_customer_appointment_issues, nil, global: true) %>
<%= link_to create_issues_customer_appointment_path(@appointment),
method: :post,
data: { confirm: l(:text_are_you_sure) } do %>
<i class="fa-solid fa-list-check"></i> <%= l(:button_create_issues_from_estimate) %>
<% end %>
<% end %>
<% if User.current.allowed_to?(:edit_customer_appointments, nil, global: true) %>
<%= link_to edit_customer_appointment_path(@appointment) do %>
<i class="fa-solid fa-pen-to-square"></i> <%= l(:button_edit) %>