mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-11-17 18:40:36 -05:00
Fill the vehicle into issue subjects (<VEHICLE>)
An issue subject containing the placeholder (e.g. an issue template's "Frame Evaluation // <VEHICLE>") gets the issue's vehicle when it's saved with one: on creation, or the first save after a vehicle is added (journaled like any subject change). The placeholder is a plugin setting, "Vehicle in subjects": <VEHICLE> by default (also for settings saved before it existed), blank turns it off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff6522ad77
commit
2074ec65b9
6 files changed
+32
-1
No files matched your search
@@ -24,6 +24,7 @@ The goal of this project is to enable vehicle tracking for customer vehicles wit
|
||||
* **Estimates (redmine_qbo 2026.11.2+):** the VIN box suggests the customer's vehicles, an invoice made from an estimate without a VIN gets its work orders' vehicle, and the Create issues from estimate page has a **Vehicle** for all the issues: preselected with the appointment's vehicle, or else the customer's vehicle whose VIN is on the estimate; when none matches it says so, so the team can pick one before creating the issues.
|
||||
* **Vehicles page:** every vehicle in a Redmine list (vehicle, VIN, customer, last serviced date and mileage, last update), sortable by column and paged with Redmine's pagination and per-page choices. Search narrows it to the vehicles matching every word (e.g. "2018 jeep wrangler"; a single match opens it). A customer's vehicles (`/customers/:id/vehicles`) are the same list for that customer, with New Vehicle.
|
||||
* **Customer page:** ticking a vehicle adds it to the New issue link.
|
||||
* **Vehicle in subjects:** an issue subject containing `<VEHICLE>` (e.g. from an issue template: `Frame Evaluation // <VEHICLE>`) gets the vehicle filled in when the issue is saved with one. The placeholder text is a plugin setting; blank turns it off.
|
||||
* **Appointments (redmine_qbo_calendar):** an appointment added from an estimate gets the customer's vehicle with the estimate's VIN. On an appointment without a vehicle, **Add Vehicle** creates one for the customer, sets it on the appointment and returns to it (for users who may edit appointments).
|
||||
* **For other plugins:** creating a vehicle calls the `:controller_vehicles_new_after_save` hook (context: `params`, `vehicle`), and the new vehicle form returns to `back_url` when given, so a plugin can link to `new_vehicle_path(customer_id:, back_url:, ...)` and act on the vehicle it gets back.
|
||||
|
||||
|
||||
@@ -35,6 +35,18 @@ class Vehicle < ApplicationRecord
|
||||
issues.includes(:invoices).flat_map(&:invoices).uniq.compact
|
||||
end
|
||||
|
||||
# Text in an issue's subject replaced by its vehicle (e.g. a template's "Frame Evaluation // <VEHICLE>"), or nil
|
||||
# when turned off in the plugin settings. Settings saved before this option existed get the default.
|
||||
DEFAULT_SUBJECT_PLACEHOLDER = '<VEHICLE>'
|
||||
|
||||
def self.subject_placeholder
|
||||
settings = Setting.plugin_redmine_qbo_vehicles || {}
|
||||
key = ['subject_placeholder', :subject_placeholder].detect { |k| settings.key?(k) }
|
||||
return DEFAULT_SUBJECT_PLACEHOLDER unless key
|
||||
|
||||
settings[key].to_s.strip.presence
|
||||
end
|
||||
|
||||
# The issue custom field holding mileage: the one chosen in the plugin settings, else one named "Mileage"
|
||||
def self.mileage_custom_field
|
||||
settings = Setting.plugin_redmine_qbo_vehicles || {}
|
||||
|
||||
@@ -6,4 +6,9 @@
|
||||
include_blank: true, id: 'settings_mileage_custom_field_id' %>
|
||||
<em class="info"><%= l(:text_mileage_custom_field_info) %></em>
|
||||
</p>
|
||||
<p>
|
||||
<label for="settings_subject_placeholder"><%= l(:label_subject_vehicle_placeholder) %></label>
|
||||
<%= text_field_tag 'settings[subject_placeholder]', Vehicle.subject_placeholder, id: 'settings_subject_placeholder', size: 20 %>
|
||||
<em class="info"><%= l(:text_subject_vehicle_placeholder_info) %></em>
|
||||
</p>
|
||||
</div>
|
||||
@@ -66,6 +66,8 @@ en:
|
||||
label_mileage_custom_field: "Mileage field"
|
||||
notice_vin_decode_timed_out: "VIN decode timed out. Please refresh or try again."
|
||||
text_mileage_custom_field_info: "Issue custom field used for \"Last serviced\" mileage. Leave blank to use a field named Mileage."
|
||||
label_subject_vehicle_placeholder: "Vehicle in subjects"
|
||||
text_subject_vehicle_placeholder_info: "Text in an issue's subject (e.g. from a template: Frame Evaluation // <VEHICLE>) replaced by its vehicle when one is assigned. Leave blank to turn off."
|
||||
text_vin_already_on_file: "A vehicle with this VIN is already on file:"
|
||||
text_click_to_copy: "Click to copy"
|
||||
text_copied: "Copied!"
|
||||
|
||||
@@ -27,7 +27,8 @@ Redmine::Plugin.register :redmine_qbo_vehicles do
|
||||
end
|
||||
|
||||
# Which issue custom field holds the mileage shown as "Last serviced" (blank: a field named "Mileage")
|
||||
settings default: { 'mileage_custom_field_id' => '' }, partial: 'settings/vehicles_settings'
|
||||
# Text in issue subjects replaced by the issue's vehicle (blank: off)
|
||||
settings default: { 'mileage_custom_field_id' => '', 'subject_placeholder' => '<VEHICLE>' }, partial: 'settings/vehicles_settings'
|
||||
|
||||
# Add safe attributes for core models
|
||||
Issue.safe_attributes :vehicle_id
|
||||
|
||||
@@ -22,10 +22,20 @@ module Vehicles
|
||||
# The vehicle must belong to the issue's customer. Only checked when either changes, so older
|
||||
# issues with a mismatch don't block unrelated edits.
|
||||
validate :vehicle_matches_customer, if: -> { will_save_change_to_vehicle_id? || will_save_change_to_customer_id? }
|
||||
|
||||
# A subject with the placeholder (e.g. from a template) gets the vehicle once one is assigned
|
||||
before_validation :fill_subject_vehicle
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fill_subject_vehicle
|
||||
placeholder = Vehicle.subject_placeholder
|
||||
return if placeholder.nil? || vehicle.nil? || !subject.to_s.include?(placeholder)
|
||||
|
||||
self.subject = subject.gsub(placeholder, vehicle.to_s)
|
||||
end
|
||||
|
||||
def vehicle_matches_customer
|
||||
return if vehicle_id.blank?
|
||||
|
||||
|
||||
Reference in new issue
Block a user