mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-11-18 02:40:37 -05:00
Vehicles page lists every vehicle, sortable, searched like the customers page
- The Vehicles page shows all vehicles without a search: a Redmine list with vehicle, VIN (click to copy), customer, last serviced date and mileage, and last update, sortable by column and paged by Redmine with its per-page choices - Search narrows it to the vehicles matching every word (a single match opens it); sorting still applies and Clear goes back to everyone - A customer's vehicles (/customers/:id/vehicles) are the same list for that customer, under a Customers » customer » Vehicles trail, with New Vehicle; its search stays within the customer - Last serviced for a page of vehicles in one query (Vehicle.last_service_infos); ties on the issue's date go to the newest issue, here and on the vehicle page - The customer page's vehicle list says "No data to display" when empty, not the search wording Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4db8b812dc
commit
063e5f12cf
7 files changed
+110
-19
No files matched your search
+16
-2
@@ -51,7 +51,7 @@ class Vehicle < ApplicationRecord
|
||||
.joins(:custom_values)
|
||||
.where(custom_values: { custom_field_id: field.id })
|
||||
.where.not(custom_values: { value: ['', nil] })
|
||||
.order(created_on: :desc)
|
||||
.order(created_on: :desc, id: :desc)
|
||||
.first
|
||||
end
|
||||
|
||||
@@ -65,13 +65,27 @@ class Vehicle < ApplicationRecord
|
||||
.joins(:custom_values)
|
||||
.where(custom_values: { custom_field_id: field.id })
|
||||
.where.not(custom_values: { value: ['', nil] })
|
||||
.order(created_on: :desc)
|
||||
.order(created_on: :desc, id: :desc)
|
||||
.pick(:created_on, 'custom_values.value')
|
||||
end
|
||||
|
||||
@last_service_info = row && { date: row[0]&.to_date, mileage: row[1].presence }
|
||||
end
|
||||
|
||||
# last_service_info for many vehicles in one query (a list's Last serviced column):
|
||||
# { vehicle id => { date:, mileage: } }, leaving out vehicles without a mileage recorded
|
||||
def self.last_service_infos(ids)
|
||||
field = mileage_custom_field
|
||||
return {} unless field && ids.any?
|
||||
|
||||
Issue.joins(:custom_values)
|
||||
.where(vehicle_id: ids, custom_values: { custom_field_id: field.id })
|
||||
.where.not(custom_values: { value: ['', nil] })
|
||||
.order(created_on: :desc, id: :desc)
|
||||
.pluck(:vehicle_id, :created_on, 'custom_values.value')
|
||||
.each_with_object({}) { |(id, on, value), infos| infos[id] ||= { date: on&.to_date, mileage: value.presence } }
|
||||
end
|
||||
|
||||
def last_service_date
|
||||
last_service_info&.dig(:date)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user