Skip to content

Add UK Gift Aid support with PolicyEngine-UK#66

Merged
MaxGhenis merged 9 commits into
mainfrom
uk-support
Dec 2, 2025
Merged

Add UK Gift Aid support with PolicyEngine-UK#66
MaxGhenis merged 9 commits into
mainfrom
uk-support

Conversation

@MaxGhenis
Copy link
Copy Markdown
Contributor

@MaxGhenis MaxGhenis commented Dec 2, 2025

Summary

This PR adds UK tax calculation support to GiveCalc, enabling UK users to calculate the tax impact of charitable donations via Gift Aid.

Dependencies

Blocked by: PolicyEngine/policyengine-uk#1430 - Fix Gift Aid Personal Allowance taper interaction

This PR depends on the policyengine-uk fix for Gift Aid PA taper calculation. Once that PR is merged and released, the policyengine-uk version constraint here can be updated.

Changes

New UK Module (givecalc/uk/)

  • constants.py: UK-specific constants (tax year, regions)
  • situation.py: Creates PolicyEngine-UK situations with donation axes
  • tax.py: UK tax calculations (marginal savings, donation effects)

API Endpoints (api/main.py)

  • GET /api/uk/regions: List UK regions grouped by nation
  • GET /api/uk/tax-programs: Gift Aid program information
  • POST /api/uk/calculate: Calculate UK tax impact of Gift Aid donations

Schemas (api/schemas.py)

  • UKIncomeInput, UKCalculateRequest, UKCalculateResponse
  • UKRegionInfo, UKRegionsResponse
  • UKDonationDataPoint, UKTaxProgramsResponse

Dependencies

  • Added policyengine-uk>=2.45.0,<2.55.0 (Python 3.12 compatible)
  • Includes workaround for policyengine-uk dataset attribute bug (fixed in 2.55.0+ which requires Python 3.13+)

UK Tax System Details

Gift Aid provides tax relief in two ways:

  1. Charity reclaim: Charities reclaim 25p per £1 donated (basic rate relief at 20%)
  2. Donor relief: Higher rate (40%+) taxpayers claim additional relief personally

Example for a £100 donation by a 40% taxpayer:

  • Charity receives: £100 + £25 (basic rate reclaim) = £125
  • Donor claims: £25 (difference between 40% and 20% on £125 gross)
  • Net cost to donor: £75

Supports all UK regions including Scotland (with different income tax rates).

Testing

47 new tests covering:

  • UK situation creation (18 tests)
  • UK tax calculations (14 tests)
  • UK API endpoints (13 tests)

All 80 tests pass (existing + new).

Related Issues

Closes #58 (parent issue)

This PR adds UK tax calculation support to GiveCalc, enabling UK users to
calculate the tax impact of charitable donations via Gift Aid.

## Changes

### New UK Module (`givecalc/uk/`)
- `constants.py`: UK-specific constants (tax year, regions)
- `situation.py`: Creates PolicyEngine-UK situations with donation axes
- `tax.py`: UK tax calculations (marginal savings, donation effects)

### API Endpoints (`api/main.py`)
- `GET /api/uk/regions`: List UK regions grouped by nation
- `GET /api/uk/tax-programs`: Gift Aid program information
- `POST /api/uk/calculate`: Calculate UK tax impact of Gift Aid donations

### Schemas (`api/schemas.py`)
- `UKIncomeInput`, `UKCalculateRequest`, `UKCalculateResponse`
- `UKRegionInfo`, `UKRegionsResponse`
- `UKDonationDataPoint`, `UKTaxProgramsResponse`

### Dependencies
- Added `policyengine-uk>=2.45.0,<2.55.0` (Python 3.12 compatible)
- Includes workaround for policyengine-uk dataset attribute bug

## UK Tax System Details

Gift Aid provides tax relief in two ways:
1. Charities reclaim 25p per £1 donated (basic rate relief at 20%)
2. Higher rate (40%+) taxpayers claim additional relief personally

Supports all UK regions including Scotland (with different tax rates).

## Testing

47 new tests covering:
- UK situation creation (18 tests)
- UK tax calculations (14 tests)
- UK API endpoints (13 tests)

All 80 tests pass (existing + new).

Closes #58
Related: #60, #61, #62, #63

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 2, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
givecalc Ready Ready Preview Comment Dec 2, 2025 4:42pm

- Update requires-python to >=3.13,<3.14
- Update policyengine-uk to >=2.55.0 (now 2.62.1)
- Remove workaround for dataset attribute bug (fixed in 2.55.0+)
- Update black target-version to py313 only

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Drop Python 3.11 and 3.12 support in CI to match pyproject.toml requirement.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Required by FastAPI TestClient (starlette.testclient).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The uv run command creates a fresh virtual environment which doesn't
see packages installed via uv pip install --system. Using pytest
directly uses the system Python where dev dependencies were installed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add country selector toggle (US/UK) with flag icons
- Create UKInputForm component with:
  - Region selector (grouped by nation)
  - Employment/self-employment income inputs
  - Gift Aid donation amount with gross-up display
  - Scottish tax rate indicator
- Add UK types, API functions, and React Query hooks
- Update Results component to support GBP currency formatting
- Update formatCurrency utility to handle USD/GBP

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This version includes the Gift Aid Personal Allowance taper fix
(PolicyEngine/policyengine-uk#1430) required for accurate UK tax calculations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Merged latest changes from main including:
- STATES constant for instant load
- Tax programs data module
- Vercel config moved to frontend

Resolved conflicts in:
- useCalculation.ts: Combined UK hooks with STATES/taxPrograms imports
- pyproject.toml: Added policyengine-uk>=2.63.0 with plotly
- uv.lock: Regenerated with all dependencies

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor Author

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Vercel Deployment Setup

I noticed the Vercel deployment is running on this PR. There was a recent issue where Vercel needs the Root Directory set to frontend in the Vercel dashboard (not in vercel.json) to avoid hitting the 250MB serverless function limit.

What happened with the Vercel setup:

  1. The vercel.json file was moved from repo root to frontend/vercel.json (PR #69)
  2. The Root Directory must be set to frontend in the Vercel dashboard settings (Project Settings → Root Directory)

To fix Vercel deployments for this branch:

  1. First, check if the vercel.json exists at frontend/vercel.json - if not, you need to add it:
{
  "buildCommand": "npm install && npm run build",
  "outputDirectory": "dist",
  "framework": "vite",
  "installCommand": "npm install"
}
  1. Make sure there's NO vercel.json in the repository root - Vercel should only look at the frontend folder

  2. The Vercel dashboard should have Root Directory = frontend

What likely went wrong:

If there's still a vercel.json at the root OR if the dashboard Root Directory isn't set, Vercel will try to deploy the entire repo including the Python api/ folder, which exceeds the 250MB limit.

Check your branch to ensure vercel.json is ONLY in frontend/ and not at the repo root.

Copy link
Copy Markdown
Contributor Author

@MaxGhenis MaxGhenis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I checked your branch - the vercel.json setup looks correct:

  • ✅ No vercel.json at repo root
  • frontend/vercel.json exists with correct config

The Vercel deployment should work as long as the Vercel dashboard has Root Directory set to frontend. If it wasn't set before, you may need to wait for Vercel to re-deploy or trigger a new deployment after confirming the dashboard setting.

Everything else in the PR looks good - comprehensive UK Gift Aid support with 47 new tests!

@MaxGhenis MaxGhenis merged commit 8ecd042 into main Dec 2, 2025
3 checks passed
@MaxGhenis MaxGhenis deleted the uk-support branch December 2, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add UK tax support to GiveCalc

1 participant