Skip to content

Commit

Permalink
Fixing formatting errors on receipt page, should not charge tax if Ta…
Browse files Browse the repository at this point in the history
…xRate (#2775)

* Fixing formatting errors on receipt page, should not charge tax if TaxRate is inactive

* missed one raw int(0)

* Updating serializer for basket to respect taxrate active flag
  • Loading branch information
jkachel authored Oct 2, 2023
1 parent 6a4199c commit 0ffdfad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion ecommerce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ def create_unfulfilled_order(validated_basket, affiliate_id=None, **kwargs):
)

try:
tax_rate_info = TaxRate.objects.get(country_code=country_code)
tax_rate_info = TaxRate.objects.filter(active=True).get(
country_code=country_code
)
except (TaxRate.DoesNotExist, TaxRate.MultipleObjectsReturned):
# not using get_or_create here because we don't want the rate to stick around
tax_rate_info = TaxRate()
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/mail_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def test_send_ecommerce_order_receipt(mocker, receipt_data):
{
"quantity": 1,
"total_paid": "100.00",
"tax_paid": 0,
"tax_paid": "0.00",
"discount": "0.00",
"price": "100.00",
"readable_id": get_readable_id(
Expand Down
15 changes: 11 additions & 4 deletions ecommerce/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" ecommerce serializers """
# pylint: disable=too-many-lines
import logging
from decimal import Decimal

from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.validators import MaxValueValidator, MinValueValidator
Expand Down Expand Up @@ -371,7 +372,11 @@ def get_tax_info(self, _):
if request and hasattr(request, "user"):
country_code = determine_visitor_country(request)
if country_code is not None:
return TaxRate.objects.get(country_code=country_code).to_dict()
return (
TaxRate.objects.filter(active=True)
.get(country_code=country_code)
.to_dict()
)
else:
log.error("No request object in get_tax_info")
except TaxRate.DoesNotExist:
Expand Down Expand Up @@ -975,9 +980,11 @@ def get_lines(self, instance):
product_version=line.product_version,
tax_rate=instance.tax_rate,
)
tax_paid = product_price_and_tax["tax_assessed"] * line.quantity
tax_paid = Decimal(
product_price_and_tax["tax_assessed"] * line.quantity
).quantize(Decimal(".01"))
total_price = product_price_and_tax["price"] * line.quantity
total_paid = total_price + tax_paid
total_paid = Decimal(total_price + tax_paid).quantize(Decimal(".01"))
discount = (line.product_version.price * line.quantity) - total_price

dates = CourseRunEnrollment.objects.filter(
Expand Down Expand Up @@ -1016,7 +1023,7 @@ def get_lines(self, instance):
dict(
quantity=line.quantity,
total_paid=str(total_paid),
tax_paid=tax_paid,
tax_paid=str(tax_paid),
discount=str(discount),
CEUs=str(CEUs) if CEUs else None,
**BaseProductVersionSerializer(line.product_version).data,
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_serialize_order_receipt(receipt_data):
"end_date": None,
"price": str(product_version.price),
"total_paid": str(line.quantity * product_version.price),
"tax_paid": 0,
"tax_paid": "0.00",
"quantity": line.quantity,
"CEUs": product_version.product.content_object.course.page.certificate_page.CEUs,
}
Expand Down

0 comments on commit 0ffdfad

Please sign in to comment.