Files
rickyandClaude Opus 5.5 a2ecb74c1d 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>
2026-11-16 12:13:30 -05:00

71 lines
3.1 KiB
Ruby

#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/test_helper', __dir__)
module QboBonusTestHelper
# Sunday 2026-11-08 to Saturday 2026-11-14 (2026-46)
WEEK_START = Date.new(2026, 11, 8)
def self.included(base)
base.fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :issues, :trackers,
:projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :enabled_modules
base.setup do
TechBonusCredit.delete_all
TechBonusWeek.delete_all
BonusTechnician.delete_all
TimeEntry.delete_all
Customer.where(id: 9000..9999).delete_all
end
end
def bonus_week
RedmineQboBonus::Week.new(WEEK_START)
end
# Time logged without Redmine's checks (membership, permissions)
def log_time(user_id, hours, spent_on: WEEK_START + 1, issue_id: 1, project_id: nil)
issue = issue_id && Issue.find(issue_id)
entry = TimeEntry.new(user_id: user_id, author_id: user_id, hours: hours, spent_on: spent_on, issue: issue,
project_id: project_id || issue&.project_id, activity_id: 9)
entry.save!(validate: false)
entry
end
# A customer, without sending it to QuickBooks
def create_customer(id: 9001, name: 'Jane Tech')
customer = Customer.new(id: id, name: name)
customer.skip_qbo_push = true
customer.save!
customer
end
def create_technician(user_id, role: 'technician', customer: nil, **attributes)
customer ||= create_customer(id: 9000 + user_id, name: "Tech #{user_id}")
BonusTechnician.create!({ user_id: user_id, role: role, customer_id: customer.id }.merge(attributes))
end
def with_bonus_settings(values)
saved = Setting.plugin_redmine_qbo_bonus
Setting.plugin_redmine_qbo_bonus = RedmineQboBonus::Settings::DEFAULTS.merge(values)
yield
ensure
Setting.plugin_redmine_qbo_bonus = saved
end
# A credit memo as QuickBooks returns it
def saved_credit_memo(id: '777', doc_number: '1042')
memo = Quickbooks::Model::CreditMemo.new
memo.id = id
memo.doc_number = doc_number
memo
end
end