From 4092045b87c9c9636ee20001aeb6639dca5a7406 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Oct 2026 11:34:39 -0400 Subject: [PATCH] Ask other plugins for the estimate appointment's extras The Add appointment link on an estimate no longer matches the estimate's VIN to a vehicle itself; it asks the qbo_calendar_appointment_params hook (redmine_qbo_vehicles answers with the vehicle). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM --- README.md | 2 +- .../customer_appointments/_estimate_actions.html.erb | 12 +++++++++--- .../hooks/customer_actions_hook_listener.rb | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1831033..02562dd 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Add appointments to the redmine calanedar with the abiltiy to attach a QBO custo * 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. * 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. +* 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). --- diff --git a/app/views/customer_appointments/_estimate_actions.html.erb b/app/views/customer_appointments/_estimate_actions.html.erb index 696660c..2a0dd86 100644 --- a/app/views/customer_appointments/_estimate_actions.html.erb +++ b/app/views/customer_appointments/_estimate_actions.html.erb @@ -1,7 +1,13 @@ -<%# Add appointment link on an estimate's page (redmine_qbo) %> +<%# Add appointment link on an estimate's page (redmine_qbo). Other plugins add to the new appointment's + params through :qbo_calendar_appointment_params, { customer:, estimate_id:, custom_fields: } (e.g. + redmine_qbo_vehicles: the vehicle with the estimate's VIN). %> <% if User.current.allowed_to?(:add_customer_appointments, nil, global: true) %> - <% vehicle = customer.vehicles.detect { |v| v.vin.to_s.casecmp?(vin.to_s.strip) } if vin.present? && customer.respond_to?(:vehicles) %> + <% + extra = Redmine::Hook.call_hook(:qbo_calendar_appointment_params, + { customer: customer, estimate_id: estimate_id, custom_fields: custom_fields || {} }) + .select { |result| result.is_a?(Hash) }.reduce({}) { |merged, result| merged.merge(result.symbolize_keys) } + %> <%= link_to sprite_icon('time-add', l(:label_add_appointment)), - new_customer_appointment_path(customer_id: customer.id, estimate_id: estimate_id, vehicle_id: vehicle&.id), + new_customer_appointment_path({ customer_id: customer.id, estimate_id: estimate_id }.merge(extra)), class: 'icon icon-time-add', target: :_blank %> <% end %> diff --git a/lib/redmine_qbo_calendar/hooks/customer_actions_hook_listener.rb b/lib/redmine_qbo_calendar/hooks/customer_actions_hook_listener.rb index b7264d5..4d1c2d3 100644 --- a/lib/redmine_qbo_calendar/hooks/customer_actions_hook_listener.rb +++ b/lib/redmine_qbo_calendar/hooks/customer_actions_hook_listener.rb @@ -20,14 +20,15 @@ module RedmineQboCalendar locals: { customer: context[:customer] }) end - # Adds "Add appointment" to an estimate's page in redmine_qbo (:view_qbo_estimate_contextual), - # with the customer, the estimate and the vehicle matching its VIN filled in + # Adds "Add appointment" to an estimate's page in redmine_qbo (:view_qbo_estimate_contextual), with the + # customer and the estimate filled in, plus what other plugins add (e.g. redmine_qbo_vehicles: the vehicle) def view_qbo_estimate_contextual(context = {}) customer = Customer.find_by(id: context[:customer_id]) return '' unless customer context[:hook_caller].render(partial: 'customer_appointments/estimate_actions', - locals: { customer: customer, estimate_id: context[:estimate_id], vin: context[:vin] }) + locals: { customer: customer, estimate_id: context[:estimate_id], + custom_fields: context[:custom_fields] }) end end