Files
rickyandClaude Opus 5.5 6fcd5f9b64 New plugin: monthly sales commission (SOP-OPS-013)
Reads the month's paid sales from QuickBooks Online (invoices paid in
full that month, sales receipts), deducts refund receipts, credit memos
and adjustments, works out the commission pool with the threshold and
marginal brackets, and records each sales rep's payout once the month
is approved for payroll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:53:25 -05:00

55 lines
2.7 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 PoolTest < ActiveSupport::TestCase
def pool(sales)
RedmineQboCommission::Pool.new(BigDecimal(sales.to_s))
end
# SOP-OPS-013 §3.3
def test_sop_examples
assert_equal BigDecimal('500'), pool(100_000).amount
assert_equal BigDecimal('600'), pool(120_000).amount
assert_equal BigDecimal('812.5'), pool(150_000).amount
assert_equal BigDecimal('1062.5'), pool(175_000).amount
end
def test_nothing_below_the_threshold
assert_equal BigDecimal('0'), pool('99999.99').amount
assert_not pool('99999.99').threshold_met?
assert_equal BigDecimal('0.01'), pool('99999.99').short_of_threshold
assert_equal [], pool(50_000).parts
assert_equal BigDecimal('100000'), pool(-500).short_of_threshold
end
def test_brackets
parts = pool(175_000).parts
assert_equal [[0, 125_000, BigDecimal('0.5')], [125_000, 150_000, BigDecimal('0.75')], [150_000, 175_000, BigDecimal('1')]],
parts.map { |part| [part.from, part.to, part.rate] }
assert_equal [BigDecimal('625'), BigDecimal('187.5'), BigDecimal('250')], parts.map(&:amount)
assert_equal 1, pool(125_000).parts.size
assert_equal BigDecimal('625'), pool(125_000).amount
end
def test_rounds_to_the_cent
assert_equal BigDecimal('500.01'), pool('100001.23').amount
end
def test_settings
saved = Setting.plugin_redmine_qbo_commission
Setting.plugin_redmine_qbo_commission = RedmineQboCommission::Settings::DEFAULTS.merge('threshold' => '50000', 'base_rate' => '1')
assert_equal BigDecimal('600'), pool(60_000).amount
ensure
Setting.plugin_redmine_qbo_commission = saved
end
end