Exemplo n.º 1
0
    def test_cartitem_CartItemStateTaxContributor(self):
        from decimal import Decimal
        from chipchop.models import CartItemAbstract, ProductAbstract, VariantAbstract
        from chipchop.price.contributor import CartItemQuantityContributor, CartItemStateTaxContributor

        p = ProductAbstract()
        p.price = Decimal('10')

        v = VariantAbstract()
        v.product = p
        v.price_offset = Decimal('-1')

        tax_rate = '0.0685'

        with self.settings(CHIPCHOP_CARTITEM_PRICE_CONTRIBUTORS=(
                CartItemQuantityContributor(),
                CartItemStateTaxContributor(dict(US=dict(
                    UT=Decimal(tax_rate)))))):
            item = CartItemAbstract()
            item.variant = v
            item.quantity = 2

            class billing:
                country = 'US'
                state = 'UT'

            item.billing_address = billing()
            item.shipping_address = None

            item_price = item.price

            assert item_price.gross == Decimal('18')
            assert item_price.tax == Decimal('18') * Decimal(tax_rate)
            assert item_price.net == item_price.gross + item_price.tax
Exemplo n.º 2
0
    def test_priceoffset(self):
        from decimal import Decimal
        from chipchop.models import ProductAbstract, VariantAbstract

        p = ProductAbstract()
        p.price = Decimal('100')

        v = VariantAbstract()
        v.product = p
        v.price_offset = Decimal('-1')

        assert v.base_price == Decimal('99')

        v.price_offset = None

        assert v.base_price == Decimal('100')