diff --git a/README.md b/README.md index 3cc232a..a67a723 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/app/controllers/customer_appointments_controller.rb b/app/controllers/customer_appointments_controller.rb index 5646f5a..3a533b7 100644 --- a/app/controllers/customer_appointments_controller.rb +++ b/app/controllers/customer_appointments_controller.rb @@ -165,6 +165,7 @@ class CustomerAppointmentsController < ApplicationController :date, :estimated_hours, :estimate_id, + :partial_estimate, :duration ) diff --git a/app/models/customer_appointment.rb b/app/models/customer_appointment.rb index 1046a5c..60970bd 100644 --- a/app/models/customer_appointment.rb +++ b/app/models/customer_appointment.rb @@ -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 diff --git a/app/views/customer_appointments/_form.html.erb b/app/views/customer_appointments/_form.html.erb index e0e415b..ed469a2 100644 --- a/app/views/customer_appointments/_form.html.erb +++ b/app/views/customer_appointments/_form.html.erb @@ -71,6 +71,11 @@
<%= f.datetime_local_field :date %>
<%= f.number_field :estimated_hours, step: 1, size: 6 %>
+ <%# Picking an estimate fills in its labor hours; ticked, the hours may be lowered below them %> +<%= f.number_field :duration, step: 1, size: 6, label: :label_duration %>
<%# 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); diff --git a/app/views/customer_appointments/_tooltip.html.erb b/app/views/customer_appointments/_tooltip.html.erb index 063616b..8bc2b2a 100644 --- a/app/views/customer_appointments/_tooltip.html.erb +++ b/app/views/customer_appointments/_tooltip.html.erb @@ -77,7 +77,10 @@ <% unless appointment.call_out? %>