Esempio n. 1
0
def calculate_tax(country, product_code, price, currency):
    price = Money(amount=price, currency=currency)
    tax = Money(amount='0', currency=currency)

    product = Catalogue.fetch(country, product_code)
    for rule in product.rules:
        tax_result = rule(price)
        if isinstance(tax_result, tuple):
            price = tax_result.next_amount
            tax += tax_result.tax
        else:
            tax += tax_result

    return product, tax
Esempio n. 2
0
def calculate_tax(country, product_code, price, currency):
    price = Money(amount=price, currency=currency)
    tax = Money(amount='0', currency=currency)

    product = Catalogue.fetch(country, product_code)
    for rule in product.rules:
        tax_result = rule(price)
        if isinstance(tax_result, tuple):
            price = tax_result.next_amount
            tax += tax_result.tax
        else:
            tax += tax_result

    return product, tax
Esempio n. 3
0
def test_catalogue():
    assert Catalogue.fetch(country_code='GBR',
                           product_code='BREAD') == ('Bread', [rules.VAT])
Esempio n. 4
0
def test_catalogue():
    assert Catalogue.fetch(country_code="GBR", product_code="BREAD") == ("Bread", [rules.VAT])