Пример #1
0
    def test_10_discount_validation(self):
        """Test discount validity periods"""
        order = self.create_order()
        d = Discount(is_active=False, valid_from=date(2100, 1, 1), valid_until=None)  # far future date

        try:
            d.validate(order)
        except ValidationError, e:
            self.assertEqual(len(e.messages), 2)
Пример #2
0
    def test_10_discount_validation(self):
        """Test discount validity periods"""
        order = self.create_order()
        d = Discount(
            is_active=False,
            valid_from=date(2100, 1, 1), # far future date
            valid_until=None,
            )

        try:
            d.validate(order)
        except ValidationError, e:
            self.assertEqual(len(e.messages), 2)
Пример #3
0
    def test_12_order4567_test(self):
        """Reproduce order ID 4567 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = 'Kleid'
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(
            _unit_price=160,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(
            _unit_price=280,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        c = Category.objects.create(
            name='category',
            slug='category',
            )
        p1.categories.add(c)

        order.modify_item(p1, 1)
        order.modify_item(p2, 1)

        self.assertAlmostEqual(order.total, Decimal('440.00'))

        discount = Discount(
            type=Discount.PERCENTAGE,
            name='Sonderrabatt Kleid',
            value=Decimal('20.00'),
            code='1234code',
            )
        discount.config = {'only_categories': {'categories': [c.pk]}}
        discount.save()

        order.add_discount(discount)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, 408)
        self.assertAlmostEqual(order.subtotal, 440)
        self.assertAlmostEqual(order.discount, 32)
Пример #4
0
    def test_13_order4206_test(self):
        """Reproduce order ID 4206 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = 'Venice'
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(
            _unit_price=170,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(
            _unit_price=Decimal('40.80'),
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        order.modify_item(p1, 1)
        order.modify_item(p2, 1)

        c = Category.objects.create(
            name='category',
            slug='category',
            )
        p1.categories.add(c)

        discount = Discount(
            type=Discount.AMOUNT_INCL_TAX,
            name='Sonderrabatt Venice',
            value=Decimal('20.00'),
            code='1234code',
            )
        discount.config = {'only_categories': {'categories': [c.pk]}}
        discount.save()

        order.add_discount(discount)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal('190.80'))
        self.assertAlmostEqual(order.subtotal, Decimal('210.80'))
        self.assertAlmostEqual(order.discount, 20)
Пример #5
0
    def test_11_multiple_discounts(self):
        """Test behavior of orders with more than one discount"""
        order = self.create_order()
        product = self.create_product()
        order.modify_item(product.variations.get(), 3)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal('239.70'))

        Discount.objects.create(
            type=Discount.PERCENTAGE,
            name='Percentage',
            code='perc20',
            value=Decimal('20.00'),
            is_active=True,
            ).add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal('239.70') / 5 * 4)

        # Add unsaved discount
        Discount(
            type=Discount.AMOUNT_INCL_TAX,
            name='Amount incl. tax',
            code='amount_incl_20',
            value=Decimal('20.00'),
            is_active=True,
            tax_class=self.tax_class,
            currency='CHF',
            ).add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, (Decimal('239.70') - 20) / 5 * 4)
Пример #6
0
    def test_11_multiple_discounts(self):
        """Test behavior of orders with more than one discount"""
        order = self.create_order()
        product = self.create_product()
        order.modify_item(product, 3)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal("239.70"))

        Discount.objects.create(
            type=Discount.PERCENTAGE_VOUCHER,
            name="Percentage",
            code="perc20",
            value=Decimal("20.00"),
            is_active=True,
        ).add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal("239.70") / 5 * 4)

        # Add unsaved discount
        Discount(
            type=Discount.AMOUNT_VOUCHER_INCL_TAX,
            name="Amount incl. tax",
            code="amount_incl_20",
            value=Decimal("20.00"),
            is_active=True,
            tax_class=self.tax_class,
            currency="CHF",
        ).add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, (Decimal("239.70") - 20) / 5 * 4)
Пример #7
0
    def test_09_selective_discount(self):
        """Test applying discounts with product restriction"""
        p1 = self.create_product()
        p2 = self.create_product()
        p2.name = 'Discountable'
        p2.save()

        d = Discount(
            type=Discount.PERCENTAGE_VOUCHER,
            name='Some discount',
            code='asdf',
            value=Decimal('30'),
            is_active=True,
        )

        d.config = {'name_filter': {'name': 'Discountable'}}
        d.save()

        order = self.create_order()
        order.modify_item(p1, 3)
        order.modify_item(p2, 2)
        d.add_to(order)
        order.recalculate_total()

        # Test that only one order item has its discount applied
        Product = plata.product_model()
        self.assertEqual(Product.objects.all().count(), 2)
        self.assertEqual(order.items.count(), 2)
        self.assertEqual(
            1,
            len([
                item for item in order.items.all() if item._line_item_discount
            ]))
