Appointment statuses in the plugin settings; call-outs as their own entry

Statuses (name, colour, counts toward hours, order) are set up on the plugin's settings page
instead of being hard-coded. Appointments keep a fixed key, so renaming is safe; removing a status
in use asks which status to move its appointments to (done on save by a SettingsController hook).
Colours come from the settings everywhere statuses show, which also fixes Cancelled never being
coloured (cancelled/canceled mismatch).

Call-outs (an employee off work) are their own kind of entry (event_type 'call_out') with an
employee, date, days and notes, added from a button on each calendar day. They sit at the top of
the day in red stripes and never count toward hours. Migration 004 converts Call_Out appointments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-02 20:22:52 -05:00
1 parent f2a16b1821
commit 31356ac3fb
23 files changed
+536 -252

No files matched your search

+43 -16
View File
@@ -22,6 +22,11 @@ class CustomerAppointment < ActiveRecord::Base
validates :subject, presence: true
validates :date, presence: true
# A call-out is about the employee who's off (checked when set, so older call-outs without one still save)
validates :user, presence: true, if: -> { call_out? && (new_record? || will_save_change_to_user_id?) }
# Call-outs have no customer side; appointments get the default status when none is chosen
before_validation :prepare_entry
# Prevent scheduling on non-working days or holidays
validate :validate_working_day
@@ -32,25 +37,32 @@ class CustomerAppointment < ActiveRecord::Base
# Capitalize the first letter only; titleize mangled vehicle names and acronyms (JL -> Jl, LED -> Led)
normalizes :subject, with: ->(subject) { subject.strip.sub(/\A[a-z]/, &:upcase) }
STATUSES = %w[
Scheduled
Checked_In
In_Progress
Ready
Completed
Cancelled
Call_Out
]
# An employee off work (sick, a day off): shown on the calendar, but not an appointment with a customer
CALL_OUT = 'call_out'
# Statuses whose time should not count toward scheduled hours totals
NON_SCHEDULED_STATUSES = %w[
Cancelled
Call_Out
]
# The statuses set up in the plugin settings (see RedmineQboCalendar::AppointmentStatus)
def self.statuses
RedmineQboCalendar::AppointmentStatus.all
end
# False for cancelled / call-out appointments, which stay on the calendar but free up their hours
# Status keys, for other plugins' settings (e.g. redmine_qbo_reminders' "statuses that get reminders")
def self.status_options
statuses.map { |s| [s.name, s.key] }
end
def call_out?
event_type == CALL_OUT
end
# This appointment's status from the settings; nil for call-outs, which have none
def status_record
return nil if call_out?
RedmineQboCalendar::AppointmentStatus.find(status) || RedmineQboCalendar::AppointmentStatus.default
end
# False for call-outs and statuses like Cancelled, which stay on the calendar but free up their hours
def counts_toward_hours?
!NON_SCHEDULED_STATUSES.include?(status.to_s)
!call_out? && status_record.counts_hours?
end
# Cast datetime to Date for Redmine Calendar compatibility
@@ -97,6 +109,21 @@ class CustomerAppointment < ActiveRecord::Base
Rails.logger.info "[CustomerAppointment] #{msg}"
end
def prepare_entry
if call_out?
self.customer = nil
self.vehicle = nil
self.estimate = nil
self.status = nil
self.estimated_hours = 0
self.subject = I18n.t(:label_call_out_subject, name: user.name) if subject.blank? && user
else
self.event_type = nil
self.status = RedmineQboCalendar::AppointmentStatus.default.key if status.blank?
end
self.description = description.to_s
end
# Checked when the estimate or the hours change, so changing just the status (the quick status buttons)
# never fails on an older appointment
def validate_hours_cover_estimate