Ejemplo n.º 1
0
    def test_18_amount_discount_incl_tax(self):
        """Test discount amounts specified with tax included"""
        p1 = self.create_product()
        p2 = self.create_product()

        price = p1.get_price(currency='ASDF')
        price.tax_class = self.tax_class_germany
        price.save()

        order = self.create_order()
        order.currency = 'ASDF'
        order.save()

        normal1 = order.modify_item(p1, 3)
        normal2 = order.modify_item(p2, 5)

        order.recalculate_total()
        #self.assertAlmostEqual(order.total, Decimal('598.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal('598.85'))

        discount = Discount.objects.create(
            type=Discount.AMOUNT_INCL_TAX,
            code='asdf',
            name='Amount discount',
            value=Decimal('50.00'),
            is_active=True)
        order.add_discount(discount)
        order.recalculate_total()

        # Exact values after usage of different tax rates in same order
        #self.assertAlmostEqual(order.total, Decimal('548.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal('548.85'))
        self.assertAlmostEqual(order.discount, Decimal('50.00'))
Ejemplo n.º 2
0
    def test_27_discounts(self):
        """Discount testing reloaded"""
        tax_class, tax_class_germany, tax_class_something = self.create_tax_classes()

        product = Product.objects.create(
            name='Ein Paar Hosen',
            slug='prodeinpaarhosen1',
            )

        product.create_variations()
        product.prices.create(
            currency='CHF',
            tax_class=tax_class,
            _unit_price=Decimal('100.00'),
            tax_included=True,
            )

        price = product.get_price(currency='CHF')
        price.tax_class = tax_class
        price.save()

        order = self.create_order()
        order.save()

        normal1 = order.modify_item(product.variations.get(), 1)

        order.recalculate_total()
        self.assertAlmostEqual(order.total, Decimal('100'))

        discount = Discount.objects.create(
            type=Discount.PREPAID,
            code='asdf',
            name='Amount discount',
            value=Decimal('20.00'),
            is_active=True,
            tax_class=tax_class,
            currency='CHF',
            )
        discount.add_to(order)
        order.recalculate_total()

        # Pre-paid discount -- tax still applies to undiscounted value
        self.assertAlmostEqual(order.total, Decimal('80.00'))
        self.assertAlmostEqual(order.subtotal, Decimal('100.00') / Decimal('1.076') - Decimal('20.00'))

        # Change something on the discount
        discount.before_tax = True # TODO implement this
        discount.add_to(order)
        order.recalculate_total()

        # Voucher from a magazine or something -- tax only applies to
        # discounted value
        self.assertAlmostEqual(order.total, Decimal('80.00'))
        self.assertAlmostEqual(order.subtotal, Decimal('80.00') / Decimal('1.076'))
Ejemplo n.º 3
0
    def test_02_eur_order(self):
        """Test basic order in EUR works as expected"""
        product = self.create_product()
        order = self.create_order()

        order.currency = 'EUR'
        order.save()

        item = order.modify_item(product.variations.get(), 2)

        self.assertEqual(item.unit_price, Decimal('49.90'))
        self.assertEqual(item.currency, order.currency)
Ejemplo n.º 4
0
    def test_02_eur_order(self):
        """Test basic order in EUR works as expected"""
        product = self.create_product()
        order = self.create_order()

        order.currency = "EUR"
        order.save()

        item = order.modify_item(product, 2)

        self.assertEqual(item.unit_price, Decimal("49.90"))
        self.assertEqual(item.currency, order.currency)
Ejemplo n.º 5
0
    def test_02_eur_order(self):
        """Test basic order in EUR works as expected"""
        product = self.create_product()
        order = self.create_order()

        order.currency = "EUR"
        order.save()

        item = order.modify_item(product, 2)

        self.assertEqual(item.unit_price, Decimal("49.90"))
        self.assertEqual(item.currency, order.currency)
Ejemplo n.º 6
0
    def test_26_amount_coupon_incl_tax(self):
        """Test coupons"""
        tax_class, tax_class_germany, tax_class_something = self.create_tax_classes()

        product = Product.objects.create(
            name='Ein Paar Hosen',
            slug='prodeinpaarhosen1',
            )

        product.create_variations()
        product.prices.create(
            currency='CHF',
            tax_class=tax_class,
            _unit_price=Decimal('100.00'),
            tax_included=True,
            )

        price = product.get_price(currency='CHF')
        price.tax_class = tax_class
        price.save()

        order = self.create_order()
        order.save()

        normal1 = order.modify_item(product.variations.get(), 1)

        order.recalculate_total()
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal('100'))

        discount = Discount.objects.create(
            type=Discount.PREPAID,
            code='asdf',
            name='Amount discount',
            value=Decimal('20.00'),
            is_active=True,
            tax_class=tax_class,
            currency='CHF',
            )
        discount.add_to(order)
        order.recalculate_total()

        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal('87.6'))
