Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Do not update last_change in checkout prices recalculations (#18538)
Iga Karbowiak16ceede761ca
diff --git a/saleor/checkout/calculations.py b/saleor/checkout/calculations.pyindex f6bbf417e8..f9bb38922a 100644--- a/saleor/checkout/calculations.py+++ b/saleor/checkout/calculations.py@@ -465,7 +465,6 @@ def _fetch_checkout_prices_if_expired("discount_amount","discount_name","currency",- "last_change","price_expiration","discount_expiration","tax_error",diff --git a/saleor/checkout/tests/test_calculations.py b/saleor/checkout/tests/test_calculations.pyindex 4fd66698b2..005f07711d 100644--- a/saleor/checkout/tests/test_calculations.py+++ b/saleor/checkout/tests/test_calculations.py@@ -1462,13 +1462,15 @@ def test_fetch_checkout_data_checkout_updated_during_price_recalculation("lines": lines_info,}expected_email = "[email protected]"+ freeze_time_str = "2024-01-01T12:00:00+00:00"# whendef modify_checkout(*args, **kwargs):- checkout_to_modify = Checkout.objects.get(pk=checkout.pk)- checkout_to_modify.lines.update(quantity=F("quantity") + 1)- checkout_to_modify.email = expected_email- checkout_to_modify.save(update_fields=["email", "last_change"])+ with freeze_time(freeze_time_str):+ checkout_to_modify = Checkout.objects.get(pk=checkout.pk)+ checkout_to_modify.lines.update(quantity=F("quantity") + 1)+ checkout_to_modify.email = expected_email+ checkout_to_modify.save(update_fields=["email", "last_change"])with race_condition.RunAfter("saleor.checkout.calculations._calculate_and_add_tax", modify_checkout@@ -1489,7 +1491,8 @@ def test_fetch_checkout_data_checkout_updated_during_price_recalculation(# Check if database contains updated checkout by other requests.checkout.refresh_from_db()- assert checkout.last_change > last_change_before_recalculation+ assert checkout.last_change != last_change_before_recalculation+ assert checkout.last_change.isoformat() == freeze_time_strassert checkout.email == expected_emailfor old_line, new_line in zip(lines, checkout.lines.all(), strict=True):assert old_line.quantity + 1 == new_line.quantitydiff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex bba41d4f98..b07d7f49b4 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -11,6 +11,7 @@ from django.test import override_settingsfrom django.utils import timezonefrom django.utils.dateparse import parse_datetimefrom django_countries.fields import Country+from freezegun import freeze_timefrom measurement.measures import Weightfrom prices import Money@@ -2949,14 +2950,16 @@ def test_checkout_prices_with_checkout_updated_during_price_recalculation(}total_before_recalculation = checkout.totallines_before_recalculation = list(checkout.lines.all())+ freeze_time_str = "2024-01-01T12:00:00+00:00"# whendef modify_checkout(*args, **kwargs):- with allow_writer():- checkout_to_modify = Checkout.objects.get(pk=checkout.pk)- checkout_to_modify.lines.update(quantity=F("quantity") + 1)- checkout_to_modify.email = expected_email- checkout_to_modify.save(update_fields=["email", "last_change"])+ with freeze_time(freeze_time_str):+ with allow_writer():+ checkout_to_modify = Checkout.objects.get(pk=checkout.pk)+ checkout_to_modify.lines.update(quantity=F("quantity") + 1)+ checkout_to_modify.email = expected_email+ checkout_to_modify.save(update_fields=["email", "last_change"])with race_condition.RunAfter("saleor.checkout.calculations._calculate_and_add_tax", modify_checkout@@ -2976,6 +2979,7 @@ def test_checkout_prices_with_checkout_updated_during_price_recalculation(checkout.refresh_from_db()assert checkout.email == expected_email+ assert checkout.last_change.isoformat() == freeze_time_str# Confirm that total price hasn't changed in database due to recalculationassert checkout.total == total_before_recalculation