Print label in the sidebar, filled in from the page

A Labels section in the sidebar of every page: Print label fills the
label in from the page's customer (their name), estimate, invoice,
appointment (its customer and estimate) or work order, or opens a blank
label anywhere else. When there's a customer, the PO number field offers
their latest estimates, invoices and open work orders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-16 11:51:53 -05:00
1 parent 3e29f14f76
commit 98a9bcc1bf
11 files changed
+239 -18

No files matched your search

+26
View File
@@ -83,10 +83,36 @@ class LabelJobsTest < Redmine::IntegrationTest
assert_select 'template#qbo-label-issue-link a.icon-qbo-label-print[data-remote=true]'
end
def test_sidebar_prints_for_the_work_order_on_its_page
log_user('jsmith', 'jsmith')
get '/issues/1'
assert_select '#sidebar .qbo-label-sidebar a.icon-qbo-label-print[href=?]', '/label_jobs/new?source_id=1&source_type=issue'
assert_select '#sidebar .qbo-label-sidebar', text: /Work order #1/
end
def test_sidebar_prints_a_blank_label_elsewhere
log_user('jsmith', 'jsmith')
get '/projects'
assert_select '#sidebar .qbo-label-sidebar a.icon-qbo-label-print[href=?]', '/label_jobs/new'
end
def test_blank_label_dialog_and_print
log_user('jsmith', 'jsmith')
get '/label_jobs/new', xhr: true
assert_response :success
assert_no_match(/qbo_label_po_numbers/, response.body)
post '/label_jobs', params: { source_type: '', source_id: '', lines: ['Parts', 'Bin 4'] }, xhr: true
job = LabelJob.last
assert_equal ['PARTS', 'BIN 4'], job.lines
assert_nil job.source_type
end
def test_no_link_without_an_active_printer
@printer.update!(active: false)
log_user('jsmith', 'jsmith')
get '/issues/1'
assert_select 'template#qbo-label-issue-link', 0
assert_select '.qbo-label-sidebar', 0
end
end
+12
View File
@@ -31,6 +31,18 @@ module QboLabelsTestHelper
LabelJob.create!({ label_printer: printer, user: user, lines: lines, status: status }.merge(attributes))
end
# A customer, without sending it to QuickBooks
def create_customer(id: 9001, name: 'Jane Smith')
customer = Customer.new(id: id, name: name)
customer.skip_qbo_push = true
customer.save!
customer
end
def create_estimate(customer, id: '8001', doc_number: '1234', txn_date: Date.new(2026, 11, 2))
Estimate.create!(id: id, doc_number: doc_number, txn_date: txn_date, customer: customer)
end
def with_label_settings(values)
saved = Setting.plugin_redmine_qbo_labels
Setting.plugin_redmine_qbo_labels = RedmineQboLabels::Settings::DEFAULTS.merge(values)
+43
View File
@@ -62,6 +62,49 @@ class LabelSourceTest < ActiveSupport::TestCase
User.current = nil
end
def test_a_blank_label
source = RedmineQboLabels::LabelSource.find('', nil)
assert source.blank?
assert_equal ['', ''], source.lines
assert_nil source.title
assert_empty source.po_suggestions
end
def test_a_customer_fills_in_the_name_and_suggests_po_numbers
customer = create_customer
create_estimate(customer, id: '8001', doc_number: '1234', txn_date: Date.new(2026, 11, 2))
create_estimate(customer, id: '8002', doc_number: '1240', txn_date: Date.new(2026, 11, 9))
Issue.find(1).update_column(:customer_id, customer.id)
User.current = User.find(1) # admin
source = RedmineQboLabels::LabelSource.find('customer', customer.id)
assert_equal ['Smith', ''], source.lines
numbers = source.po_suggestions.map(&:first)
assert_equal %w[E1240 E1234 W1], numbers
ensure
User.current = nil
end
def test_estimates_from_the_record
customer = create_customer
estimate = create_estimate(customer)
User.current = User.find(1)
source = RedmineQboLabels::LabelSource.find('estimate', estimate.id)
assert_equal %w[Smith E1234], source.lines
assert_equal 'Estimate #1234', source.title
assert_includes source.po_suggestions.map(&:first), 'E1234'
ensure
User.current = nil
end
def test_customers_need_view_customers
customer = create_customer
User.current = User.find(7)
assert_nil RedmineQboLabels::LabelSource.find('customer', customer.id)
ensure
User.current = nil
end
def test_estimates_and_invoices_need_redmine_qbos_permissions
User.current = User.find(7) # no global permissions
assert_nil RedmineQboLabels::LabelSource.find('estimate', 1)