Own the QuickBooks VIN and Mileage fields

redmine_qbo now handles QuickBooks custom fields generically; this plugin claims the fields named like
VIN and Mileage (Vehicles::QboFields) and supplies their behaviour:

- qbo_billing_issue_values keyed by field id; qbo_billing_field_options (the customer's vehicles for the
  VIN box) and qbo_billing_field_defaults (the work orders' VIN and highest mileage) replace the VIN hooks.
- Editor script (view_qbo_estimate_form_bottom): VINs in capitals; importing time or estimates fills the
  VIN from the work orders' vehicle (or an estimate's own VIN), warns about several vehicles, and fills
  the highest mileage. The several-vehicle and missing-VIN-field texts moved here.
- qbo_calendar_appointment_params: an appointment added from an estimate gets the vehicle with its VIN.
- The estimate's VIN is read through redmine_qbo's generic custom_field_value.

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 11:34:28 -04:00
1 parent 1aa2fa9d5e
commit 70f4ce7e4a
7 files changed
+150 -19

No files matched your search

@@ -0,0 +1,51 @@
<%#
redmine_qbo's estimate/invoice editor: this plugin's part of the VIN and Mileage custom fields (see
Vehicles::QboFields). Uses redmine_qbo's window.qboEditor and its qbo:imported event:
- VINs are shown in capitals
- importing time or estimates fills the VIN from the work orders' vehicle (or an estimate's own VIN when
its work orders give none), warns when they're for more than one vehicle, and fills the highest mileage
%>
<% vin_field = Vehicles::QboFields.vin_field %>
<% mileage_field = Vehicles::QboFields.mileage_field %>
<%= javascript_tag do %>
$(function () {
var ed = window.qboEditor;
if (!ed) return;
var vinId = <%= raw (vin_field && vin_field.id.to_s).to_json %>;
var mileageId = <%= raw (mileage_field && mileage_field.id.to_s).to_json %>;
var $vin = vinId ? ed.field(vinId) : $();
$vin.css({ fontFamily: 'monospace', textTransform: 'uppercase', width: '220px' })
.on('blur', function () { this.value = this.value.trim().toUpperCase(); });
<% if vin_field.nil? && User.current.admin? && RedmineQboBilling::Company.settings.present? %>
$('<em class="info">').text(<%= raw l(:text_no_vin_field).to_json %>).appendTo(ed.form.find('.qbo-estimate-details').first());
<% end %>
var number = function (value) {
var n = parseFloat(String(value || '').replace(/[^0-9.\-]/g, ''));
return isNaN(n) ? null : n;
};
ed.form.on('qbo:imported', function (event, data) {
var values = data.issue_values || {}, vins = [], mileage = null;
var addVin = function (vin) {
vin = String(vin || '').trim().toUpperCase();
if (vin && vins.indexOf(vin) < 0) vins.push(vin);
};
(data.issue_ids || []).forEach(function (id) {
var v = values[String(id)] || {};
if (vinId) addVin(v[vinId]);
var miles = mileageId ? number(v[mileageId]) : null;
if (miles !== null && (mileage === null || miles > mileage)) mileage = miles;
});
// An imported estimate whose work orders give no VIN adds its own
(data.estimates || []).forEach(function (estimate) {
var fromIssue = vinId && estimate.issue_id && (values[String(estimate.issue_id)] || {})[vinId];
if (vinId && !fromIssue) addVin((estimate.custom_fields || {})[vinId]);
});
if (vins.length === 1 && $vin.length && !$vin.prop('disabled')) $vin.val(vins[0]);
if (mileage !== null) ed.field(mileageId).val(String(mileage));
if (vins.length > 1) window.alert(<%= raw l(:text_invoice_many_vehicles).to_json %> + ' ' + vins.join(', '));
});
});
<% end %>