Move vehicle code out to redmine_qbo_vehicles

- IssueMileageListener removed: redmine_qbo_vehicles answers qbo_billing_issue_values with mileage.
- New hook qbo_billing_build_issue sets plugins' fields on issues created from an estimate; the vehicle
  lookup by VIN moved to redmine_qbo_vehicles.
- New hook qbo_billing_vin_options gives the VIN box's suggestions (RedmineQboBilling.vin_options)
  instead of reading customer.vehicles.
- The customer page's New issue link script is generic: any checkbox with
  data-new-issue-param="issue[field]" fills that field.

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-31 09:12:52 -04:00
1 parent 3304fce92f
commit 06a78ebccb
11 files changed
+75 -112

No files matched your search

+6 -3
View File
@@ -123,7 +123,7 @@ Estimates and invoices keep their number, date, customer, total and **man-hours*
* **Undo import** puts the lines back until the invoice is saved. * **Undo import** puts the lines back until the invoice is saved.
* **An estimate is billed once**: an estimate that's on an invoice (linked to one, or closed) or was rejected can't be made into an invoice or imported, and its page shows the invoice it's billed on. This is checked against QuickBooks again when the invoice is saved, so an estimate invoiced meanwhile (in another tab, by someone else, or in QuickBooks) stops the save. * **An estimate is billed once**: an estimate that's on an invoice (linked to one, or closed) or was rejected can't be made into an invoice or imported, and its page shows the invoice it's billed on. This is checked against QuickBooks again when the invoice is saved, so an estimate invoiced meanwhile (in another tab, by someone else, or in QuickBooks) stops the save.
* Time lines are linked to their time activities, so QuickBooks marks the time as billed. Estimates the invoice was made from, or imported into it, are linked and closed when it's saved. * Time lines are linked to their time activities, so QuickBooks marks the time as billed. Estimates the invoice was made from, or imported into it, are linked and closed when it's saved.
* **VIN and mileage from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. When they're imported, the VIN box takes their vehicle's VIN (with redmine_qbo_vehicles) and a **Mileage** box (shown when QuickBooks has a text custom field named like "Mileage") takes the highest value of the issues' Mileage custom field. With redmine_qbo_vehicles, an invoice whose work orders are for more than one vehicle isn't saved. * **VIN and mileage from the work orders**: the issues behind an invoice are the ones its time lines and lineitems estimates name. When they're imported, the VIN box takes their vehicle's VIN and a **Mileage** box (shown when QuickBooks has a text custom field named like "Mileage") takes the highest value of the issues' Mileage custom field, both supplied by redmine_qbo_vehicles. With redmine_qbo_vehicles, an invoice whose work orders are for more than one vehicle isn't saved.
* **Sales person**: an invoice credits the sales person on the estimate it was made from (the first linked estimate that names one); if none does, the user who writes the invoice. * **Sales person**: an invoice credits the sales person on the estimate it was made from (the first linked estimate that names one); if none does, the user who writes the invoice.
* Invoices with a payment applied open read-only. The due date is left to QuickBooks (from the customer's terms) unless one is picked. The "default message shown on invoices" fills in the message. * Invoices with a payment applied open read-only. The due date is left to QuickBooks (from the customer's terms) unless one is picked. The "default message shown on invoices" fills in the message.
@@ -218,10 +218,13 @@ View Hook|:pdf_right, { issue: issue } | Used to add text to right side of PDF
View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view View Hook|:show_customer_view_right, { customer: customer } | Used to show partials on right side of customer view
Hook| :qbo_additional_entities | Used to add additional entites to be processed by the WebhookProcessJob Hook| :qbo_additional_entities | Used to add additional entites to be processed by the WebhookProcessJob
Hook| :qbo_full_sync | Used to add a Class to be called by the QboSyncDispatcher Hook| :qbo_full_sync | Used to add a Class to be called by the QboSyncDispatcher
Hook|:qbo_billing_issue_values, { issues: } | Return `{ field => { issue_id => value } }` for the work orders behind an invoice, e.g. `{ vin: { 116 => "1C4..." } }` (redmine_qbo_vehicles). Importing time or estimates fills the VIN box when the work orders share one VIN, and the mileage box with the highest mileage (read from the issue custom field named "Mileage") Hook|:qbo_billing_issue_values, { issues: } | Return `{ field => { issue_id => value } }` for the work orders behind an invoice, e.g. `{ vin: { 116 => "1C4..." } }` (redmine_qbo_vehicles). Importing time or estimates fills the VIN box when the work orders share one VIN, and the mileage box with the highest `mileage` value (redmine_qbo_vehicles reads it from the issue custom field named "Mileage")
Hook|:qbo_billing_validate, { document:, form:, issues: } | Return an error message (or several) to stop an estimate or invoice from saving, e.g. redmine_qbo_vehicles: one vehicle per invoice Hook|:qbo_billing_validate, { document:, form:, issues: } | Return an error message (or several) to stop an estimate or invoice from saving, e.g. redmine_qbo_vehicles: one vehicle per invoice
Hook|:qbo_billing_issue_defaults, { estimate:, params: } | Return `start_date`, `due_date`, `assignee`, `vehicle_id`, `project`, `description`, `return_path`, `return_label` for issues created from an estimate (redmine_qbo_calendar, when opened from an appointment) Hook|:qbo_billing_issue_defaults, { estimate:, params: } | Return `start_date`, `due_date`, `assignee`, `project`, `description`, `return_path`, `return_label`, plus any values your own fields need (e.g. redmine_qbo_calendar's `vehicle_id`), for issues created from an estimate (redmine_qbo_calendar, when opened from an appointment)
Hook|:qbo_billing_build_issue, { issue:, estimate:, defaults: } | Set your plugin's own fields on each issue created from an estimate, before it's saved (redmine_qbo_vehicles sets the vehicle: the one in `defaults`, or the customer's vehicle whose VIN is on the estimate)
Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after issues are created from an estimate Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after issues are created from an estimate
Hook|:qbo_billing_vin_options, { customer: } | Return `[{ vin:, name: }, ...]` to suggest in the estimate/invoice VIN box; one suggestion fills an empty box (redmine_qbo_vehicles: the customer's vehicles)
View|checkboxes with `data-new-issue-param="issue[field]"` on the customer page | Ticking one adds `issue[field]=value` to the New issue link, one per field (redmine_qbo's estimates, redmine_qbo_vehicles' vehicles)
View Hook|:view_qbo_estimate_contextual, { estimate_id:, customer_id:, vin:, doc_number: } | Adds links to an estimate page's action area (e.g. redmine_qbo_calendar's Add appointment) View Hook|:view_qbo_estimate_contextual, { estimate_id:, customer_id:, vin:, doc_number: } | Adds links to an estimate page's action area (e.g. redmine_qbo_calendar's Add appointment)
Other plugins create estimates with `RedmineQboBilling::EstimateWriter.create_estimate(customer:, lines:, private_note:, vin:, mileage:, user:)`; each line is a hash of `description`, `item_id`, `quantity`, `rate` and `taxable`. Other plugins create estimates with `RedmineQboBilling::EstimateWriter.create_estimate(customer:, lines:, private_note:, vin:, mileage:, user:)`; each line is a hash of `description`, `item_id`, `quantity`, `rate` and `taxable`.
+3 -3
View File
@@ -106,18 +106,18 @@ class QboEstimatesController < ApplicationController
end end
end end
# Customer details for the editor when a customer is picked: email, billing address and vehicles (VINs) # Customer details for the editor when a customer is picked: email, billing address and the VINs plugins
# suggest for the VIN box (RedmineQboBilling.vin_options)
def customer_info def customer_info
customer = Customer.find_by(id: params[:customer_id]) customer = Customer.find_by(id: params[:customer_id])
return render(json: {}, status: :not_found) unless customer return render(json: {}, status: :not_found) unless customer
vehicles = customer.respond_to?(:vehicles) ? customer.vehicles.to_a : []
render json: { render json: {
id: customer.id, id: customer.id,
name: customer.name, name: customer.name,
email: RedmineQboBilling::EstimateWriter.customer_email(customer), email: RedmineQboBilling::EstimateWriter.customer_email(customer),
billing_address: RedmineQboBilling::EstimateWriter.customer_address(customer), billing_address: RedmineQboBilling::EstimateWriter.customer_address(customer),
vehicles: vehicles.select { |v| v.vin.present? }.map { |v| { vin: v.vin, name: v.to_s } } vin_options: RedmineQboBilling.vin_options(customer)
} }
end end
@@ -1,59 +1,45 @@
<%# <%#
Adds the estimate and vehicle ticked on the customer page to the "New issue" link Adds what's ticked on the customer page to the "New issue" link (#dynamic-new-issue-link in the contextual
(#dynamic-new-issue-link in the contextual area). One of each can be ticked. area). Any checkbox with data-new-issue-param="issue[field]" takes part, one ticked per field: this plugin's
estimates (issue[estimate_id]), and other plugins' lists (e.g. redmine_qbo_vehicles' issue[vehicle_id]).
%> %>
<script> <script>
function handleSingleSelect(event, className) { function newIssueParamBoxes(param) {
if (event.target.checked) { return Array.prototype.filter.call(document.querySelectorAll('input[data-new-issue-param]'), function (cb) {
// Uncheck all other checkboxes of the same type return !param || cb.getAttribute('data-new-issue-param') === param;
document.querySelectorAll('.' + className).forEach(cb => { });
if (cb !== event.target) {
cb.checked = false;
} }
// One box per field: ticking one unticks the others for the same field
document.addEventListener('change', function (event) {
var box = event.target;
if (!box.matches || !box.matches('input[data-new-issue-param]')) return;
if (box.checked) {
newIssueParamBoxes(box.getAttribute('data-new-issue-param')).forEach(function (cb) {
if (cb !== box) cb.checked = false;
}); });
} }
updateLink(); updateLink();
}
// Bind single-select behavior to checkboxes once the DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.estimate-checkbox').forEach(cb => {
cb.addEventListener('change', (e) => handleSingleSelect(e, 'estimate-checkbox'));
});
document.querySelectorAll('.vehicle-checkbox').forEach(cb => {
cb.addEventListener('change', (e) => handleSingleSelect(e, 'vehicle-checkbox'));
});
}); });
function updateLink() { function updateLink() {
const link = document.getElementById('dynamic-new-issue-link'); var link = document.getElementById('dynamic-new-issue-link');
if (!link) return; if (!link) return;
// Cache the pristine base URL on first run // Cache the pristine base URL on first run
if (!link.dataset.baseUrl) { if (!link.dataset.baseUrl) link.dataset.baseUrl = link.getAttribute('href');
link.dataset.baseUrl = link.getAttribute('href'); var url = new URL(link.dataset.baseUrl, window.location.origin);
}
// Build base URL object newIssueParamBoxes().forEach(function (cb) {
let url = new URL(link.dataset.baseUrl, window.location.origin); var param = cb.getAttribute('data-new-issue-param');
var ticked = newIssueParamBoxes(param).filter(function (b) { return b.checked; })[0];
// 1. Handle Single Estimate if (ticked) {
const checkedEstimate = document.querySelector('.estimate-checkbox:checked'); url.searchParams.set(param, ticked.value);
if (checkedEstimate) {
url.searchParams.set('issue[estimate_id]', checkedEstimate.value);
} else { } else {
url.searchParams.delete('issue[estimate_id]'); url.searchParams.delete(param);
} }
});
// 2. Handle Single Vehicle
const checkedVehicle = document.querySelector('.vehicle-checkbox:checked');
if (checkedVehicle) {
url.searchParams.set('issue[vehicle_id]', checkedVehicle.value);
} else {
url.searchParams.delete('issue[vehicle_id]');
}
// Update the link's href attribute
link.setAttribute('href', url.toString()); link.setAttribute('href', url.toString());
} }
</script> </script>
+1 -1
View File
@@ -1,5 +1,5 @@
<div class="contextual"> <div class="contextual">
<%# New issue for this customer; picks up the estimate / vehicle ticked on this page %> <%# New issue for this customer; picks up what's ticked on this page (an estimate, other plugins' items) %>
<%= link_to sprite_icon('add', l(:label_new_issue)), new_issue_path(issue: { customer_id: @customer.id }), <%= link_to sprite_icon('add', l(:label_new_issue)), new_issue_path(issue: { customer_id: @customer.id }),
id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank %> id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank %>
<%# Plugins add their customer actions here (e.g. redmine_qbo_calendar's Add appointment) %> <%# Plugins add their customer actions here (e.g. redmine_qbo_calendar's Add appointment) %>
+1 -1
View File
@@ -2,7 +2,7 @@
<% estimates.sort.reverse.each do |estimate| %> <% estimates.sort.reverse.each do |estimate| %>
<div class="row"> <div class="row">
<%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { text: "Estimate ##{estimate.doc_number}" }, class: "estimate-checkbox appointment" %> <%= check_box_tag "estimate_ids[]", estimate.id, false, onchange: "updateLink()", data: { text: "Estimate ##{estimate.doc_number}", new_issue_param: 'issue[estimate_id]' }, class: "estimate-checkbox appointment" %>
<b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %> <b><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b> <%= estimate.txn_date %>
<%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %> <%= render partial: 'qbo_estimates/estimate_actions', locals: { estimate: estimate } if RedmineQboBilling.writer? %>
</div> </div>
+4 -3
View File
@@ -4,7 +4,8 @@
vin_field = company.vin_field vin_field = company.vin_field
mileage_field = company.mileage_field mileage_field = company.mileage_field
customer = Customer.find_by(id: form.customer_id) if form.customer_id.present? customer = Customer.find_by(id: form.customer_id) if form.customer_id.present?
vehicles = customer.respond_to?(:vehicles) ? customer.vehicles.select { |v| v.vin.present? } : [] # VINs other plugins suggest for the VIN box (e.g. redmine_qbo_vehicles: the customer's vehicles)
vin_options = RedmineQboBilling.vin_options(customer)
# When QuickBooks' settings couldn't be read at all, the page header says so instead of each field # When QuickBooks' settings couldn't be read at all, the page header says so instead of each field
settings_read = company.settings.present? settings_read = company.settings.present?
# The same editor writes estimates and invoices # The same editor writes estimates and invoices
@@ -121,8 +122,8 @@
<%= text_field_tag 'estimate[vin]', form.vin, id: 'qbo_estimate_vin', list: 'qbo-estimate-vins', maxlength: 31, <%= text_field_tag 'estimate[vin]', form.vin, id: 'qbo_estimate_vin', list: 'qbo-estimate-vins', maxlength: 31,
autocomplete: 'off', spellcheck: false, disabled: vin_field.nil? %> autocomplete: 'off', spellcheck: false, disabled: vin_field.nil? %>
<datalist id="qbo-estimate-vins"> <datalist id="qbo-estimate-vins">
<% vehicles.each do |vehicle| %> <% vin_options.each do |option| %>
<option value="<%= vehicle.vin %>"><%= vehicle.to_s %></option> <option value="<%= option[:vin] %>"><%= option[:name] %></option>
<% end %> <% end %>
</datalist> </datalist>
<% if settings_read && !vin_field %> <% if settings_read && !vin_field %>
+7 -5
View File
@@ -283,12 +283,14 @@ $(function () {
loadedEmail = info.email || ''; loadedEmail = info.email || '';
$('#qbo-estimate-address').text(info.billing_address || ''); $('#qbo-estimate-address').text(info.billing_address || '');
// VINs plugins suggest for this customer (e.g. their vehicles); one fills an empty VIN box
var options = info.vin_options || [];
var $list = $('#qbo-estimate-vins').empty(); var $list = $('#qbo-estimate-vins').empty();
(info.vehicles || []).forEach(function (vehicle) { options.forEach(function (option) {
$('<option>').attr('value', vehicle.vin).text(vehicle.name).appendTo($list); $('<option>').attr('value', option.vin).text(option.name).appendTo($list);
}); });
if ($vin.length && !$vin.prop('disabled') && !$vin.val().trim() && (info.vehicles || []).length === 1) { if ($vin.length && !$vin.prop('disabled') && !$vin.val().trim() && options.length === 1) {
$vin.val(info.vehicles[0].vin); $vin.val(options[0].vin);
} }
}); });
}); });
@@ -381,7 +383,7 @@ $(function () {
return ids; return ids;
}; };
// VIN and mileage from the work orders (via plugins such as redmine_qbo_vehicles and redmine_mileage_cp): // VIN and mileage from the work orders (via plugins such as redmine_qbo_vehicles):
// one vehicle fills the VIN box; the highest mileage fills the mileage box // one vehicle fills the VIN box; the highest mileage fills the mileage box
var updateVehicleFields = function (issueIds) { var updateVehicleFields = function (issueIds) {
var values = (importData && importData.issue_values) || {}; var values = (importData && importData.issue_values) || {};
+16 -1
View File
@@ -19,7 +19,6 @@ module RedmineQboBilling
# Hooks # Hooks
RedmineQboBilling::Hooks::QboHookListener RedmineQboBilling::Hooks::QboHookListener
RedmineQboBilling::Hooks::IssueMileageListener
# Administration menu: the QuickBooks product/service list (accounts are reached from it) # Administration menu: the QuickBooks product/service list (accounts are reached from it)
Redmine::MenuManager.map :admin_menu do |menu| Redmine::MenuManager.map :admin_menu do |menu|
@@ -28,6 +27,22 @@ module RedmineQboBilling
end end
end end
# VINs to suggest in the estimate/invoice VIN box for a customer, from plugins answering
# :qbo_billing_vin_options, { customer: } => [{ vin:, name: }, ...] (e.g. redmine_qbo_vehicles: the
# customer's vehicles)
def self.vin_options(customer)
return [] unless customer
Redmine::Hook.call_hook(:qbo_billing_vin_options, { customer: customer }).flatten.compact.filter_map do |option|
option = option.to_h.symbolize_keys
vin = option[:vin].to_s.strip
{ vin: vin, name: option[:name].to_s.presence || vin } unless vin.empty?
end.uniq { |o| o[:vin].upcase }
rescue StandardError => e
Rails.logger.warn "[RedmineQboBilling] VIN suggestions failed: #{e.message}"
[]
end
# True when the user may write estimates # True when the user may write estimates
def self.writer?(user = User.current) def self.writer?(user = User.current)
user.allowed_to?(:write_estimates, nil, global: true) user.allowed_to?(:write_estimates, nil, global: true)
@@ -12,7 +12,7 @@ module RedmineQboBilling
# Turns the labor lines of a QuickBooks estimate into proposed issues, and creates the ones the user selects # Turns the labor lines of a QuickBooks estimate into proposed issues, and creates the ones the user selects
# on the "Create issues from estimate" page (moved here from redmine_qbo_calendar). # on the "Create issues from estimate" page (moved here from redmine_qbo_calendar).
# #
# - Only lines whose item matches a configured item code (e.g. "Labor", "Alignments") are proposed # - Only lines with a labor product/service (LaborItems, e.g. "Labor") are proposed
# - Subject = the line's description; estimated hours = the line's quantity # - Subject = the line's description; estimated hours = the line's quantity
# - Lines already turned into issues are shown but can't be created again # - Lines already turned into issues are shown but can't be created again
# - Creation is all-or-nothing: if any issue fails validation, none are saved # - Creation is all-or-nothing: if any issue fails validation, none are saved
@@ -20,8 +20,10 @@ module RedmineQboBilling
# #
# Other plugins fill in more through hooks: # Other plugins fill in more through hooks:
# :qbo_billing_issue_defaults, { estimate:, params: } => a hash of start_date, due_date, assignee, # :qbo_billing_issue_defaults, { estimate:, params: } => a hash of start_date, due_date, assignee,
# vehicle_id, description, project, return_path, return_label (e.g. redmine_qbo_calendar, when the page is # description, project, return_path, return_label, plus anything a plugin's own fields need (e.g.
# opened from an appointment) # redmine_qbo_calendar's vehicle_id, when the page is opened from an appointment)
# :qbo_billing_build_issue, { issue:, estimate:, defaults: } for each new issue before it's saved, to set
# plugins' own fields (e.g. redmine_qbo_vehicles sets the vehicle)
# :qbo_billing_issues_created, { estimate:, issues:, params: } after issues are created # :qbo_billing_issues_created, { estimate:, issues:, params: } after issues are created
class EstimateIssueBuilder class EstimateIssueBuilder
include Redmine::I18n include Redmine::I18n
@@ -89,7 +91,7 @@ module RedmineQboBilling
attr_reader :estimate, :defaults, :errors attr_reader :estimate, :defaults, :errors
# estimate: redmine_qbo's local Estimate (its QuickBooks details give the lines) # estimate: redmine_qbo's local Estimate (its QuickBooks details give the lines)
# defaults: start_date, due_date, assignee, vehicle_id, description (from another plugin's hook) # defaults: start_date, due_date, assignee, description and plugins' own values (from :qbo_billing_issue_defaults)
def initialize(estimate, defaults: {}) def initialize(estimate, defaults: {})
@estimate = estimate @estimate = estimate
@defaults = (defaults || {}).to_h.symbolize_keys @defaults = (defaults || {}).to_h.symbolize_keys
@@ -218,29 +220,15 @@ module RedmineQboBilling
assignee = defaults[:assignee] assignee = defaults[:assignee]
issue.assigned_to = assignee if assignee && issue.assignable_users.include?(assignee) issue.assigned_to = assignee if assignee && issue.assignable_users.include?(assignee)
# Customer / vehicle / estimate fields are added to issues by redmine_qbo and redmine_qbo_vehicles
issue.customer_id = estimate.customer_id if issue.respond_to?(:customer_id=) issue.customer_id = estimate.customer_id if issue.respond_to?(:customer_id=)
issue.vehicle_id = vehicle_id if issue.respond_to?(:vehicle_id=)
issue.estimate_id = estimate.id if issue.respond_to?(:estimate_id=) issue.estimate_id = estimate.id if issue.respond_to?(:estimate_id=)
# Plugins set their own fields (e.g. redmine_qbo_vehicles: the vehicle)
Redmine::Hook.call_hook(:qbo_billing_build_issue, { issue: issue, estimate: estimate, defaults: defaults })
issue issue
end end
# The vehicle from the hook, or the customer's vehicle whose VIN is on the estimate
def vehicle_id
return defaults[:vehicle_id] if defaults[:vehicle_id].present?
customer = estimate.customer
return nil unless customer.respond_to?(:vehicles)
vin = EstimateWriter.custom_value(estimate.details, Company.vin_field, Company::VIN_NAME).to_s.strip
return nil if vin.empty?
customer.vehicles.detect { |v| v.vin.to_s.casecmp?(vin) }&.id
rescue StandardError
nil
end
def default_description def default_description
defaults[:description].presence || defaults[:description].presence ||
"The purpose of this work is to bill the time spent on this issue for Estimate ##{estimate.doc_number}" "The purpose of this work is to bill the time spent on this issue for Estimate ##{estimate.doc_number}"
@@ -1,32 +0,0 @@
#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 RedmineQboBilling
module Hooks
# Each work order's mileage, from Redmine's own issue custom field named "Mileage" (any capitalisation),
# so an invoice's mileage box fills in when its time or estimates are imported. Answers the same
# qbo_billing_issue_values hook other plugins use (see IssueValues).
class IssueMileageListener < Redmine::Hook::Listener
def qbo_billing_issue_values(context = {})
issue_ids = Array(context[:issues]).map(&:id)
field = IssueCustomField.all.detect { |f| f.name.to_s.strip.casecmp?('mileage') }
return {} if field.nil? || issue_ids.empty?
values = CustomValue.where(customized_type: 'Issue', customized_id: issue_ids, custom_field_id: field.id)
.where.not(value: [nil, ''])
.pluck(:customized_id, :value)
{ mileage: values.to_h }
end
end
end
end
+3 -3
View File
@@ -14,9 +14,9 @@ module RedmineQboBilling
# #
# :qbo_billing_issue_values, { issues: [Issue, ...] } # :qbo_billing_issue_values, { issues: [Issue, ...] }
# Return a hash of field => { issue_id => value }, e.g. redmine_qbo_vehicles returns # Return a hash of field => { issue_id => value }, e.g. redmine_qbo_vehicles returns
# { vin: { 116 => "1C4HJXDG5JW123456" } }. This plugin answers it too with { mileage: ... } from the # { vin: { 116 => "1C4HJXDG5JW123456" }, mileage: { 116 => "48210" } } (mileage from the issue custom
# issue custom field named "Mileage" (Hooks::IssueMileageListener). # field named "Mileage"). The invoice's VIN and mileage boxes are filled from them when time or
# The invoice's VIN and mileage boxes are filled from them when time or estimates are imported. # estimates are imported (the highest mileage wins).
# #
# :qbo_billing_validate, { document: "invoice" or "estimate", form: EstimateForm, issues: [Issue, ...] } # :qbo_billing_validate, { document: "invoice" or "estimate", form: EstimateForm, issues: [Issue, ...] }
# Return an error message (or a list of them) to stop the save, e.g. redmine_qbo_vehicles refuses an # Return an error message (or a list of them) to stop the save, e.g. redmine_qbo_vehicles refuses an