Ejemplo n.º 7
0
    def test_18_amount_discount_incl_tax(self):
        """Test discount amounts specified with tax included"""
        p1 = self.create_product()
        p2 = self.create_product()

        price = p1.get_price(currency='CAD')
        price.tax_class = self.tax_class_germany
        price.save()

        order = self.create_order()
        order.currency = 'CAD'
        order.save()

        normal1 = order.modify_item(p1.variations.get(), 3)
        normal2 = order.modify_item(p2.variations.get(), 5)

        order.recalculate_total()
        #self.assertAlmostEqual(order.total, Decimal('598.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal('598.85'))

        discount = Discount.objects.create(
            type=Discount.AMOUNT_INCL_TAX,
            code='asdf',
            name='Amount discount',
            value=Decimal('50.00'),
            is_active=True,
            tax_class=self.tax_class_germany,
            currency='CAD',
            config_json='{"products": {"products": [%d]}}' % p1.id,
            )
        discount.add_to(order)
        order.recalculate_total()

        # Exact values after usage of different tax rates in same order
        #self.assertAlmostEqual(order.total, Decimal('548.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal('548.85'))
        self.assertAlmostEqual(order.discount, Decimal('50.00'))
Ejemplo n.º 8
0
    def test_18_amount_discount_incl_tax(self):
        """Test discount amounts specified with tax included"""
        p1 = self.create_product()
        p2 = self.create_product()

        price = p1.get_price(currency="CAD")
        price.tax_class = self.tax_class_germany
        price.save()

        order = self.create_order()
        order.currency = "CAD"
        order.save()

        normal1 = order.modify_item(p1, 3)
        normal2 = order.modify_item(p2, 5)

        order.recalculate_total()
        # self.assertAlmostEqual(order.total, Decimal('598.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal("598.85"))

        discount = Discount.objects.create(
            type=Discount.AMOUNT_VOUCHER_INCL_TAX,
            code="asdf",
            name="Amount discount",
            value=Decimal("50.00"),
            is_active=True,
            tax_class=self.tax_class_germany,
            currency="CAD",
            config='{"products": {"products": [%d]}}' % p1.id,
        )
        discount.add_to(order)
        order.recalculate_total()

        # Exact values after usage of different tax rates in same order
        # self.assertAlmostEqual(order.total, Decimal('548.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal("548.85"))
        self.assertAlmostEqual(order.discount, Decimal("50.00"))
Ejemplo n.º 9
0
    def test_18_amount_discount_incl_tax(self):
        """Test discount amounts specified with tax included"""
        p1 = self.create_product()
        p2 = self.create_product()

        price = p1.get_price(currency="CAD")
        price.tax_class = self.tax_class_germany
        price.save()

        order = self.create_order()
        order.currency = "CAD"
        order.save()

        order.modify_item(p1, 3)
        order.modify_item(p2, 5)

        order.recalculate_total()
        # self.assertAlmostEqual(order.total, Decimal('598.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal("598.85"))

        discount = Discount.objects.create(
            type=Discount.AMOUNT_VOUCHER_INCL_TAX,
            code="asdf",
            name="Amount discount",
            value=Decimal("50.00"),
            is_active=True,
            tax_class=self.tax_class_germany,
            currency="CAD",
            config='{"products": {"products": [%d]}}' % p1.id,
        )
        discount.add_to(order)
        order.recalculate_total()

        # Exact values after usage of different tax rates in same order
        # self.assertAlmostEqual(order.total, Decimal('548.84'))
        # We use ROUND_HALF_UP now
        self.assertAlmostEqual(order.total, Decimal("548.85"))
        self.assertAlmostEqual(order.discount, Decimal("50.00"))
Ejemplo n.º 10
0
 def _compare(data):
     order.data = data
     order.save()
     reloaded_order = Order.objects.get(pk=order.pk)
     self.assertEqual(data, reloaded_order.data)
Ejemplo n.º 11
0
 def _compare(data):
     order.data = data
     order.save()
     reloaded_order = Order.objects.get(pk=order.pk)
     self.assertEqual(data, reloaded_order.data)