From ae0ffc7c1cdfe5ec1e86ac3c7dfef58abd6a1e0f Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sat, 21 Nov 2026 07:37:57 -0500 Subject: [PATCH] Leave other plugins' features to hooks Refund emails and PDFs take the shop name and mail settings from :qbo_mail_settings instead of reading redmine_qbo_reminders' settings; the customer page's ticked boxes use generic data-ticked-field/data-ticked-params instead of knowing redmine_qbo_calendar's Add appointment link; and Create issues carries the params plugins name in :qbo_billing_issue_carry_params instead of appointment_id. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 ++- app/mailers/qbo_refund_mailer.rb | 10 ++--- .../customers/_new_issue_link_script.html.erb | 43 ++++++++----------- app/views/customers/show.html.erb | 2 +- app/views/estimates/_list.html.erb | 4 +- .../qbo_estimates/issues_preview.html.erb | 4 +- lib/redmine_qbo_billing.rb | 12 ++++++ lib/redmine_qbo_billing/refund_pdf.rb | 3 +- test/integration/customers_controller_test.rb | 7 +++ test/unit/qbo_helpers_test.rb | 17 ++++++++ 10 files changed, 69 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index cf49cea..251532c 100644 --- a/README.md +++ b/README.md @@ -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. @@ -277,7 +277,9 @@ Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after 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) diff --git a/app/mailers/qbo_refund_mailer.rb b/app/mailers/qbo_refund_mailer.rb index 4bdeda5..c08dba2 100644 --- a/app/mailers/qbo_refund_mailer.rb +++ b/app/mailers/qbo_refund_mailer.rb @@ -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 diff --git a/app/views/customers/_new_issue_link_script.html.erb b/app/views/customers/_new_issue_link_script.html.erb index 5ab1858..d52f131 100644 --- a/app/views/customers/_new_issue_link_script.html.erb +++ b/app/views/customers/_new_issue_link_script.html.erb @@ -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. %>