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

+1 -1
View File
@@ -29,7 +29,7 @@ This plugin allows for adding customer appointment capability to the Redmine cal
Add appointments to the redmine calanedar with the abiltiy to attach a QBO customer, QBO Vehicle, QBO Estimate, ect.
* An appointment's hours can't be less than its estimate's labor hours (the quantities of its lines with redmine_qbo's labor products/services). Picking an estimate raises the hours to match.
* An appointment's hours can't be less than its estimate's labor hours (the quantities of its lines with redmine_qbo's labor products/services). Picking an estimate raises the hours to match. Tick **Partial estimate** to schedule only part of it, and the hours can then be lowered (migration 006).
* The appointment page lists the issues linked to its estimate, and **Create Issues from Estimate** opens redmine_qbo's Create issues page with the appointment's dates, technician and vehicle.
* Estimate pages in redmine_qbo get an **Add appointment** link. Other plugins can add to the new appointment through the `:qbo_calendar_appointment_params, { customer:, estimate_id:, custom_fields: }` hook (e.g. redmine_qbo_vehicles: the vehicle with the estimate's VIN).
* **Appointment statuses** are set up in the plugin's settings (Administration › Plugins › Configure): name, colour, whether the time counts toward the calendar's hours, and order (the first is the default). Renaming a status keeps its appointments; removing one in use asks which status to move them to. Statuses that don't count hours (e.g. Cancelled) stay on the calendar, crossed out.
@@ -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>
+4 -1
View File
@@ -86,7 +86,10 @@ en:
permission_manage_customer_appointments: Manage Customer Appointments
permission_view_customer_appointments: "View customer appointments"
title_customer_appointments: Customer Appointments
error_hours_less_than_estimate: "The hours can't be less than the %{hours} labor hours on estimate #%{estimate}"
error_hours_less_than_estimate: "The hours can't be less than the %{hours} labor hours on estimate #%{estimate}. Tick \"Partial estimate\" to schedule only part of it."
field_partial_estimate: "Partial estimate"
label_partial_estimate: "partial estimate"
text_partial_estimate: "Only part of the estimate this time: the hours may be less than its labor hours"
label_estimate_issues: "Issues for estimate #%{estimate}"
# Call-outs: an employee off work, shown on the calendar (not a customer appointment)
@@ -0,0 +1,16 @@
# 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.
# An appointment that works only part of its estimate: its hours may be less than the estimate's labor hours
class AddPartialEstimateToCustomerAppointments < ActiveRecord::Migration[7.0]
def change
add_column :customer_appointments, :partial_estimate, :boolean, default: false, null: false
end
end