Estimate hours rule, linked issues, issue creation via redmine_qbo_billing

- An appointment's hours can't be less than its estimate's labor hours
  (checked when the estimate or hours change, so the quick status buttons
  still work on older appointments). Picking an estimate on the form, or
  arriving from an estimate page, raises the hours to match.
- The appointment page lists the issues linked to its estimate.
- Creating issues from an estimate moved to redmine_qbo_billing (now
  required): Create Issues from Estimate opens its page with this
  appointment's dates, technician, vehicle and project (via
  qbo_billing_issue_defaults). The builder, preview page, settings and rake
  task are removed here; the old settings stay registered so billing can
  read them until its own are saved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-30 23:11:33 -04:00
1 parent 3b753c1f35
commit fc503fca68
16 files changed
+135 -764

No files matched your search

+26
View File
@@ -26,6 +26,9 @@ 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
validate :validate_hours_cover_estimate
# 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) }
@@ -77,12 +80,35 @@ class CustomerAppointment < ActiveRecord::Base
subject
end
# The estimate's labor hours rounded up to whole hours (appointment hours are whole numbers): the
# quantities of its lines whose item matches redmine_qbo_billing's item codes (e.g. Labor). 0 if the
# estimate can't be read from QuickBooks.
def self.estimate_labor_hours(estimate)
return 0 if estimate.nil?
RedmineQboBilling::EstimateIssueBuilder.labor_hours(estimate).ceil
rescue StandardError => e
Rails.logger.warn "[CustomerAppointment] Could not read labor hours for estimate #{estimate&.id}: #{e.message}"
0
end
private
def log(msg)
Rails.logger.info "[CustomerAppointment] #{msg}"
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
return if estimate.nil?
return unless new_record? || will_save_change_to_estimate_id? || will_save_change_to_estimated_hours?
labor = self.class.estimate_labor_hours(estimate)
return if labor.zero? || estimated_hours.to_i >= labor
errors.add(:base, I18n.t(:error_hours_less_than_estimate, hours: labor, estimate: estimate.doc_number))
end
# Validates that the appointment date does not land on a weekend or holiday
def validate_working_day
return if date.blank?