You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tax_tests.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from decimal import Decimal as D
  2. from django.test import TestCase
  3. from oscar.apps.offer import models
  4. from oscar.apps.basket.models import Basket
  5. from oscar.apps.partner import strategy
  6. from oscar.test.basket import add_product
  7. class TestAValueBasedOffer(TestCase):
  8. def setUp(self):
  9. # Get 20% if spending more than 20.00
  10. range = models.Range.objects.create(
  11. name="All products", includes_all_products=True)
  12. condition = models.Condition.objects.create(
  13. range=range,
  14. type=models.Condition.VALUE,
  15. value=D('10.00'))
  16. benefit = models.Benefit.objects.create(
  17. range=range,
  18. type=models.Benefit.PERCENTAGE,
  19. value=20)
  20. self.offer = models.ConditionalOffer.objects.create(
  21. name="Test",
  22. offer_type=models.ConditionalOffer.SITE,
  23. condition=condition,
  24. benefit=benefit)
  25. self.basket = Basket.objects.create()
  26. def test_respects_effective_price_when_taxes_not_known(self):
  27. # Assign US style strategy (no tax known)
  28. self.basket.strategy = strategy.US()
  29. # Add sufficient products to meet condition
  30. add_product(self.basket, price=D('6'), quantity=2)
  31. # Ensure discount is correct
  32. result = self.offer.apply_benefit(self.basket)
  33. self.assertEqual(D('2.40'), result.discount)
  34. def test_respects_effective_price_when_taxes_are_known(self):
  35. # Assign UK style strategy (20% tax)
  36. self.basket.strategy = strategy.UK()
  37. # Add sufficient products to meet condition
  38. add_product(self.basket, price=D('6'), quantity=2)
  39. # Ensure discount is calculated against tax-inclusive price
  40. result = self.offer.apply_benefit(self.basket)
  41. self.assertEqual(2 * D('6.00') * D('1.2') * D('0.20'), result.discount)