Fix MT income tax applying preferential LTCG rates when net CG is negative#7862
Fix MT income tax applying preferential LTCG rates when net CG is negative#7862PavelMakarchuk wants to merge 3 commits intomainfrom
Conversation
…ative Two bugs fixed: 1. mt_regular_income_tax: only subtract LTCG from taxable income when net capital gains (STCG + LTCG) are positive. When STCG losses exceed LTCG, all income should be taxed at ordinary rates. 2. mt_capital_gains_tax_joint: convert from Person to TaxUnit entity to fix mismatch where LTCG and taxable income are on different persons in joint filing, causing both to get $0 CG tax. Closes #7859 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7862 +/- ##
============================================
+ Coverage 71.81% 100.00% +28.18%
============================================
Files 4084 6 -4078
Lines 58886 138 -58748
Branches 288 4 -284
============================================
- Hits 42288 138 -42150
+ Misses 16583 0 -16583
+ Partials 15 0 -15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Integration tests: - Positive net CG with STCG losses: confirms preferential rates still apply - LTCG on head, wages on spouse: confirms TaxUnit aggregation works cross-person - Both spouses with LTCG: confirms combined LTCG aggregation Unit tests: - Negative net CG: confirms $0 CG tax when STCG losses exceed LTCG - Positive net CG with STCG losses: confirms full LTCG gets preferential rates Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Review: Verified against MT Form 2 (2024) and MCA 15-30-2103 The core fix (no preferential LTCG rates when net CG <= 0) is correct per Form 2 Line 1: "If you do not have a net long-term capital gain, skip lines 2 through 10 and enter 0 (zero) on line 11." Two issues found: 1. "Lesser of line 15 or line 16" not fully implemented The Form 2 instructions (p. 11) say Line 2 should be:
The PR currently uses
Suggested fix: 2. Same bug in The Sources: |
Program Review: PR #7862 - Fix MT income tax applying preferential LTCG rates when net CG is negativeSource Documents
Bugs FixedBug 1: Missing net capital gain check
Bug 2: Person-level vs TaxUnit mismatch in CG tax
Critical (Must Fix)None identified. Should AddressNone identified. SuggestionsNone - this is a well-implemented bug fix. Files Changed
Test CoverageNew test scenarios added:
Validation Summary
Review Severity: APPROVEThis is a well-implemented bug fix with:
🤖 Generated with Claude Code |
Minor Code Quality SuggestionThe code validator found that an existing variable Optional improvement: Replace the inline calculation: ltcg = add(tax_unit, period, ["long_term_capital_gains"])
stcg = add(tax_unit, period, ["short_term_capital_gains"])
net_cg = ltcg + stcgWith: ltcg = add(tax_unit, period, ["long_term_capital_gains"])
net_cg = tax_unit("net_capital_gains", period)This applies to This is not blocking - just a maintainability improvement. The PR is approved as-is. |
Summary
Fixes two interacting bugs in Montana's income tax calculation that caused $0 tax when it should be ~$20,837.
Closes #7859
Bug 1: Missing net capital gain check
mt_regular_income_tax_joint.pysubtracted all positive LTCG from taxable income even when STCG losses exceeded LTCG. Per MT Form 2 and TaxAct, preferential LTCG rates should not apply when the overall net capital position is a loss.Fix: Only subtract LTCG from taxable income when
net_capital_gains(STCG + LTCG) > 0. Applied to both_jointand_indivvariants.Bug 2: Person-level vs tax-unit mismatch in CG tax
mt_capital_gains_tax_jointwas a Person-level variable, but for joint filers, LTCG and taxable income can be on different persons (taxable income is assigned to head viais_head *). Neither person had both LTCG and taxable income, so both got $0 CG tax.Fix: Convert
mt_capital_gains_tax_jointandmt_capital_gains_tax_applicable_threshold_jointfrom Person to TaxUnit entity, aggregating LTCG and taxable income across persons.Test case
From TaxAct (policyengine-taxsim#755):
Test plan
policyengine-core test policyengine_us/tests/policy/baseline/gov/states/mt/tax/income/integration.yaml policyengine_us/tests/policy/baseline/gov/states/mt/tax/income/capital_gains/ -c policyengine_us🤖 Generated with Claude Code