Пример #1
0
def test_application():
    result = flat_tax(TaxedMoney(Money(10, 'BTC'), Money(10, 'BTC')), 1)
    assert result.net == Money(10, 'BTC')
    assert result.gross == Money(20, 'BTC')
    result = flat_tax(Money(100, 'BTC'), Decimal('0.5'))
    assert result.net == Money(100, 'BTC')
    assert result.gross == Money(150, 'BTC')
    with pytest.raises(TypeError):
        flat_tax(1, 1)
Пример #2
0
def test_tax_from_gross():
    result = flat_tax(
        TaxedMoney(Money(120, 'USD'), Money(120, 'USD')),
        Decimal('0.2'), keep_gross=True)
    assert result.net == Money(100, 'USD')
    assert result.gross == Money(120, 'USD')
    result = flat_tax(Money(150, 'BTC'), Decimal('0.5'), keep_gross=True)
    assert result.net == Money(100, 'BTC')
    assert result.gross == Money(150, 'BTC')
Пример #3
0
def test_range():
    price_range = MoneyRange(Money(10, 'BTC'), Money(20, 'BTC'))
    result = flat_tax(price_range, 1)
    assert result.start == TaxedMoney(Money(10, 'BTC'), Money(20, 'BTC'))
    assert result.stop == TaxedMoney(Money(20, 'BTC'), Money(40, 'BTC'))
    price_range = TaxedMoneyRange(
        TaxedMoney(Money(10, 'BTC'), Money(10, 'BTC')),
        TaxedMoney(Money(20, 'BTC'), Money(20, 'BTC')))
    result = flat_tax(price_range, 1)
    assert result.start == TaxedMoney(Money(10, 'BTC'), Money(20, 'BTC'))
    assert result.stop == TaxedMoney(Money(20, 'BTC'), Money(40, 'BTC'))
Пример #4
0
def compute_price(net=0, gross=0, tax=0, currency='EUR', keep_gross=True):
    """Compute net, gross and tax amount

    The computation can be net or gross based (gross as default)

    :param net: Net price (untaxed)
    :type net: int, float, decimal
    :param gross: Gross price (including taxes)
    :type gross: int, float, decimal
    :param tax: Tax percentage (a value between 0 and 1)
    :type tax: int, float, decimal
    :param currency: Currency (3 character code)
    :type currency: string
    :param keep_gross: A boolean to force computation gross price.
        Default value is True
    :type keep_gross: Boolean
    :return: TaxedMoney from `prices` python package
    :rtype: TaxedMoney

    Example:

    # compute net from gross
    >>> price = compute_price(gross=100, tax=0.2, currency='EUR')
    >>> price
    >>> TaxedMoney(net=Money('83.33', 'EUR'), gross=Money('100.00', 'EUR'))
    >>> price.tax
    >>> Money('16.67', 'EUR')
    # compute gross from net
    >>> price = compute_price(net=83.33, tax=0.2, keep_gross=False)
    >>> price
    >>> TaxedMoney(net=Money('83.33', 'EUR'), gross=Money('100.00', 'EUR'))
    >>> price.tax
    >>> Money('16.67', 'EUR')
    """
    if net != gross:
        if keep_gross:
            net = gross
        else:
            gross = net
    tax = compute_tax(tax)
    return flat_tax(TaxedMoney(
        Money(D(net), currency).quantize(),
        Money(D(gross), currency).quantize()),
                    tax,
                    keep_gross=keep_gross)
Пример #5
0
 def tax(base, keep_gross=False):
     return flat_tax(base, final_tax_rate, keep_gross=keep_gross)