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>
58 lines
2.8 KiB
Ruby
58 lines
2.8 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_helper', __dir__)
|
|
|
|
class CreditMemoWriterTest < ActiveSupport::TestCase
|
|
include QboBonusTestHelper
|
|
|
|
FakeItem = Struct.new(:id, :name)
|
|
|
|
def setup
|
|
RedmineQboBonus::Settings.stubs(:item).returns(FakeItem.new('31', 'Tech Bonus'))
|
|
end
|
|
|
|
def build(hours)
|
|
tech = create_technician(2)
|
|
log_time(2, hours)
|
|
report = RedmineQboBonus::WeekReport.new(bonus_week)
|
|
RedmineQboBonus::CreditMemoWriter.new(report).build(report.lines.first, customer: tech.customer,
|
|
email: 'tech@example.com')
|
|
end
|
|
|
|
def test_one_line_at_the_goal
|
|
memo = build(115.5)
|
|
assert_equal 1, memo.line_items.size
|
|
line = memo.line_items.first
|
|
assert_equal 'Tech Bonus 2026-46 115.5/110 hours (total/goal)', line.description
|
|
assert_equal BigDecimal('100'), line.amount
|
|
assert_equal '31', line.sales_item_line_detail.item_ref.value
|
|
assert_equal 'NON', line.sales_item_line_detail.tax_code_ref.value
|
|
assert_equal '9002', memo.customer_ref.value
|
|
assert_equal 'tech@example.com', memo.bill_email.address
|
|
end
|
|
|
|
def test_tiers_on_their_own_line
|
|
memo = build(141)
|
|
assert_equal 2, memo.line_items.size
|
|
tier = memo.line_items.last
|
|
assert_equal 'Tier Bonus 2026-46 2 x 15 hours over goal', tier.description
|
|
assert_equal BigDecimal('2'), tier.sales_item_line_detail.quantity
|
|
assert_equal BigDecimal('100'), tier.sales_item_line_detail.unit_price
|
|
assert_equal BigDecimal('200'), tier.amount
|
|
assert_includes memo.to_xml.to_s, 'Tier Bonus'
|
|
end
|
|
|
|
def test_needs_a_product_or_service
|
|
RedmineQboBonus::Settings.stubs(:item).returns(nil)
|
|
assert_raises(RedmineQboBonus::CreditMemoWriter::Error) { build(120) }
|
|
end
|
|
end
|