Пример #8
0
    def test_09_selective_discount(self):
        """Test applying discounts with product restriction"""
        p1 = self.create_product()
        p2 = self.create_product()
        p2.name = 'Discountable'
        p2.save()

        c = Category.objects.create(
            name='category',
            slug='category',
            is_active=True,
            is_internal=True,
            )
        p2.categories.add(c)

        d = Discount(
            type=Discount.PERCENTAGE,
            name='Some discount',
            code='asdf',
            value=Decimal('30'),
            is_active=True,
            )

        d.config = {'only_categories': {'categories': [c.pk]}}
        d.save()

        order = self.create_order()
        order.modify_item(p1, 3)
        order.modify_item(p2, 2)
        order.add_discount(d)
        order.recalculate_total()

        # Test that only one order item has its discount applied
        self.assertEqual(Product.objects.all().count(), 2)
        self.assertEqual(order.items.count(), 2)
        self.assertEqual(1,
            len([item for item in order.items.all() if item._line_item_discount]))

        self.assertEqual(Category.objects.active().count(), 1)
        self.assertEqual(Category.objects.public().count(), 0)
        self.assertEqual(unicode(Category.objects.create(
            name='blaa', slug='blaa', parent=c)), 'category - blaa')
Пример #9
0
    def test_09_selective_discount(self):
        """Test applying discounts with product restriction"""
        p1 = self.create_product()
        p2 = self.create_product()
        p2.name = 'Discountable'
        p2.save()

        d = Discount(
            type=Discount.PERCENTAGE_VOUCHER,
            name='Some discount',
            code='asdf',
            value=Decimal('30'),
            is_active=True,
            )

        d.config = {'name_filter': {'name': 'Discountable'}}
        d.save()

        order = self.create_order()
        order.modify_item(p1, 3)
        order.modify_item(p2, 2)
        d.add_to(order)
        order.recalculate_total()

        # Test that only one order item has its discount applied
        Product = plata.product_model()
        self.assertEqual(Product.objects.all().count(), 2)
        self.assertEqual(order.items.count(), 2)
        self.assertEqual(1,
            len([item for item in order.items.all() if item._line_item_discount]))
Пример #10
0
    def test_12_order4567_test(self):
        """Reproduce order ID 4567 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = "Kleid"
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(_unit_price=160, tax_included=True, currency=order.currency, tax_class=self.tax_class)

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(_unit_price=280, tax_included=True, currency=order.currency, tax_class=self.tax_class)

        order.modify_item(p1, 1)
        order.modify_item(p2, 1)

        self.assertAlmostEqual(order.total, Decimal("440.00"))

        discount = Discount(
            type=Discount.PERCENTAGE_VOUCHER, name="Sonderrabatt Kleid", value=Decimal("20.00"), code="1234code"
        )
        discount.config = {"name_filter": {"name": "Kleid"}}
        discount.save()

        discount.add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, 408)
        self.assertAlmostEqual(order.subtotal, 440)
        self.assertAlmostEqual(order.discount, 32)
Пример #11
0
    def test_13_order4206_test(self):
        """Reproduce order ID 4206 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = 'Venice'
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(
            _unit_price=170,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(
            _unit_price=Decimal('40.80'),
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        order.modify_item(p1.variations.get(), 1)
        order.modify_item(p2.variations.get(), 1)

        c = Category.objects.create(
            name='category',
            slug='category',
            )
        p1.categories.add(c)

        discount = Discount(
            type=Discount.AMOUNT_INCL_TAX,
            name='Sonderrabatt Venice',
            value=Decimal('20.00'),
            code='1234code',
            tax_class=self.tax_class,
            currency='CHF',
            )
        discount.config = {'only_categories': {'categories': [c.pk]}}
        discount.save()

        discount.add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal('190.80'))
        self.assertAlmostEqual(order.subtotal, Decimal('210.80'))
        self.assertAlmostEqual(order.discount, 20)
Пример #12
0
    def test_12_order4567_test(self):
        """Reproduce order ID 4567 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = 'Kleid'
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(
            _unit_price=160,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(
            _unit_price=280,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        c = Category.objects.create(
            name='category',
            slug='category',
            )
        p1.categories.add(c)

        order.modify_item(p1.variations.get(), 1)
        order.modify_item(p2.variations.get(), 1)

        self.assertAlmostEqual(order.total, Decimal('440.00'))

        discount = Discount(
            type=Discount.PERCENTAGE,
            name='Sonderrabatt Kleid',
            value=Decimal('20.00'),
            code='1234code',
            )
        discount.config = {'only_categories': {'categories': [c.pk]}}
        discount.save()

        discount.add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, 408)
        self.assertAlmostEqual(order.subtotal, 440)
        self.assertAlmostEqual(order.discount, 32)
Пример #13
0
    def test_13_order4206_test(self):
        """Reproduce order ID 4206 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = 'Venice'
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(
            _unit_price=170,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
        )

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(
            _unit_price=Decimal('40.80'),
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
        )

        order.modify_item(p1, 1)
        order.modify_item(p2, 1)

        discount = Discount(
            type=Discount.AMOUNT_VOUCHER_INCL_TAX,
            name='Sonderrabatt Venice',
            value=Decimal('20.00'),
            code='1234code',
            tax_class=self.tax_class,
            currency='CHF',
        )
        discount.config = {'name_filter': {'name': 'Venice'}}
        discount.save()

        discount.add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal('190.80'))
        self.assertAlmostEqual(order.subtotal, Decimal('210.80'))
        self.assertAlmostEqual(order.discount, 20)
