mirror of
https://github.com/rickbarrette/redmine_qbo_calendar.git
synced 2026-11-17 21:50:37 -05:00
Add appointment link on estimate pages
Listens for redmine_qbo_billing's view_qbo_estimate_contextual hook and adds an Add appointment link with the customer, the estimate, and the vehicle whose VIN matches the estimate's. The new appointment form uses the estimate and vehicle only when they belong to the customer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
3 files changed
+32
No files matched your search
@@ -95,6 +95,7 @@ class CustomerAppointmentsController < ApplicationController
|
|||||||
@appointment.project = @project
|
@appointment.project = @project
|
||||||
@appointment.date = (params[:start_date].to_date + 9.hours) if params[:start_date].present?
|
@appointment.date = (params[:start_date].to_date + 9.hours) if params[:start_date].present?
|
||||||
@appointment.customer_id = params[:customer_id] if params[:customer_id].present?
|
@appointment.customer_id = params[:customer_id] if params[:customer_id].present?
|
||||||
|
prefill_estimate_and_vehicle
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -129,6 +130,20 @@ class CustomerAppointmentsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Links from an estimate (redmine_qbo_billing) pass the estimate and vehicle; each is used only when it
|
||||||
|
# belongs to the appointment's customer
|
||||||
|
def prefill_estimate_and_vehicle
|
||||||
|
customer = @appointment.customer
|
||||||
|
return unless customer
|
||||||
|
|
||||||
|
if params[:estimate_id].present? && customer.estimates.exists?(id: params[:estimate_id])
|
||||||
|
@appointment.estimate_id = params[:estimate_id]
|
||||||
|
end
|
||||||
|
if params[:vehicle_id].present? && customer.respond_to?(:vehicles) && customer.vehicles.exists?(id: params[:vehicle_id])
|
||||||
|
@appointment.vehicle_id = params[:vehicle_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def appointment_params
|
def appointment_params
|
||||||
|
|
||||||
params
|
params
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<%# Add appointment link on an estimate's page (redmine_qbo_billing) %>
|
||||||
|
<% 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) %>
|
||||||
|
<%= 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),
|
||||||
|
class: 'icon icon-time-add', target: :_blank %>
|
||||||
|
<% end %>
|
||||||
@@ -19,6 +19,16 @@ module RedmineQboCalendar
|
|||||||
context[:hook_caller].render(partial: 'customer_appointments/customer_actions',
|
context[:hook_caller].render(partial: 'customer_appointments/customer_actions',
|
||||||
locals: { customer: context[:customer] })
|
locals: { customer: context[:customer] })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Adds "Add appointment" to an estimate's page in redmine_qbo_billing (:view_qbo_estimate_contextual),
|
||||||
|
# with the customer, the estimate and the vehicle matching its VIN filled in
|
||||||
|
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] })
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in new issue
Block a user