mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-11-18 02:40:37 -05:00
Invoices: VIN from work orders, one vehicle per invoice
Listens for redmine_qbo_billing's hooks: qbo_billing_issue_values gives each work order's VIN, so the invoice's VIN box fills in when its time or estimates are imported; qbo_billing_validate stops an invoice whose work orders are for more than one vehicle (one vehicle per invoice). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
4 files changed
+46
No files matched your search
@@ -18,6 +18,7 @@ The goal of this project is to enable vehicle tracking for customer vehicles wit
|
|||||||
|
|
||||||
* **Asset Tracking:** Adds vehicles owned by customers to the system.
|
* **Asset Tracking:** Adds vehicles owned by customers to the system.
|
||||||
* **Issue Association:** Allows these vehicles to be attached directly to Redmine issues for better service tracking.
|
* **Issue Association:** Allows these vehicles to be attached directly to Redmine issues for better service tracking.
|
||||||
|
* **Invoices (with [redmine_qbo_billing](https://github.com/rickbarrette/redmine_qbo_billing)):** importing a work order's time or estimate fills the invoice's VIN box with its vehicle's VIN, and an invoice whose work orders are for more than one vehicle isn't saved (one vehicle per invoice).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ en:
|
|||||||
warn_ru_sure: "Are you sure?"
|
warn_ru_sure: "Are you sure?"
|
||||||
|
|
||||||
alert_vehicle_has_issues: "This vehicle has issues, so it can't be deleted (that would lose its service history). If it was sold, change its customer instead."
|
alert_vehicle_has_issues: "This vehicle has issues, so it can't be deleted (that would lose its service history). If it was sold, change its customer instead."
|
||||||
|
error_one_vehicle_per_invoice: "Only one vehicle per invoice: these work orders are for %{vehicles}. Make a separate invoice for each vehicle."
|
||||||
error_vehicle_customer_mismatch: "Vehicle %{vehicle} belongs to a different customer. Pick one of this customer's vehicles."
|
error_vehicle_customer_mismatch: "Vehicle %{vehicle} belongs to a different customer. Pick one of this customer's vehicles."
|
||||||
error_vehicle_not_found_for_issue: "The selected vehicle no longer exists."
|
error_vehicle_not_found_for_issue: "The selected vehicle no longer exists."
|
||||||
error_vin_status_check_failed: "Error checking VIN status."
|
error_vin_status_check_failed: "Error checking VIN status."
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ module RedmineQboVehicles
|
|||||||
Vehicles::Hooks::PdfHookListener
|
Vehicles::Hooks::PdfHookListener
|
||||||
Vehicles::Hooks::ViewHookListener
|
Vehicles::Hooks::ViewHookListener
|
||||||
Vehicles::Hooks::CustomerAppointmentShowHookListener
|
Vehicles::Hooks::CustomerAppointmentShowHookListener
|
||||||
|
Vehicles::Hooks::BillingHookListener
|
||||||
|
|
||||||
# If the SubtaskFieldCopier plugin is installed, register our fields
|
# If the SubtaskFieldCopier plugin is installed, register our fields
|
||||||
if defined?(SubtaskFieldCopier)
|
if defined?(SubtaskFieldCopier)
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#The MIT License (MIT)
|
||||||
|
#
|
||||||
|
#Copyright (c) 2026 rick barrette
|
||||||
|
#
|
||||||
|
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
module Vehicles
|
||||||
|
module Hooks
|
||||||
|
|
||||||
|
# Hooks for redmine_qbo_billing's estimates and invoices
|
||||||
|
class BillingHookListener < Redmine::Hook::Listener
|
||||||
|
|
||||||
|
# Each work order's VIN, so the invoice's VIN box is filled when its time or estimates are imported
|
||||||
|
def qbo_billing_issue_values(context = {})
|
||||||
|
vins = Array(context[:issues]).each_with_object({}) do |issue, by_issue|
|
||||||
|
vin = issue.respond_to?(:vehicle) ? issue.vehicle&.vin : nil
|
||||||
|
by_issue[issue.id] = vin if vin.present?
|
||||||
|
end
|
||||||
|
{ vin: vins }
|
||||||
|
end
|
||||||
|
|
||||||
|
# One vehicle per invoice (OSOR SOP): an invoice whose work orders are for more than one vehicle
|
||||||
|
# isn't saved
|
||||||
|
def qbo_billing_validate(context = {})
|
||||||
|
return nil unless context[:document].to_s == 'invoice'
|
||||||
|
|
||||||
|
vehicles = Array(context[:issues]).filter_map { |issue| issue.respond_to?(:vehicle) ? issue.vehicle : nil }.uniq
|
||||||
|
return nil if vehicles.size <= 1
|
||||||
|
|
||||||
|
details = vehicles.map do |vehicle|
|
||||||
|
numbers = Array(context[:issues]).select { |issue| issue.vehicle == vehicle }.map { |issue| "##{issue.id}" }
|
||||||
|
"#{vehicle} (#{numbers.join(', ')})"
|
||||||
|
end
|
||||||
|
I18n.t(:error_one_vehicle_per_invoice, vehicles: details.join('; '))
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in new issue
Block a user