Functional Weave
Code in Python

finance.tax.add-vat

Add VAT to a net amount using the rate in force on the date of supply.

1.0.0 (not the latest) · published 2026-10-03 by charlie · Anterra

Pinned by 9 tests, run in TypeScript, Python and Rust.

Not professional advice. This capability calculates tax figures from published rules. It is a software component for developers, not tax advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed in its README, and have a chartered accountant or tax adviser review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.

What it does

Returns the whole breakdown, not just the tax. An invoice needs net, tax and gross together, and deriving the third from the other two in caller code is where rounding bugs are born.

The date is the date of supply. Defaulting it to today is the single most common way to get a credit note wrong.

For example

  • add_vat(£100.00, GB, STANDARD, 2026-09-16) → net £100.00, tax £20.00, gross £120.00, rate 20% 20 percent on 100 pounds
  • add_vat(£1.99, GB, STANDARD, 2026-09-16) → net £1.99, tax £0.40, gross £2.39, rate 20% rounds a fractional penny up
  • add_vat(£100.00, GB, ZERO, 2026-09-16) → net £100.00, tax £0.00, gross £100.00, rate 0% zero rated goods are taxable at nothing

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

def add_vat(net: Money, jurisdiction: str, category: str, on_date: str) -> VatBreakdown
netMoneythe amount before tax
jurisdictionstring
categorystring
on_datedatedate of supply, not today
returnsVatBreakdown

The type it declares, generated into your project

@dataclass(frozen=True)
class VatBreakdown:
    """Net, tax and gross together, so a caller never derives one from the other two."""

    net: Money
    tax: Money
    gross: Money
    basis_points: int

Your code names it in one line, in the file that uses it

from fune.finance.tax.add_vat import add_vat  # finance.tax.add-vat@^1
impl/python.py · 22 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .finance_tax_add_vat_types import VatBreakdown
from .finance_tax_vat_rate import vat_rate  ← from finance.tax.vat-rate ^1.0.0 · built alongside by fune
from .money_add import add_money  ← from money.add ^1.0.0 · built alongside by fune
from .money_amount import Money  ← from money.amount ^1.0.0 · built alongside by fune
from .money_apply_rate import apply_rate  ← from money.apply-rate ^1.0.0 · built alongside by fune


def add_vat(net: Money, jurisdiction: str, category: str, on_date: str) -> VatBreakdown:
    """Add VAT to a net amount at the rate in force on the date of supply.

    Returns the whole breakdown rather than just the tax: an invoice needs net,
    tax and gross together, and deriving the third from the other two in caller
    code is where rounding bugs are born.
    """
    rate = vat_rate(jurisdiction, category, on_date)
    tax = apply_rate(net, rate.basis_points, "half-up")
    return VatBreakdown(
        net=net,
        tax=tax,
        gross=add_money(net, tax),
        basis_points=rate.basis_points,
    )

Install

fune build

With that line in your source, in a Python project (language python in fune.project), fune build resolves it and its 4 dependencies, pins them in fune.lock, downloads only the Python package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add finance.tax.add-vat
Download for Python finance.tax.add-vat-1.0.0-python.fune · 6,189 bytes sha256 82200c7a4e89996afdc66d937f21dfc52ce6662c93bc7c1f356cb2aa4cf1cdf7

The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./finance.tax.add-vat-1.0.0-python.fune, or fetch it from a terminal with fune pull finance.tax.add-vat@1.0.0:python.

The whole function, every language, is one file too: finance.tax.add-vat-1.0.0.fune, 8,542 bytes, sha256 05f063a240ebc0fa25068224c4945615ecd6b9ddb72ceb1a68ac2af306ec8b3a. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

# fune: before finance.tax.add-vat

after — your function gets the result and the arguments, and returns the final result.

# fune: after finance.tax.add-vat

replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.

# fune: replace finance.tax.vat-rate in finance.tax.add-vat
# fune: replace money.add in finance.tax.add-vat
# fune: replace money.amount in finance.tax.add-vat
# fune: replace money.apply-rate in finance.tax.add-vat

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show finance.tax.add-vat --steps.

# fune: step finance.tax.add-vat after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

CaseArgumentsExpected
20 percent on 100 pounds £100.00, GB, STANDARD, 2026-09-16 → net £100.00, tax £20.00, gross £120.00, rate 20%
rounds a fractional penny up £1.99, GB, STANDARD, 2026-09-16 → net £1.99, tax £0.40, gross £2.39, rate 20%
zero rated goods are taxable at nothing £100.00, GB, ZERO, 2026-09-16 → net £100.00, tax £0.00, gross £100.00, rate 0%
reduced rate £100.00, GB, REDUCED, 2026-09-16 → net £100.00, tax £5.00, gross £105.00, rate 5%
a 2009 supply still uses the 2009 rate £100.00, GB, STANDARD, 2009-06-01 → net £100.00, tax £15.00, gross £115.00, rate 15%
hospitality during the covid cut £100.00, GB, HOSPITALITY, 2020-12-25 → net £100.00, tax £5.00, gross £105.00, rate 5%
Irish standard rate €100.00, IE, STANDARD, 2026-09-16 → net €100.00, tax €23.00, gross €123.00, rate 23%
a credit line carries negative tax -£100.00, GB, STANDARD, 2026-09-16 → net -£100.00, tax -£20.00, gross -£120.00, rate 20%
an unknown jurisdiction is an error £100.00, FR, STANDARD, 2026-09-16 → error: no VAT rule

Files

PathBytes
README.md320
impl/python.py827
impl/rust.rs1,370
impl/typescript.ts869
vectors.json2,561