No-new-work weeks on the calendar

A checkbox under each week number flags the week "no new work" and circles
it in red. New appointments in a flagged week (or ones moved or lengthened
into it) warn on the form and are stopped on save; users with "Override
no-new-work weeks" can tick "Schedule anyway". Flagging needs "Flag
no-new-work weeks". Call-outs aren't affected. Adds migration 005.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-06 10:16:10 -05:00
1 parent cba0057c9c
commit 9a07c16731
13 files changed
+304 -5

No files matched your search

@@ -83,11 +83,14 @@ class CustomerAppointmentsController < ApplicationController
@appointment.date = (params[:start_date].to_date + 9.hours) if params[:start_date].present?
@appointment.customer_id = params[:customer_id] if params[:customer_id].present?
prefill_estimate_and_vehicle
# Warn up front when the day picked on the calendar is in a no-new-work week
@no_work_weeks = @appointment.no_work_weeks_added
end
def create
@appointment = CustomerAppointment.new(appointment_params)
@appointment.project = @project
apply_no_work_week_override
if @appointment.save
flash[:notice] = l(:notice_successful_create)
redirect_to customer_appointment_path( @appointment )
@@ -101,7 +104,9 @@ class CustomerAppointmentsController < ApplicationController
end
def update
if @appointment.update( appointment_params )
@appointment.assign_attributes(appointment_params)
apply_no_work_week_override
if @appointment.save
flash[:notice] = l(:notice_successful_update)
redirect_to customer_appointment_path( @appointment )
else
@@ -117,6 +122,16 @@ class CustomerAppointmentsController < ApplicationController
private
# "Schedule anyway" on the form counts only for users with "Override no-new-work weeks"
def apply_no_work_week_override
@appointment.no_work_week_override = params[:override_no_work_week] == '1' && can_override_no_work_weeks?
end
def can_override_no_work_weeks?
User.current.allowed_to?(:override_no_work_weeks, nil, global: true)
end
helper_method :can_override_no_work_weeks?
# Links from an estimate (redmine_qbo) pass the estimate and vehicle; each is used only when it
# belongs to the appointment's customer
def prefill_estimate_and_vehicle
@@ -0,0 +1,31 @@
# 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.
# Flags and unflags a calendar week as "no new work" (the checkbox at the start of each calendar week)
class NoWorkWeeksController < ApplicationController
before_action :require_login
before_action :authorize_global
def update
date = Date.parse(params[:week].to_s)
if params[:flagged] == '1'
NoWorkWeek.flag!(date)
else
NoWorkWeek.unflag!(date)
end
respond_to do |format|
format.html { redirect_back_or_default issues_calendar_path }
format.json { render json: { week_start: NoWorkWeek.week_start_for(date), flagged: params[:flagged] == '1' } }
end
rescue Date::Error
render_error status: 422, message: l(:error_invalid_no_work_week)
end
end