Пример #14
0
    def test_12_order4567_test(self):
        """Reproduce order ID 4567 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = 'Kleid'
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(
            _unit_price=160,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
        )

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(
            _unit_price=280,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
        )

        order.modify_item(p1, 1)
        order.modify_item(p2, 1)

        self.assertAlmostEqual(order.total, Decimal('440.00'))

        discount = Discount(
            type=Discount.PERCENTAGE_VOUCHER,
            name='Sonderrabatt Kleid',
            value=Decimal('20.00'),
            code='1234code',
        )
        discount.config = {'name_filter': {'name': 'Kleid'}}
        discount.save()

        discount.add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, 408)
        self.assertAlmostEqual(order.subtotal, 440)
        self.assertAlmostEqual(order.discount, 32)
Пример #15
0
    def test_09_selective_discount(self):
        """Test applying discounts with product restriction"""
        p1 = self.create_product()
        p2 = self.create_product()
        p2.name = 'Discountable'
        p2.save()

        c = Category.objects.create(
            name='category',
            slug='category',
            is_active=True,
            is_internal=True,
            )
        p2.categories.add(c)

        d = Discount(
            type=Discount.PERCENTAGE,
            name='Some discount',
            code='asdf',
            value=Decimal('30'),
            is_active=True,
            )

        d.config = {'only_categories': {'categories': [c.pk]}}
        d.save()

        order = self.create_order()
        order.modify_item(p1.variations.get(), 3)
        order.modify_item(p2.variations.get(), 2)
        d.add_to(order)
        order.recalculate_total()

        # Test that only one order item has its discount applied
        self.assertEqual(Product.objects.all().count(), 2)
        self.assertEqual(order.items.count(), 2)
        self.assertEqual(1,
            len([item for item in order.items.all() if item._line_item_discount]))

        self.assertEqual(Category.objects.active().count(), 1)
        self.assertEqual(Category.objects.public().count(), 0)
        self.assertEqual(unicode(Category.objects.create(
            name='blaa', slug='blaa', parent=c)), 'category - blaa')
Пример #16
0
    def test_13_order4206_test(self):
        """Reproduce order ID 4206 of a deployed satchmo shop installation"""
        order = self.create_order()

        p1 = self.create_product()
        p1.name = 'Venice'
        p1.save()
        p1.prices.all().delete()
        p1.prices.create(
            _unit_price=170,
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        p2 = self.create_product()
        p2.prices.all().delete()
        p2.prices.create(
            _unit_price=Decimal('40.80'),
            tax_included=True,
            currency=order.currency,
            tax_class=self.tax_class,
            )

        order.modify_item(p1, 1)
        order.modify_item(p2, 1)

        discount = Discount(
            type=Discount.AMOUNT_VOUCHER_INCL_TAX,
            name='Sonderrabatt Venice',
            value=Decimal('20.00'),
            code='1234code',
            tax_class=self.tax_class,
            currency='CHF',
            )
        discount.config = {'name_filter': {'name': 'Venice'}}
        discount.save()

        discount.add_to(order)
        order.recalculate_total()

        self.assertAlmostEqual(order.total, Decimal('190.80'))
        self.assertAlmostEqual(order.subtotal, Decimal('210.80'))
        self.assertAlmostEqual(order.discount, 20)