Warn about the customer's open issues on a new invoice

A new invoice lists the customer's open issues (any project, those the user can see) in a warning under
the title, so work orders aren't left open once the work is billed. It's there when the page opens with a
customer (from the customer page or an estimate) and follows the customer when it's changed: customer_info
returns open_issues_html for invoices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-02 17:55:14 -05:00
1 parent 88160a985d
commit 4ba96e2dfd
5 files changed
+31 -2

No files matched your search

+7 -1
View File
@@ -116,13 +116,19 @@ class QboEstimatesController < ApplicationController
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
render json: { info = {
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),
field_options: RedmineQboBilling.field_options(customer) field_options: RedmineQboBilling.field_options(customer)
} }
# A new invoice warns about the customer's open issues
if params[:document] == 'invoice'
info[:open_issues_html] = render_to_string(partial: 'qbo_invoices/open_issues', formats: [:html],
locals: { customer: customer })
end
render json: info
end end
# Product/service search for the line table (the QuickBooks item list) # Product/service search for the line table (the QuickBooks item list)
+3 -1
View File
@@ -446,7 +446,9 @@ $(function () {
var id = $(this).val(); var id = $(this).val();
if (!id) return; if (!id) return;
dirty = true; dirty = true;
$.getJSON($form.data('customerInfoUrl'), { customer_id: id }).done(function (info) { $.getJSON($form.data('customerInfoUrl'), { customer_id: id, document: $form.data('document') }).done(function (info) {
// A new invoice's open issues notice follows the customer
if (info.open_issues_html !== undefined) $('#qbo-open-issues').replaceWith(info.open_issues_html);
// Replace the email only if it was the previous customer's (or empty) // Replace the email only if it was the previous customer's (or empty)
if (!$email.val().trim() || $email.val() === loadedEmail) $email.val(info.email || ''); if (!$email.val().trim() || $email.val() === loadedEmail) $email.val(info.email || '');
loadedEmail = info.email || ''; loadedEmail = info.email || '';
@@ -0,0 +1,17 @@
<%# A new invoice's customer still has open issues (work orders), so they're not left behind once billed.
Replaced when the customer is changed (customer_info's open_issues_html). %>
<%
issues = customer ? customer.issues.open.visible.order(id: :desc).to_a : []
%>
<div id="qbo-open-issues">
<% if issues.any? %>
<div class="warning qbo-estimate-notice">
<%= l(:text_invoice_customer_open_issues, count: issues.size) %>
<ul>
<% issues.each do |issue| %>
<li><%= link_to_issue(issue, truncate: 60) %> (<%= issue.status %>)</li>
<% end %>
</ul>
</div>
<% end %>
</div>
+1
View File
@@ -1,4 +1,5 @@
<% html_title l(:label_new_invoice) %> <% html_title l(:label_new_invoice) %>
<%= render partial: 'qbo_estimates/header', locals: { form: @form } %> <%= render partial: 'qbo_estimates/header', locals: { form: @form } %>
<%= render partial: 'qbo_invoices/open_issues', locals: { customer: (Customer.find_by(id: @form.customer_id) if @form.customer_id.present?) } %>
<%= render partial: 'qbo_estimates/form', locals: { form: @form } %> <%= render partial: 'qbo_estimates/form', locals: { form: @form } %>
+3
View File
@@ -256,6 +256,9 @@ en:
notice_invoice_sent: "Invoice #%{number} emailed to %{email}" notice_invoice_sent: "Invoice #%{number} emailed to %{email}"
text_email_invoice_confirmation: "Email invoice #%{number} to %{email}?" text_email_invoice_confirmation: "Email invoice #%{number} to %{email}?"
text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved." text_invoice_from_estimate: "Made from estimate #%{number}. The estimate is closed when the invoice is saved."
text_invoice_customer_open_issues:
one: "This customer has an open issue. Make sure its work is finished and billed so it isn't left open:"
other: "This customer has %{count} open issues. Make sure their work is finished and billed so none are left open:"
text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed" text_line_bills_time: "Bills a QuickBooks time activity; saving marks the time as billed"
text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). Each time entry takes the place of the line with its issue's description (e.g. Install Lift Kit), then any others in order." text_replace_lines: "Tick the lines the time replaces (e.g. the estimate's labor lines). Each time entry takes the place of the line with its issue's description (e.g. Install Lift Kit), then any others in order."