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:
commit
a2ecb74c1d
37 files changed
+2274
No files matched your search
@@ -0,0 +1,127 @@
|
||||
#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 WeekReportTest < ActiveSupport::TestCase
|
||||
include QboBonusTestHelper
|
||||
|
||||
def report
|
||||
RedmineQboBonus::WeekReport.new(bonus_week)
|
||||
end
|
||||
|
||||
def test_everyones_hours_count_toward_the_shop_total
|
||||
create_technician(2)
|
||||
log_time(2, 60)
|
||||
log_time(3, 40.5) # not a technician (e.g. front desk)
|
||||
log_time(2, 8, spent_on: WEEK_START - 1) # Saturday before
|
||||
log_time(2, 8, spent_on: WEEK_START + 7) # Sunday after
|
||||
|
||||
assert_equal({ 2 => BigDecimal('60'), 3 => BigDecimal('40.5') }, report.hours_by_user)
|
||||
assert_equal BigDecimal('100.5'), report.total_hours
|
||||
assert_not report.goal_met?
|
||||
assert_equal 0, report.tiers
|
||||
end
|
||||
|
||||
def test_sunday_and_saturday_count
|
||||
log_time(2, 5, spent_on: WEEK_START)
|
||||
log_time(2, 5, spent_on: WEEK_START + 6)
|
||||
assert_equal BigDecimal('10'), report.total_hours
|
||||
end
|
||||
|
||||
def test_a_tier_for_every_full_15_hours_over_the_goal
|
||||
{ '110' => 0, '124.99' => 0, '125' => 1, '139.75' => 1, '140' => 2 }.each do |hours, tiers|
|
||||
TimeEntry.delete_all
|
||||
log_time(2, BigDecimal(hours))
|
||||
assert_equal tiers, report.tiers, "#{hours} hours"
|
||||
assert report.goal_met?
|
||||
end
|
||||
end
|
||||
|
||||
def test_projects_and_subprojects
|
||||
log_time(2, 10, issue_id: 1) # eCookbook
|
||||
log_time(2, 20, issue_id: 5) # eCookbook's subproject
|
||||
log_time(2, 40, issue_id: 4) # OnlineStore
|
||||
with_bonus_settings('project_ids' => ['1'], 'include_subprojects' => '1') do
|
||||
assert_equal BigDecimal('30'), report.total_hours
|
||||
end
|
||||
with_bonus_settings('project_ids' => ['1'], 'include_subprojects' => '0') do
|
||||
assert_equal BigDecimal('10'), report.total_hours
|
||||
end
|
||||
end
|
||||
|
||||
def test_excluded_trackers
|
||||
Issue.find(2).update_columns(tracker_id: 3)
|
||||
log_time(2, 10, issue_id: 1)
|
||||
log_time(2, 20, issue_id: 2)
|
||||
log_time(2, 5, issue_id: nil, project_id: 1)
|
||||
with_bonus_settings('tracker_mode' => 'exclude', 'tracker_ids' => ['3']) do
|
||||
assert_equal BigDecimal('15'), report.total_hours
|
||||
end
|
||||
with_bonus_settings('tracker_mode' => 'include', 'tracker_ids' => ['3']) do
|
||||
assert_equal BigDecimal('20'), report.total_hours
|
||||
end
|
||||
end
|
||||
|
||||
def test_picked_users_and_the_technicians
|
||||
create_technician(2)
|
||||
log_time(2, 10)
|
||||
log_time(3, 20)
|
||||
log_time(1, 40)
|
||||
with_bonus_settings('user_ids' => ['3']) do
|
||||
assert_equal [2, 3], report.hours_by_user.keys.sort
|
||||
end
|
||||
end
|
||||
|
||||
def test_what_each_technician_earns
|
||||
create_technician(2)
|
||||
create_technician(3, role: 'foreman')
|
||||
log_time(2, 70)
|
||||
log_time(3, 72) # 142 hours: 2 tiers
|
||||
lines = report.lines.index_by { |line| line.technician.user_id }
|
||||
|
||||
assert_equal BigDecimal('100'), lines[2].base_amount
|
||||
assert_equal BigDecimal('200'), lines[2].tier_amount
|
||||
assert_equal BigDecimal('150'), lines[3].base_amount
|
||||
assert_equal BigDecimal('300'), lines[3].tier_amount
|
||||
assert_equal BigDecimal('450'), lines[3].amount
|
||||
end
|
||||
|
||||
def test_nothing_below_the_goal
|
||||
create_technician(2)
|
||||
log_time(2, 109.75)
|
||||
assert_equal BigDecimal('0'), report.lines.first.amount
|
||||
assert_equal BigDecimal('0.25'), report.hours_to_next_tier
|
||||
end
|
||||
|
||||
def test_probation_and_missing_customer_are_ineligible
|
||||
create_technician(2, probation_until: WEEK_START)
|
||||
tech = create_technician(3)
|
||||
tech.update_columns(customer_id: nil)
|
||||
log_time(2, 130)
|
||||
lines = report.lines.index_by { |line| line.technician.user_id }
|
||||
|
||||
assert_match(/probation/i, lines[2].ineligible_reason)
|
||||
assert_equal BigDecimal('0'), lines[2].amount
|
||||
assert_match(/customer/i, lines[3].ineligible_reason)
|
||||
|
||||
BonusTechnician.find_by(user_id: 2).update!(probation_until: WEEK_START - 1)
|
||||
assert RedmineQboBonus::WeekReport.new(bonus_week).lines.find { |l| l.technician.user_id == 2 }.eligible?
|
||||
end
|
||||
|
||||
def test_redmine_report_params
|
||||
with_bonus_settings('project_ids' => ['2'], 'tracker_ids' => %w[3 18]) do
|
||||
params = report.redmine_report_params
|
||||
assert_equal %w[spent_on project_id issue.tracker_id], params[:f]
|
||||
assert_equal '!', params[:op]['issue.tracker_id']
|
||||
assert_equal %w[2026-11-08 2026-11-14], params[:v]['spent_on']
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user