Esempio n. 1
0
def test_taxed_base_unit_prices():
    assert_almost_equal(line.taxless_base_unit_price,
                        TaxlessPrice(5, 'EUR') / Decimal('1.1'))
    assert line.taxful_base_unit_price == TaxfulPrice(5, 'EUR')
Esempio n. 2
0
def test_discounted_unit_price():
    assert line.discounted_unit_price == TaxfulPrice(33, 'EUR') / 9
Esempio n. 3
0
def test_unit_discount_amount():
    assert line.unit_discount_amount == TaxfulPrice(12, 'EUR') / 9
Esempio n. 4
0
def test_tax_special_cases3():
    taxless_line = Line(base_unit_price=TaxfulPrice(0, 'EUR'),
                        quantity=0,
                        discount_amount=TaxfulPrice(0, 'EUR'),
                        tax_amount=Money(0, 'EUR'))
    assert taxless_line.taxful_price == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxless_price == TaxlessPrice(0, 'EUR')

    assert taxless_line.base_unit_price == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxful_base_unit_price == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxless_base_unit_price == TaxlessPrice(0, 'EUR')

    assert taxless_line.discount_amount == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxful_discount_amount == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxless_discount_amount == TaxlessPrice(0, 'EUR')

    assert taxless_line.price == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxful_price == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxless_price == TaxlessPrice(0, 'EUR')

    assert taxless_line.base_price == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxful_base_price == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxless_base_price == TaxlessPrice(0, 'EUR')

    assert taxless_line.unit_discount_amount == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxful_unit_discount_amount == TaxfulPrice(0, 'EUR')
    assert taxless_line.taxless_unit_discount_amount == TaxlessPrice(0, 'EUR')

    assert taxless_line.discount_rate == 0
    assert taxless_line.tax_rate == 0
Esempio n. 5
0
def test_price():
    assert line.price == TaxfulPrice(33, 'EUR')  # 5 * 9 - 12
Esempio n. 6
0
def tfprice(value):
    return TaxfulPrice(value, 'USD')
Esempio n. 7
0

class Line(Priceful):
    base_unit_price = None
    quantity = None
    discount_amount = None
    tax_amount = None

    def __init__(self, base_unit_price, quantity, discount_amount, tax_amount):
        self.base_unit_price = base_unit_price
        self.quantity = quantity
        self.discount_amount = discount_amount
        self.tax_amount = tax_amount


line = Line(base_unit_price=TaxfulPrice(5, 'EUR'),
            quantity=9,
            discount_amount=TaxfulPrice(12, 'EUR'),
            tax_amount=Money(3, 'EUR'))
line2 = Line(base_unit_price=TaxfulPrice(10, 'EUR'),
             quantity=123,
             discount_amount=TaxfulPrice(0, 'EUR'),
             tax_amount=Money(123, 'EUR'))


def test_price():
    assert line.price == TaxfulPrice(33, 'EUR')  # 5 * 9 - 12


def test_discounted_unit_price():
    assert line.discounted_unit_price == TaxfulPrice(33, 'EUR') / 9
def test_price_property_get():
    m = get_market()
    assert m.price == TaxfulPrice(123, 'GBP')
def test_price_property_set_invalid_unit():
    m = get_market()
    with pytest.raises(UnitMixupError):
        m.price = TaxlessPrice(3, 'GBP')
    with pytest.raises(UnitMixupError):
        m.price = TaxfulPrice(3, 'USD')
Esempio n. 10
0
def test_money_propped_type_checking_currency():
    foo = Foo(currency='EUR', includes_tax=True)
    with pytest.raises(TypeError):
        FooItem(foo=foo, price=TaxfulPrice(42, 'USD'))
Esempio n. 11
0
def test_money_propped_basic():
    foo = Foo(currency='EUR', includes_tax=True)
    item = FooItem(foo=foo, price=TaxfulPrice(42, 'EUR'))
    assert item.price == TaxfulPrice(42, 'EUR')
    assert item.value == 42
    assert item.foo.currency == 'EUR'
Esempio n. 12
0
def test_new():
    assert TaxfulPrice(currency='EUR').new(42) == TaxfulPrice(42, 'EUR')
    assert TaxlessPrice(currency='EUR').new(-10) == TaxlessPrice(-10, 'EUR')
    assert TaxfulPrice(10, 'GBP').new(5) == TaxfulPrice(5, 'GBP')
Esempio n. 13
0
def test_tax_mixup():
    with pytest.raises(TypeError):
        TaxfulPrice(42, 'EUR') - TaxlessPrice(2, 'EUR')
Esempio n. 14
0
 def get_effective_price(self, source, **kwargs):
     if source.shipping_address and source.shipping_address.country == "SE":
         return TaxfulPrice("5.00")
     return TaxfulPrice("4.00")