Skip to content

tax

Tax services.

add_tax(*, to_value, at_rate) cached

Add tax to a value.

Parameters:

Name Type Description Default
to Decimal

Amount to add tax to.

required
at_rate Decimal

Rate (percentage) to add tax at. 20% should be written as Decimal("20")

required

Returns:

Name Type Description
Decimal Decimal

The amount with tax added.

Source code in src/pycountant/services/tax.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@cache
def add_tax(*, to_value: Decimal, at_rate: Decimal) -> Decimal:
    """
    Add tax to a value.

    Args:
        to (Decimal): Amount to add tax to.
        at_rate (Decimal): Rate (percentage) to add tax at.
                           20% should be written as Decimal("20")

    Returns:
        Decimal: The amount with tax added.
    """
    base_rate = Decimal("1.0")
    return to_value * (base_rate + (at_rate / Decimal("100")))

remove_tax(*, from_value, at_rate) cached

Remove tax from a value.

Parameters:

Name Type Description Default
to Decimal

Amount to remove tax from.

required
at_rate Decimal

Rate (percentage) to remove tax at. 20% should be written as Decimal("20")

required

Returns:

Name Type Description
Decimal Decimal

The amount with tax removed.

Source code in src/pycountant/services/tax.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@cache
def remove_tax(*, from_value: Decimal, at_rate: Decimal) -> Decimal:
    """
    Remove tax from a value.

    Args:
        to (Decimal): Amount to remove tax from.
        at_rate (Decimal): Rate (percentage) to remove tax at.
                           20% should be written as Decimal("20")

    Returns:
        Decimal: The amount with tax removed.
    """
    base_rate = Decimal("1.0")
    return from_value / (base_rate + (at_rate / Decimal(100)))