Partial estimates

Picking an estimate still fills in its labor hours; ticking Partial estimate lets the hours be lowered below them. Saved with the appointment and shown next to its hours. Adds migration 006.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-06 10:44:25 -05:00
1 parent 26685f0847
commit c3aab4a532
8 files changed
+46 -9

No files matched your search

@@ -165,6 +165,7 @@ class CustomerAppointmentsController < ApplicationController
:date,
:estimated_hours,
:estimate_id,
:partial_estimate,
:duration
)
+5 -4
View File
@@ -31,7 +31,7 @@ class CustomerAppointment < ActiveRecord::Base
# Prevent scheduling on non-working days or holidays
validate :validate_working_day
# The hours can't be less than the attached estimate's labor hours
# The hours can't be less than the attached estimate's labor hours, unless it's a partial estimate
validate :validate_hours_cover_estimate
# New work landing in a week flagged "no new work" needs an override (see #no_work_week_override)
@@ -153,6 +153,7 @@ class CustomerAppointment < ActiveRecord::Base
self.estimate = nil
self.status = nil
self.estimated_hours = 0
self.partial_estimate = false
self.subject = I18n.t(:label_call_out_subject, name: user.name) if subject.blank? && user
else
self.event_type = nil
@@ -162,10 +163,10 @@ class CustomerAppointment < ActiveRecord::Base
end
# Checked when the estimate or the hours change, so changing just the status (the quick status buttons)
# never fails on an older appointment
# never fails on an older appointment. A partial estimate (only some of its work this time) may use fewer.
def validate_hours_cover_estimate
return if estimate.nil?
return unless new_record? || will_save_change_to_estimate_id? || will_save_change_to_estimated_hours?
return if estimate.nil? || partial_estimate?
return unless new_record? || will_save_change_to_estimate_id? || will_save_change_to_estimated_hours? || will_save_change_to_partial_estimate?
labor = self.class.estimate_labor_hours(estimate)
return if labor.zero? || estimated_hours.to_i >= labor
+11 -1
View File
@@ -71,6 +71,11 @@
<p><%= f.datetime_local_field :date %></p>
<p><%= f.number_field :estimated_hours, step: 1, size: 6 %></p>
<%# Picking an estimate fills in its labor hours; ticked, the hours may be lowered below them %>
<p id="partial-estimate-row" style="<%= 'display: none;' unless @appointment.estimate_id %>">
<%= f.check_box :partial_estimate, label: :field_partial_estimate %>
<em class="info"><%= l(:text_partial_estimate) %></em>
</p>
<p><%= f.number_field :duration, step: 1, size: 6, label: :label_duration %></p>
<%# The statuses set up in the plugin settings, plus a removed one this appointment still has %>
@@ -99,7 +104,12 @@
var $hours = $('#customer_appointment_estimated_hours');
if (!$estimate.length || !$hours.length) return;
$estimate.on('change', function () {
if (!this.value) return;
// "Partial estimate" only means something with an estimate picked
$('#partial-estimate-row').toggle(!!this.value);
if (!this.value) {
$('#customer_appointment_partial_estimate').prop('checked', false);
return;
}
$.getJSON('<%= j estimate_hours_customer_appointments_path %>', { estimate_id: this.value }).done(function (data) {
var hours = parseInt(data.hours, 10) || 0;
if (hours > (parseInt($hours.val(), 10) || 0)) $hours.val(hours);
@@ -77,7 +77,10 @@
<% unless appointment.call_out? %>
<tr>
<th><%= l(:label_estimated_hours) %></th>
<td><%= number_with_precision(appointment.estimated_hours, precision: 1) %> hrs</td>
<td>
<%= number_with_precision(appointment.estimated_hours, precision: 1) %> hrs
<% if appointment.partial_estimate? && appointment.estimate %>(<%= l(:label_partial_estimate) %>)<% end %>
</td>
</tr>
<% end %>
@@ -124,7 +124,10 @@
<% unless @appointment.call_out? %>
<div class="attribute">
<div class="label"><%= l(:field_estimated_hours) %>:</div>
<div class="value"><%= @appointment.estimated_hours %> <%= l(:label_hours) %></div>
<div class="value">
<%= @appointment.estimated_hours %> <%= l(:label_hours) %>
<% if @appointment.partial_estimate? && @appointment.estimate %>(<%= l(:label_partial_estimate) %>)<% end %>
</div>
</div>
<% end %>
</div>