Files
redmine_qbo_commission/test/test_helper.rb
T
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

64 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/test_helper', __dir__)
module QboCommissionTestHelper
# October 2026: over, so it can be approved
MONTH_START = Date.new(2026, 10, 1)
def self.included(base)
base.fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :issues, :trackers,
:projects_trackers, :issue_statuses, :enabled_modules, :enumerations
base.setup do
CommissionLine.delete_all
CommissionAdjustment.delete_all
CommissionPayout.delete_all
CommissionMonth.delete_all
CommissionRep.delete_all
Rails.cache.clear
end
end
def commission_month
RedmineQboCommission::Month.new(MONTH_START)
end
def sale(id, total, tax: 0, kind: 'invoice', date: MONTH_START + 10, customer: 'Jane Customer')
RedmineQboCommission::Txn.new(kind: kind, txn_id: id.to_s, doc_number: "10#{id}", customer_name: customer,
txn_date: date, total: BigDecimal(total.to_s), tax: BigDecimal(tax.to_s))
end
def refund(id, total, tax: 0, kind: 'refund_receipt')
sale(id, total, tax: tax, kind: kind)
end
# $120,000 of sales without tax, and a $1,000 refund: $119,000, a $595.00 commission
def october_txns
[sale(1, 64_200, tax: 4_200), sale(2, 60_000), refund(3, 1_000)]
end
def stub_qbo(txns = october_txns)
RedmineQboCommission::QboSource.stubs(:transactions).returns(txns)
end
def create_rep(user_id, **attributes)
CommissionRep.create!({ user_id: user_id }.merge(attributes))
end
def with_commission_settings(values)
saved = Setting.plugin_redmine_qbo_commission
Setting.plugin_redmine_qbo_commission = RedmineQboCommission::Settings::DEFAULTS.merge(values)
yield
ensure
Setting.plugin_redmine_qbo_commission = saved
end
end