Fix vehicle dropdown after a customer change; drop vehicles.js

The issue form already reloads on the server when the customer changes
(redmine_qbo's updateIssueFrom), re-rendering the vehicle list for the
new customer. 0a3c734 broke that by always keeping the issue's current
vehicle in the list, so after changing the customer the previous
customer's vehicle stayed listed and selected.

- The current vehicle is only kept for an existing issue whose customer
  hasn't been changed in the form (keeps sold vehicles' history);
  otherwise only the selected customer's vehicles are offered
- Removes vehicles.js, which duplicated the form reload, its include and
  the JSON vehicle listing it used

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-29 19:09:47 -04:00
1 parent 133322460e
commit d4684b8ae9
4 files changed
+16 -58

No files matched your search

@@ -17,12 +17,18 @@ module Vehicles
def view_issues_form_details_bottom(context={})
# Load the customer's vehicles for selection in the issue form. The vehicle already on the issue is
# always included: after a vehicle is sold it belongs to another customer, and leaving it out
# would blank it on the next save, dropping the issue from that vehicle's history.
# The selected customer's vehicles. Changing the customer reloads the issue form (redmine_qbo's
# updateIssueFrom), which re-renders this list for the new customer.
#
# An existing issue keeps its vehicle in the list while its customer is unchanged: if the
# vehicle was sold since, it belongs to another customer now, and leaving it out would blank it
# on the next save, dropping the issue from the vehicle's history. Once the customer is changed
# in the form, only the new customer's vehicles are offered.
issue = context[:issue]
vehicles = (issue.customer&.vehicles.to_a || [])
vehicles |= [issue.vehicle] if issue.vehicle
vehicles = issue.customer&.vehicles.to_a || []
if issue.vehicle && issue.persisted? && !issue.customer_id_changed?
vehicles |= [issue.vehicle]
end
context[:controller].send(:render_to_string, {
partial: 'issues/form_hook_vehicles',
@@ -30,9 +36,8 @@ module Vehicles
vehicle: context[:form].select(
:vehicle_id,
vehicles.map { |v| [v.name, v.id] },
{ selected: context[:issue].vehicle&.id, include_blank: true },
# vehicles.js swaps in the customer id and reloads this list when the customer changes
{ data: { vehicles_url: customer_vehicles_path('__CUSTOMER_ID__') } }
selected: issue.vehicle&.id,
include_blank: true
)
}
})
+1 -2
View File
@@ -15,8 +15,7 @@ module Vehicles
def view_layouts_base_html_head(context = {})
safe_join([
stylesheet_link_tag('style', plugin: :redmine_qbo_vehicles, media: :all),
javascript_include_tag('copy', plugin: :redmine_qbo_vehicles),
javascript_include_tag('vehicles', plugin: :redmine_qbo_vehicles)
javascript_include_tag('copy', plugin: :redmine_qbo_vehicles)
])
end