Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8ce702cb44 | ||
|
|
ae0ffc7c1c | ||
|
|
0552e2f1a3 | ||
|
|
bc822ddc22 | ||
|
|
62d767b695 | ||
|
|
7029aa70dc | ||
|
|
ff9556e728 |
No files matched your search
@@ -162,7 +162,7 @@ Refunds for canceled orders and returned parts, following SOP-OPS-014, so they d
|
||||
1. makes the restocking fee invoice, its line showing the math ("Restocking fee: 30% × $307.99 parts on E1068 = $92.40"), and pays it from the customer's credit, oldest first (unless QuickBooks already applied the credit to it on its own);
|
||||
2. records the rest of the credit as a refund with the category **Accounts Receivable**, from the bank account in the settings, described "Refund for deposit on E1068": a **Check** for a check, an **Expense** for a card refund;
|
||||
3. applies the customer's remaining credit to that check or expense, so the deposit, the fee invoice and the refund reconcile, and reads back the customer's balance (it should be $0.00).
|
||||
* As ticked on the page, it also marks the estimate **Rejected**, sets the order's work orders to the canceled status with the reason as a note, and emails the customer a summary (through redmine_qbo_reminders' mail settings when that plugin is set up, otherwise Redmine's).
|
||||
* As ticked on the page, it also marks the estimate **Rejected**, sets the order's work orders to the canceled status with the reason as a note, and emails the customer a summary (with the shop name and mail settings another plugin gives through `:qbo_mail_settings`, e.g. redmine_qbo_reminders', otherwise Redmine's).
|
||||
* Each refund has its own page, listed on the customer page: what was refunded and how, with the fee invoice (opened in Redmine), a **PDF** of the refund (QuickBooks has no PDF of a check or an expense), the fee invoice's PDF, and **Email the customer** to send the summary again. If a QuickBooks step fails, the refund stops there and its page says which step and what was already done, to finish in QuickBooks.
|
||||
* It refunds all of the customer's remaining credit held as unapplied payments. Credit held as credit memos isn't refunded here.
|
||||
|
||||
@@ -270,14 +270,16 @@ Hook| :qbo_additional_entities | Used to add additional entites to be processed
|
||||
Hook| :qbo_full_sync | Used to add a Class to be called by the QboSyncDispatcher
|
||||
Hook|:qbo_billing_issue_values, { issues: } | Return `{ field_id => { issue_id => value } }` (QuickBooks custom field id; find yours with `RedmineQboBilling::Company.custom_field_matching(/name/)`) for the work orders behind an invoice, e.g. redmine_qbo_vehicles' VIN and mileage. They're given to the editor with imported time and estimates (the `qbo:imported` event) and put on redmine_qbo_lineitems' estimates
|
||||
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`, `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_issue_defaults, { estimate:, params:, parent_issue: } | Return `start_date`, `due_date`, `assignee`, `project`, `description`, `return_path`, `return_label`, plus any values your own fields need, for issues created from an estimate (redmine_qbo_calendar, when opened from an appointment; redmine_qbo_vehicles: the parent's or appointment's vehicle). Every plugin's hash is merged
|
||||
Hook|:qbo_billing_build_issue, { issue:, estimate:, defaults:, parent: } | Set your plugin's own fields on each issue created from an estimate, before it's saved; `parent` is the parent issue, if any (redmine_qbo_vehicles sets the vehicle: the one in `defaults`, the customer's vehicle whose VIN is on the estimate, or the parent's)
|
||||
View|:view_qbo_estimate_issues_form, { estimate:, defaults:, project: } | Draw your plugin's fields on the Create issues from estimate page, applied to every issue. Name them `issue_plugin_fields[name]`; the posted values reach `:qbo_billing_build_issue` in `defaults` (redmine_qbo_vehicles: the Vehicle, preselected from the estimate's VIN)
|
||||
Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after issues are created from an estimate
|
||||
Hook|:qbo_billing_field_defaults, { customer:, issues: } | Return `{ field_id => value }` for a document's work orders: used when an invoice is made from an estimate, for the fields it leaves blank. New estimates and invoices start blank (redmine_qbo_vehicles: the work orders' VIN and highest mileage)
|
||||
Hook|:qbo_billing_field_options, { customer: } | Return `{ field_id => [{ value:, label: }, ...] }` to suggest in the editor's custom field boxes for a customer (redmine_qbo_vehicles: the customer's vehicles for the VIN box)
|
||||
View|:view_qbo_estimate_form_bottom, { form:, document: } | Add your plugin's script to the estimate/invoice editor. It can use `window.qboEditor` (`field(id)`, `fieldNamed(/name/)`, `setFieldOptions(id, options)`) and listen for `qbo:customer-changed` and `qbo:imported` on the form (redmine_qbo_vehicles fills the VIN and mileage)
|
||||
View|checkboxes with `data-new-issue-param="issue[field]"` and `data-appointment-param="field"` on the customer page | Ticking one adds `issue[field]=value` to the New issue link and `field=value` to redmine_qbo_calendar's Add appointment link (`#appointment_link`), one per field (redmine_qbo's estimates: `estimate_id`, redmine_qbo_vehicles' vehicles: `vehicle_id`)
|
||||
View|checkboxes with `data-ticked-field="field"`, links with `data-ticked-params` on the customer page | Ticking a box adds its value to every link with `data-ticked-params`, named by that format: `issue[%s]` for the New issue link, `%s` for a plain param (e.g. redmine_qbo_calendar's Add appointment link). One box per field (redmine_qbo's estimates: `estimate_id`, redmine_qbo_vehicles' vehicles: `vehicle_id`)
|
||||
Hook|:qbo_billing_issue_carry_params | Return names of request params the Create issues from estimate page keeps through its form (redmine_qbo_calendar: `appointment_id`)
|
||||
Hook|:qbo_mail_settings | Return any of `shop_name`, `from`, `reply_to` and `delivery` (options for ActionMailer's `mail()`, e.g. an SMTP server) for customer emails such as refund summaries (redmine_qbo_reminders: its shop name and email settings). Blank ones fall back to Redmine's settings
|
||||
View Hook|:view_qbo_estimate_contextual, { estimate_id:, customer_id:, custom_fields:, doc_number: } | Adds links to an estimate page's action area (e.g. redmine_qbo_calendar's Add appointment); `custom_fields` is `{ field_id => value }`
|
||||
View Hook|:view_qbo_invoice_contextual, { invoice_id:, customer_id:, doc_number: } | Adds links to an invoice page's action area (e.g. redmine_qbo_labels' Print label)
|
||||
|
||||
@@ -285,6 +287,22 @@ Other plugins create estimates with `RedmineQboBilling::EstimateWriter.create_es
|
||||
|
||||
---
|
||||
|
||||
# Screenshots
|
||||
|
||||
All names and figures are made up.
|
||||
|
||||
<table>
|
||||
<tr><td width="50%"><img src="Screenshots/issue.png" alt="An issue with its customer, estimate and invoice, and Bill Time / Share"><br><sub>An issue with its customer, estimate and invoice, and Bill Time / Share</sub></td><td width="50%"><img src="Screenshots/issue_form.png" alt="The customer and estimate on the issue form"><br><sub>The customer and estimate on the issue form</sub></td></tr>
|
||||
<tr><td width="50%"><img src="Screenshots/issue_list.png" alt="The Customer column in issue lists"><br><sub>The Customer column in issue lists</sub></td><td width="50%"><img src="Screenshots/customers.png" alt="Customers, searchable by name or phone"><br><sub>Customers, searchable by name or phone</sub></td></tr>
|
||||
<tr><td width="50%"><img src="Screenshots/customer.png" alt="A customer: QuickBooks details, estimates and invoices"><br><sub>A customer: QuickBooks details, estimates and invoices</sub></td><td width="50%"><img src="Screenshots/estimate_editor.png" alt="Writing an estimate"><br><sub>Writing an estimate</sub></td></tr>
|
||||
<tr><td width="50%"><img src="Screenshots/estimate_linked_unlock.png" alt="An estimate linked to an issue, with Unlock to edit"><br><sub>An estimate linked to an issue, with Unlock to edit</sub></td><td width="50%"><img src="Screenshots/issues_from_estimate.png" alt="Creating issues from an estimate"><br><sub>Creating issues from an estimate</sub></td></tr>
|
||||
<tr><td width="50%"><img src="Screenshots/invoice_editor.png" alt="Writing an invoice"><br><sub>Writing an invoice</sub></td><td width="50%"><img src="Screenshots/receive_payment.png" alt="Receiving a payment"><br><sub>Receiving a payment</sub></td></tr>
|
||||
<tr><td width="50%"><img src="Screenshots/payment.png" alt="A payment and the invoices it paid"><br><sub>A payment and the invoices it paid</sub></td><td width="50%"><img src="Screenshots/business_report.png" alt="The business report"><br><sub>The business report</sub></td></tr>
|
||||
<tr><td width="50%"><img src="Screenshots/plugin_config.png" alt="Plugin settings"><br><sub>Plugin settings</sub></td><td width="50%"><img src="Screenshots/user_edit.png" alt="Linking a user to a QuickBooks employee"><br><sub>Linking a user to a QuickBooks employee</sub></td></tr>
|
||||
</table>
|
||||
|
||||
---
|
||||
|
||||
# Prerequisites
|
||||
|
||||
Before installing the plugin:
|
||||
|
||||
|
After Width: | Height: | Size: 169 KiB |
|
After Width: | Height: | Size: 122 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 98 KiB |
|
After Width: | Height: | Size: 104 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 724 KiB After Width: | Height: | Size: 104 KiB |
|
Before Width: | Height: | Size: 520 KiB After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 269 KiB After Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 148 KiB |
|
Before Width: | Height: | Size: 539 KiB |
|
Before Width: | Height: | Size: 181 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 141 KiB |
@@ -95,8 +95,8 @@ class QboEstimatesController < ApplicationController
|
||||
end
|
||||
|
||||
# Preview of the issues that can be created from the estimate's labor lines. Each line gets a tracker and
|
||||
# (optionally) a template before anything is created. Opened from an appointment, the appointment's dates,
|
||||
# technician and vehicle are used (redmine_qbo_calendar's :qbo_billing_issue_defaults).
|
||||
# (optionally) a template before anything is created. Plugins fill in defaults through
|
||||
# :qbo_billing_issue_defaults (e.g. redmine_qbo_calendar: the appointment's dates and technician).
|
||||
def issues_preview
|
||||
end
|
||||
|
||||
@@ -227,19 +227,11 @@ class QboEstimatesController < ApplicationController
|
||||
|
||||
# What the new issues start from:
|
||||
# - dates: another plugin's (e.g. the appointment's), else the parent issue's
|
||||
# - vehicle: the parent issue's, else another plugin's (e.g. the appointment's)
|
||||
# Values posted with the form (the dates, plugins' fields such as redmine_qbo_vehicles' vehicle) win.
|
||||
# - plugins' own fields: what they return for :qbo_billing_issue_defaults (they're given the parent issue)
|
||||
# Values posted with the form (the dates, plugins' fields) win.
|
||||
def build_defaults
|
||||
parent_dates = {}
|
||||
parent_vehicle = {}
|
||||
if @parent_issue
|
||||
parent_dates = { start_date: @parent_issue.start_date, due_date: @parent_issue.due_date }.compact
|
||||
if @parent_issue.respond_to?(:vehicle_id) && @parent_issue.vehicle_id.present?
|
||||
parent_vehicle = { vehicle_id: @parent_issue.vehicle_id.to_s }
|
||||
end
|
||||
end
|
||||
|
||||
parent_dates.merge(issue_defaults.compact).merge(parent_vehicle).merge(submitted_plugin_fields).merge(submitted_dates)
|
||||
parent_dates = @parent_issue ? { start_date: @parent_issue.start_date, due_date: @parent_issue.due_date }.compact : {}
|
||||
parent_dates.merge(issue_defaults.compact).merge(submitted_plugin_fields).merge(submitted_dates)
|
||||
end
|
||||
|
||||
# The Start date / Due date entered on the page, only when the form was posted. A blank one means no date.
|
||||
@@ -269,14 +261,15 @@ class QboEstimatesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# The first non-empty hash a plugin returns for :qbo_billing_issue_defaults
|
||||
# What plugins return for :qbo_billing_issue_defaults, merged (each fills in its own keys)
|
||||
def issue_defaults
|
||||
results = Redmine::Hook.call_hook(:qbo_billing_issue_defaults, { estimate: @estimate, params: params })
|
||||
(results.detect { |r| r.is_a?(Hash) && r.any? } || {}).symbolize_keys
|
||||
results = Redmine::Hook.call_hook(:qbo_billing_issue_defaults,
|
||||
{ estimate: @estimate, params: params, parent_issue: @parent_issue })
|
||||
results.select { |r| r.is_a?(Hash) }.reduce({}) { |merged, r| merged.merge(r.symbolize_keys) }
|
||||
end
|
||||
|
||||
# Plugins' own fields on the preview form (issue_plugin_fields[...], drawn by :view_qbo_estimate_issues_form),
|
||||
# only when the form was posted: { vehicle_id: "5" }
|
||||
# only when the form was posted, e.g. { some_plugin_field: "5" }
|
||||
def submitted_plugin_fields
|
||||
return {} unless request.post?
|
||||
|
||||
|
||||
@@ -21,16 +21,16 @@ class QboRefundMailer < ActionMailer::Base
|
||||
def refund_summary(refund, email)
|
||||
@refund = refund
|
||||
@customer = refund.customer
|
||||
reminders = defined?(RedmineQboReminders::Settings) ? RedmineQboReminders::Settings.current : nil
|
||||
@shop_name = reminders&.[]('shop_name').to_s.presence || Setting.app_title
|
||||
delivery = reminders ? reminders.delivery_options : {}
|
||||
settings = RedmineQboBilling.mail_settings
|
||||
@shop_name = settings[:shop_name].presence || Setting.app_title
|
||||
delivery = settings[:delivery] || {}
|
||||
if delivery.empty? && !ActionMailer::Base.perform_deliveries
|
||||
raise DeliveryOff, I18n.t(:text_refund_email_off)
|
||||
end
|
||||
|
||||
options = { to: email, from: reminders&.from.presence || Setting.mail_from.to_s,
|
||||
options = { to: email, from: settings[:from].presence || Setting.mail_from.to_s,
|
||||
subject: I18n.t(:text_refund_email_subject, shop: @shop_name, amount: RedmineQboBilling::RefundWriter.money(refund.refund_amount)) }
|
||||
options[:reply_to] = reminders.reply_to if reminders&.reply_to
|
||||
options[:reply_to] = settings[:reply_to] if settings[:reply_to]
|
||||
message = mail(options.merge(delivery)) do |format|
|
||||
format.text
|
||||
end
|
||||
|
||||
@@ -9,5 +9,15 @@
|
||||
#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.
|
||||
|
||||
class EstimateService < ServiceBase
|
||||
# Raised when an estimate can't be read from QuickBooks (e.g. QuickBooks is down or disconnected)
|
||||
class FetchError < StandardError; end
|
||||
|
||||
private
|
||||
|
||||
# Estimates are only read here (EstimateWriter saves them). When the read fails, raise an ordinary error
|
||||
# rather than ServiceBase's NotImplementedError, which callers' `rescue StandardError` would miss; nothing
|
||||
# is cached, so the next read tries QuickBooks again.
|
||||
def build_qbo_remote
|
||||
raise FetchError, "Could not read estimate ##{@local.id} from QuickBooks"
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,5 @@
|
||||
<%# Phone numbers as (401) 555-0101, left blank when the customer has none %>
|
||||
<% phone = ->(number) { digits = number.to_s.gsub(/\D/, ''); digits.present? ? number_to_phone(digits.to_i, area_code: true) : '' } %>
|
||||
<table>
|
||||
<tbody>
|
||||
|
||||
@@ -13,27 +15,27 @@
|
||||
|
||||
<tr>
|
||||
<th><%= t(:label_primary_phone) %></th>
|
||||
<td><%= number_to_phone(customer&.primary_phone&.gsub(/[^\d]/, '').to_i, area_code: true) %></td>
|
||||
<td><%= phone.call(customer&.primary_phone) %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%= t(:label_mobile_phone) %></th>
|
||||
<td><%= number_to_phone(customer&.mobile_phone&.gsub(/[^\d]/, '').to_i, area_code: true) %></td>
|
||||
<td><%= phone.call(customer&.mobile_phone) %></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%= t(:label_billing_address) %></th>
|
||||
<td><pre><%= @billing_address %></pre></td>
|
||||
<td><pre><%= RedmineQboBilling::EstimateWriter.format_address(customer.billing_address) %></pre></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%= t(:label_shipping_address) %></th>
|
||||
<td><pre><%= @shipping_address %></pre></td>
|
||||
<td><pre><%= RedmineQboBilling::EstimateWriter.format_address(customer.shipping_address) %></pre></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th><%= t(:label_account_balance) %></th>
|
||||
<td>$<%= customer.balance %></td>
|
||||
<td><%= number_to_currency(customer.balance || 0) %></td>
|
||||
</tr>
|
||||
|
||||
<% if customer.notes.present? %>
|
||||
|
||||
@@ -1,40 +1,33 @@
|
||||
<%#
|
||||
Adds what's ticked on the customer page to its links: "New issue" (#dynamic-new-issue-link in the contextual area)
|
||||
and redmine_qbo_calendar's "Add appointment" (#appointment_link). A checkbox takes part with
|
||||
data-new-issue-param="issue[field]" (New issue) and data-appointment-param="field" (Add appointment); one is
|
||||
ticked per field: this plugin's estimates (estimate_id), and other plugins' lists (e.g. redmine_qbo_vehicles'
|
||||
vehicle_id).
|
||||
Adds what's ticked on the customer page to its links. A checkbox takes part with data-ticked-field="field"
|
||||
(one is ticked per field), e.g. this plugin's estimates (estimate_id) and other plugins' lists. A link takes
|
||||
part with data-ticked-params, how each field is named in its URL: "issue[%s]" for New issue
|
||||
(#dynamic-new-issue-link), "%s" for a plain param. Other plugins' links on the page work the same way.
|
||||
%>
|
||||
<script>
|
||||
(function () {
|
||||
var LINKS = [['dynamic-new-issue-link', 'data-new-issue-param'], ['appointment_link', 'data-appointment-param']];
|
||||
var ANY = 'input[data-new-issue-param], input[data-appointment-param]';
|
||||
var BOX = 'input[data-ticked-field]';
|
||||
|
||||
function boxes(attr, param) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll('input[' + attr + ']'), function (cb) {
|
||||
return !param || cb.getAttribute(attr) === param;
|
||||
function boxes(field) {
|
||||
return Array.prototype.filter.call(document.querySelectorAll(BOX), function (cb) {
|
||||
return !field || cb.getAttribute('data-ticked-field') === field;
|
||||
});
|
||||
}
|
||||
|
||||
// Boxes for the same field (the same estimate list, the same vehicle list)
|
||||
function sameField(box) {
|
||||
for (var i = 0; i < LINKS.length; i++) {
|
||||
var attr = LINKS[i][1], param = box.getAttribute(attr);
|
||||
if (param) return boxes(attr, param);
|
||||
}
|
||||
return [box];
|
||||
function fields() {
|
||||
return boxes().map(function (cb) { return cb.getAttribute('data-ticked-field'); })
|
||||
.filter(function (field, i, all) { return all.indexOf(field) === i; });
|
||||
}
|
||||
|
||||
function updateLinks() {
|
||||
LINKS.forEach(function (pair) {
|
||||
var link = document.getElementById(pair[0]);
|
||||
if (!link) return;
|
||||
Array.prototype.forEach.call(document.querySelectorAll('a[data-ticked-params]'), function (link) {
|
||||
// Cache the pristine base URL on first run
|
||||
if (!link.dataset.baseUrl) link.dataset.baseUrl = link.getAttribute('href');
|
||||
var url = new URL(link.dataset.baseUrl, window.location.origin);
|
||||
boxes(pair[1]).forEach(function (cb) {
|
||||
var param = cb.getAttribute(pair[1]);
|
||||
var ticked = boxes(pair[1], param).filter(function (b) { return b.checked; })[0];
|
||||
var format = link.getAttribute('data-ticked-params');
|
||||
fields().forEach(function (field) {
|
||||
var param = format.replace('%s', field);
|
||||
var ticked = boxes(field).filter(function (b) { return b.checked; })[0];
|
||||
if (ticked) {
|
||||
url.searchParams.set(param, ticked.value);
|
||||
} else {
|
||||
@@ -48,9 +41,9 @@
|
||||
// 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(ANY)) return;
|
||||
if (!box.matches || !box.matches(BOX)) return;
|
||||
if (box.checked) {
|
||||
sameField(box).forEach(function (cb) { if (cb !== box) cb.checked = false; });
|
||||
boxes(box.getAttribute('data-ticked-field')).forEach(function (cb) { if (cb !== box) cb.checked = false; });
|
||||
}
|
||||
updateLinks();
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="contextual qbo-under-title">
|
||||
<%# 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 }),
|
||||
id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank %>
|
||||
id: 'dynamic-new-issue-link', class: 'icon icon-add', target: :_blank, data: { ticked_params: 'issue[%s]' } %>
|
||||
<%# Plugins add their customer actions here (e.g. redmine_qbo_calendar's Add appointment) %>
|
||||
<%= call_hook :view_customers_show_contextual, { customer: @customer } %>
|
||||
<%# Estimates, invoices and payments are handled here, each shown to users with its permission; Open in
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<% estimates.sort.reverse.each do |estimate| %>
|
||||
<%# One cell each (qbo_estimates/_status_styles lines them up in columns, so the icons line up) %>
|
||||
<div class="row">
|
||||
<%# Ticking an estimate adds it to the customer page's New issue and Add appointment links (customers/_new_issue_link_script) %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "estimate_ids[]", estimate.id, false, data: { new_issue_param: 'issue[estimate_id]', appointment_param: 'estimate_id' }, class: "estimate-checkbox" if local_assigns[:new_issue_checkboxes] %></span>
|
||||
<%# Ticking an estimate adds it to the customer page's links (customers/_new_issue_link_script) %>
|
||||
<span class="qbo-list-check"><%= check_box_tag "estimate_ids[]", estimate.id, false, data: { ticked_field: 'estimate_id' }, class: "estimate-checkbox" if local_assigns[:new_issue_checkboxes] %></span>
|
||||
<b class="qbo-list-number"><%= link_to "##{estimate.doc_number}", estimate_path(estimate), target: :_blank %></b>
|
||||
<span class="qbo-list-date"><%= estimate.txn_date %></span>
|
||||
<%# QuickBooks status, cached by the estimate sync (kept current by the webhook) %>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% html_title l(:button_create_estimate_issues) %>
|
||||
<%# Extra params to carry through (e.g. appointment_id from redmine_qbo_calendar) %>
|
||||
<% carry = request.query_parameters.merge(request.request_parameters).slice('appointment_id') %>
|
||||
<%# Params other plugins carry through the page (:qbo_billing_issue_carry_params, e.g. redmine_qbo_calendar's appointment) %>
|
||||
<% carry = request.query_parameters.merge(request.request_parameters).slice(*Redmine::Hook.call_hook(:qbo_billing_issue_carry_params, {}).flatten.compact.map(&:to_s)) %>
|
||||
|
||||
<div class="contextual">
|
||||
<%= link_to sprite_icon('angle-left', @return_label), @return_path, class: 'icon icon-angle-left' %>
|
||||
@@ -15,7 +15,7 @@
|
||||
</h2>
|
||||
|
||||
<%# Target project and parent task: changing either reloads the page (the project's trackers and templates;
|
||||
the parent's project, vehicle and custom field values) %>
|
||||
the parent's project, custom field values and plugins' fields) %>
|
||||
<%= form_tag issues_preview_qbo_estimate_path(@estimate.id), method: :get, id: 'estimate-issues-project-form' do %>
|
||||
<% carry.each do |key, value| %><%= hidden_field_tag key, value, id: nil %><% end %>
|
||||
<p>
|
||||
|
||||
@@ -15,7 +15,7 @@ en:
|
||||
error_estimate_parent_not_found: "Parent task #%{id} wasn't found, or you can't see it."
|
||||
error_estimate_parent_not_allowed: "You aren't allowed to add subtasks in %{project}."
|
||||
label_estimate_parent_placeholder: "Optional"
|
||||
text_estimate_parent_info: "The issues are created as subtasks. They get the parent's customer, and the vehicle and custom field values below start from the parent's; any left empty are filled from the parent."
|
||||
text_estimate_parent_info: "The issues are created as subtasks. They get the parent's customer, and the fields below start from the parent's; any left empty are filled from the parent."
|
||||
notice_qbo_oauth_state_mismatch: "QuickBooks connection was not completed: the request could not be verified. Please try connecting again."
|
||||
permission_bill_issues: "Bill issue time to QuickBooks"
|
||||
permission_share_issues_with_customers: "Share issues with customers"
|
||||
|
||||
@@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_qbo do
|
||||
name 'Redmine QBO plugin'
|
||||
author 'Rick Barrette'
|
||||
description 'A pluging for Redmine to connect with QuickBooks Online: customers, time activities for billable hours when an issue is closed, and estimates, invoices and payments written in Redmine'
|
||||
version '2026.11.26'
|
||||
version '2026.11.28'
|
||||
url 'https://github.com/rickbarrette/redmine_qbo'
|
||||
author_url 'https://barrettefabrication.com'
|
||||
settings default: {empty: true}, partial: 'qbo/settings'
|
||||
|
||||
@@ -30,6 +30,18 @@ module RedmineQboBilling
|
||||
# Suggestions for the editor's custom field boxes for a customer, from plugins answering
|
||||
# :qbo_billing_field_options, { customer: } => { field_id => [{ value:, label: }, ...] }
|
||||
# (e.g. redmine_qbo_vehicles: the customer's vehicles for its VIN field). Returns { "2" => [...] }.
|
||||
# The shop's name and how customer emails (refund summaries) are sent, from other plugins (e.g.
|
||||
# redmine_qbo_reminders: its shop name and SMTP server) through :qbo_mail_settings. Each returns any of
|
||||
# shop_name:, from:, reply_to:, delivery: (options for ActionMailer's mail(), e.g. an SMTP server); blank
|
||||
# ones fall back to Redmine's own settings.
|
||||
def self.mail_settings
|
||||
Redmine::Hook.call_hook(:qbo_mail_settings, {}).select { |result| result.is_a?(Hash) }
|
||||
.reduce({}) { |merged, result| merged.merge(result.symbolize_keys.compact_blank) }
|
||||
rescue StandardError => e
|
||||
Rails.logger.warn "[RedmineQboBilling] Could not read mail settings from plugins: #{e.message}"
|
||||
{}
|
||||
end
|
||||
|
||||
def self.field_options(customer)
|
||||
return {} unless customer
|
||||
|
||||
|
||||
@@ -17,16 +17,16 @@ module RedmineQboBilling
|
||||
# - 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
|
||||
# - All issues created from the same estimate are related to each other, across batches
|
||||
# - With a parent issue, the issues are created as its subtasks and take its customer, plus its vehicle and
|
||||
# custom field values where the page left them empty (the same rules as the subtask_field_copier plugin,
|
||||
# which is used when installed)
|
||||
# - With a parent issue, the issues are created as its subtasks and take its customer, plus its custom field
|
||||
# values where the page left them empty (the same rules as the subtask_field_copier plugin, which is used
|
||||
# when installed). Plugins copy their own fields from the parent in :qbo_billing_build_issue.
|
||||
#
|
||||
# Other plugins fill in more through hooks:
|
||||
# :qbo_billing_issue_defaults, { estimate:, params: } => a hash of start_date, due_date, assignee,
|
||||
# description, project, return_path, return_label, plus anything a plugin's own fields need (e.g.
|
||||
# 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_issue_defaults, { estimate:, params:, parent_issue: } => a hash of start_date, due_date,
|
||||
# assignee, description, project, return_path, return_label, plus anything a plugin's own fields need.
|
||||
# Every plugin's hash is merged.
|
||||
# :qbo_billing_build_issue, { issue:, estimate:, defaults:, parent: } for each new issue before it's saved,
|
||||
# to set plugins' own fields (e.g. redmine_qbo_vehicles sets the vehicle, else the parent's)
|
||||
# :view_qbo_estimate_issues_form, { estimate:, defaults:, project: } (view hook) draws plugins' fields on
|
||||
# the page, applied to every issue; posted as issue_plugin_fields[name], they reach :qbo_billing_build_issue
|
||||
# in defaults (e.g. redmine_qbo_vehicles' Vehicle, preselected from the estimate's VIN)
|
||||
@@ -237,7 +237,7 @@ module RedmineQboBilling
|
||||
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 })
|
||||
Redmine::Hook.call_hook(:qbo_billing_build_issue, { issue: issue, estimate: estimate, defaults: defaults, parent: parent })
|
||||
|
||||
if parent
|
||||
issue.parent_issue_id = parent.id
|
||||
@@ -248,7 +248,7 @@ module RedmineQboBilling
|
||||
end
|
||||
|
||||
# Fills the subtask's empty fields from the parent: custom fields (those the author can see on the parent
|
||||
# and edit on the subtask) and plugins' registered fields (customer, vehicle). Values entered on the page win.
|
||||
# and edit on the subtask), and with subtask_field_copier its registered fields. Values entered on the page win.
|
||||
def copy_from_parent(issue, author)
|
||||
if defined?(::SubtaskFieldCopier)
|
||||
::SubtaskFieldCopier.copy_from_parent(issue, parent, author, {})
|
||||
@@ -263,10 +263,6 @@ module RedmineQboBilling
|
||||
values[custom_value.custom_field_id.to_s] = value
|
||||
end
|
||||
issue.custom_field_values = copied if copied.any?
|
||||
|
||||
if issue.respond_to?(:vehicle_id=) && issue.vehicle_id.blank? && parent.respond_to?(:vehicle_id)
|
||||
issue.vehicle_id = parent.vehicle_id
|
||||
end
|
||||
end
|
||||
|
||||
def default_description
|
||||
|
||||
@@ -132,8 +132,7 @@ module RedmineQboBilling
|
||||
end
|
||||
|
||||
def shop_name
|
||||
reminders = defined?(RedmineQboReminders::Settings) ? RedmineQboReminders::Settings.current : nil
|
||||
reminders&.[]('shop_name').to_s.presence || Setting.app_title
|
||||
RedmineQboBilling.mail_settings[:shop_name].presence || Setting.app_title
|
||||
rescue StandardError
|
||||
Setting.app_title
|
||||
end
|
||||
|
||||
@@ -62,6 +62,13 @@ class CustomersControllerTest < Redmine::IntegrationTest
|
||||
assert_redirected_to '/customers/9101'
|
||||
end
|
||||
|
||||
def test_new_issue_picks_up_ticked_boxes
|
||||
grant(:view_customers, :add_issues)
|
||||
get '/customers/9101'
|
||||
assert_select 'a#dynamic-new-issue-link[data-ticked-params=?]', 'issue[%s]'
|
||||
assert_includes response.body, "a[data-ticked-params]"
|
||||
end
|
||||
|
||||
def test_show_lists_open_and_closed_issues
|
||||
grant(:view_customers)
|
||||
get '/customers/9101'
|
||||
@@ -72,6 +79,26 @@ class CustomersControllerTest < Redmine::IntegrationTest
|
||||
assert_response :not_found
|
||||
end
|
||||
|
||||
def test_show_details_from_quickbooks
|
||||
address = Quickbooks::Model::PhysicalAddress.new
|
||||
address.line1 = '123 Main St'
|
||||
address.city = 'Springfield'
|
||||
address.country_sub_division_code = 'RI'
|
||||
address.postal_code = '02900'
|
||||
details = Quickbooks::Model::Customer.new(display_name: 'Jane Customer', balance: BigDecimal('125'))
|
||||
details.billing_address = address
|
||||
details.primary_phone = Quickbooks::Model::TelephoneNumber.new.tap { |t| t.free_form_number = '401-555-0101' }
|
||||
@fake.customers['9101'] = details
|
||||
grant(:view_customers)
|
||||
get '/customers/9101'
|
||||
rows = css_select('table tr').to_h { |tr| [tr.at('th')&.text.to_s.strip, tr.at('td')&.text.to_s.strip] }
|
||||
assert_equal "123 Main St\nSpringfield, RI 02900", rows[I18n.t(:label_billing_address)]
|
||||
assert_equal '(401) 555-0101', rows[I18n.t(:label_primary_phone)]
|
||||
# No mobile number: blank, not "0"
|
||||
assert_equal '', rows[I18n.t(:label_mobile_phone)]
|
||||
assert_equal '$125.00', rows[I18n.t(:label_account_balance)]
|
||||
end
|
||||
|
||||
def test_autocomplete
|
||||
grant(:view_customers)
|
||||
get '/customers/autocomplete', params: { q: 'jane custmer' }
|
||||
|
||||
@@ -12,6 +12,14 @@ require File.expand_path('../../../test/test_helper', __dir__)
|
||||
require File.expand_path('qbo_fake_service', __dir__)
|
||||
require File.expand_path('qbo_editor_test_helper', __dir__)
|
||||
|
||||
# With redmine_qbo_reminders installed, refund emails go out through its SMTP server
|
||||
# (smtp-relay.gmail.com by default). Keep tests on Redmine's own (test) delivery.
|
||||
if defined?(RedmineQboReminders::Settings)
|
||||
ActiveSupport::TestCase.setup do
|
||||
Setting.plugin_redmine_qbo_reminders = { 'delivery' => 'redmine' }
|
||||
end
|
||||
end
|
||||
|
||||
module QboRefundTestHelper
|
||||
CUSTOMER_ID = 9101
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#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.
|
||||
|
||||
require File.expand_path('../test_helper', __dir__)
|
||||
|
||||
class EstimateServiceTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
Estimate.where(id: 9601).delete_all
|
||||
@estimate = Estimate.create!(id: 9601, doc_number: '1068', customer_id: 9101)
|
||||
end
|
||||
|
||||
def test_an_estimate_quickbooks_cannot_read_raises_an_ordinary_error
|
||||
QboConnectionService.stubs(:with_qbo_service).raises(RuntimeError, 'QBO not connected')
|
||||
error = assert_raises(EstimateService::FetchError) { @estimate.details }
|
||||
assert_kind_of StandardError, error
|
||||
assert_match(/9601/, error.message)
|
||||
end
|
||||
|
||||
def test_labor_hours_are_zero_while_quickbooks_is_down
|
||||
skip 'redmine_qbo_calendar is not installed' unless defined?(CustomerAppointment)
|
||||
|
||||
QboConnectionService.stubs(:with_qbo_service).raises(RuntimeError, 'QBO not connected')
|
||||
assert_equal 0, CustomerAppointment.estimate_labor_hours(@estimate)
|
||||
end
|
||||
end
|
||||
@@ -103,6 +103,23 @@ class QboHelpersTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_refund_email_with_another_plugins_mail_settings
|
||||
RedmineQboBilling.stubs(:mail_settings).returns(shop_name: 'Example Garage', from: 'Example Garage <shop@example.com>',
|
||||
reply_to: 'office@example.com')
|
||||
mail = QboRefundMailer.refund_summary(refund, 'jane@example.com')
|
||||
assert_equal ['shop@example.com'], mail.from
|
||||
assert_equal ['office@example.com'], mail.reply_to
|
||||
assert_match 'Example Garage', mail.subject
|
||||
end
|
||||
|
||||
def test_mail_settings_from_plugins
|
||||
Redmine::Hook.stubs(:call_hook).with(:qbo_mail_settings, {})
|
||||
.returns([{ shop_name: '', from: 'a@example.com' }, nil, { 'shop_name' => 'Example Garage' }])
|
||||
assert_equal({ from: 'a@example.com', shop_name: 'Example Garage' }, RedmineQboBilling.mail_settings)
|
||||
Redmine::Hook.stubs(:call_hook).with(:qbo_mail_settings, {}).raises(StandardError, 'boom')
|
||||
assert_equal({}, RedmineQboBilling.mail_settings)
|
||||
end
|
||||
|
||||
def test_refund_email_when_delivery_is_off
|
||||
ActionMailer::Base.stubs(:perform_deliveries).returns(false)
|
||||
assert_raises(QboRefundMailer::DeliveryOff) { QboRefundMailer.refund_summary(refund, 'jane@example.com').message }
|
||||
|
||||