New plugin: weekly technician bonus credit memos (SOP-OPS-012)

Totals the shop's billable hours for a Sunday-Saturday week (picked
projects, trackers and users) against the SOP-OPS-012 target, and
credits each qualifying technician's QuickBooks customer account with a
credit memo: a "Tech Bonus <week> <total>/<goal> hours (total/goal)"
line, plus a separate tier line for every full 15 hours over the goal.
Credit memos are emailed through QuickBooks.

- Bonus technicians (admin): user, QuickBooks customer, role
  (technician/foreman), probation end
- Tech bonuses (global "Run tech bonuses" permission): week preview,
  attendance check, run, PDF and email again; re-running a week never
  credits anyone twice

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-16 12:13:30 -05:00
commit a2ecb74c1d
37 files changed
+2274

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
#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 TechBonusesTest < Redmine::IntegrationTest
include QboBonusTestHelper
def setup
Customer.any_instance.stubs(:email).returns('tech@example.com')
RedmineQboBonus::Settings.stubs(:item).returns(Struct.new(:id, :name).new('31', 'Tech Bonus'))
RedmineQboBonus::CreditMemoWriter.stubs(:send_email).returns(true)
RedmineQboBonus::CreditMemoWriter.any_instance.stubs(:create).returns(saved_credit_memo)
create_technician(2)
log_time(2, 100)
log_time(3, 15.5)
end
def test_needs_the_permission
log_user('jsmith', 'jsmith')
get '/tech_bonuses'
assert_response :forbidden
Role.find(1).add_permission!(:run_tech_bonuses)
get '/tech_bonuses'
assert_response :success
assert_select '#top-menu a.tech-bonuses'
end
def test_week_preview
log_user('admin', 'admin')
get '/tech_bonuses', params: { week: '2026-11-10' }
assert_redirected_to '/tech_bonuses/2026-11-08'
get '/tech_bonuses/2026-11-08'
assert_response :success
assert_select 'h2', text: /2026-46/
assert_select '.tech-bonus-summary .value', text: '115.5'
assert_select 'input[name=?][value="2"]', 'attended[]'
assert_select 'td', text: '$100.00'
assert_select 'a[href^="/time_entries/report"]'
end
def test_run_week
log_user('admin', 'admin')
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
assert_redirected_to '/tech_bonuses/2026-11-08'
credit = TechBonusCredit.find_by(user_id: 2)
assert_equal 'emailed', credit.status
assert_equal '1042', credit.doc_number
follow_redirect!
assert_select 'a[href*="creditmemo?txnId=777"]', text: '#1042'
get '/tech_bonuses'
assert_select 'table.tech-bonus-weeks td', text: /115.5\/110/
end
def test_pdf
log_user('admin', 'admin')
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
credit = TechBonusCredit.find_by(user_id: 2)
RedmineQboBonus::CreditMemoWriter.expects(:pdf).with('777').returns('%PDF-1.4')
get "/tech_bonuses/credits/#{credit.id}/pdf"
assert_response :success
assert_equal 'application/pdf', response.media_type
end
def test_resend
log_user('admin', 'admin')
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
credit = TechBonusCredit.find_by(user_id: 2)
RedmineQboBonus::CreditMemoWriter.expects(:send_email).with('777', 'tech@example.com').returns(true)
post "/tech_bonuses/credits/#{credit.id}/resend"
assert_redirected_to '/tech_bonuses/2026-11-08'
end
def test_not_a_week
log_user('admin', 'admin')
get '/tech_bonuses/2026-02-31'
assert_response :not_found
end
end