mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-11-18 02:40:37 -05:00
Add Vehicle from an appointment sets it there and returns
The appointment page's Add Vehicle link (shown when the appointment has none) now carries the appointment and a back_url. Creating the vehicle calls a new :controller_vehicles_new_after_save hook; this plugin's listener sets the vehicle on that appointment (same customer, no vehicle yet, user may edit appointments) and the form redirects back to the appointment. The calendar plugin is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
7 files changed
+57
-6
No files matched your search
@@ -47,7 +47,11 @@ class VehiclesController < ApplicationController
|
||||
|
||||
if @vehicle.save
|
||||
flash[:notice] = t :notice_vehicle_created
|
||||
redirect_to @vehicle
|
||||
# For whatever the vehicle was added from (e.g. an appointment, which then gets this vehicle: see
|
||||
# Vehicles::Hooks::AppointmentVehicleHookListener). Context: params, vehicle
|
||||
call_hook(:controller_vehicles_new_after_save, params: params, vehicle: @vehicle)
|
||||
# Back to where the vehicle was added from (back_url), else the vehicle
|
||||
redirect_back_or_default @vehicle
|
||||
else
|
||||
# A duplicate VIN: point to the vehicle that already has it
|
||||
@existing_vehicle = Vehicle.find_by(vin: @vehicle.vin) if @vehicle.errors.of_kind?(:vin, :taken)
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<%# On an appointment without a vehicle: add one for the customer; once created, it's set on this appointment
|
||||
and you're brought back here (Vehicles::Hooks::AppointmentVehicleHookListener) %>
|
||||
<% if User.current.allowed_to?(:add_vehicles, nil, global: true) %>
|
||||
<% if appointment.customer.present? %>
|
||||
<% unless appointment.vehicle.present? %>
|
||||
<p>
|
||||
<%= link_to new_vehicle_path(customer_id: appointment.customer_id), class: 'icon icon-add' do %>
|
||||
<%= link_to new_vehicle_path(customer_id: appointment.customer_id, appointment_id: appointment.id,
|
||||
back_url: customer_appointment_path(appointment)), class: 'icon icon-add' do %>
|
||||
<%= l(:label_add_vehicle) %>
|
||||
<% end %>
|
||||
</p>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
@@ -1,9 +1,12 @@
|
||||
<h2><%= link_to l(:field_vehicles), vehicles_path %> » <%= l(:label_new_vehicle) %></h2>
|
||||
|
||||
<%= labelled_form_for @vehicle do |f| %>
|
||||
<%# Where to go back to, and what the vehicle is being added for (see VehiclesController#create) %>
|
||||
<%= back_url_hidden_field_tag %>
|
||||
<%= hidden_field_tag 'appointment_id', params[:appointment_id] if params[:appointment_id].present? %>
|
||||
<%= render partial: 'vehicles/form', locals: { f: f } %>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= link_to l(:button_cancel), @vehicle.customer ? customer_path(@vehicle.customer) : vehicles_path %>
|
||||
<%= link_to l(:button_cancel), validate_back_url(params[:back_url].to_s) || (@vehicle.customer ? customer_path(@vehicle.customer) : vehicles_path) %>
|
||||
<% end %>
|
||||
|
||||
<% html_title(l(:label_new_vehicle)) -%>
|
||||
Reference in new issue
Block a user