Add needs_price_update field to Purchase model #94

Merged
lukas merged 3 commits from purchase-needs-price-update into main 2026-05-12 13:03:34 +00:00
2 changed files with 13 additions and 20 deletions
Showing only changes of commit 5003b739d3 - Show all commits
+11 -11
View File
@@ -14,14 +14,14 @@ currency_to = currency_to.upper()
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
def _get_exchange_rate(currency_from, currency_to, year):
logger.info(
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
logger.debug(
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
f"[convert_prices]: Looking for exchange rate in database: {currency_from}->{currency_to}"
)
exchange_rate = ExchangeRate.objects.filter(
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
rate = ExchangeRate.objects.filter(
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
currency_from=currency_from, currency_to=currency_to, year=year
).first()
if not exchange_rate:
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
logger.info(
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
if not rate:
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
logger.debug(
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
f"[convert_prices]: Getting exchange rate from {currency_from} to {currency_to} for {year}..."
)
try:
@@ -40,16 +40,16 @@ def _get_exchange_rate(currency_from, currency_to, year):
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
year=year,
rate=floatformat(rate, 2),
)
exchange_rate = exchange_rate.rate
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
rate = exchange_rate.rate
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
else:
logger.info("[convert_prices]: Could not get an exchange rate.")
except requests.RequestException as e:
logger.info(
f"[convert_prices]: Failed to fetch exchange rate for {currency_from}->{currency_to} in {year}: {e}"
)
elif exchange_rate:
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
exchange_rate = exchange_rate.rate
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
return exchange_rate
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
elif rate:
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
rate = rate.rate
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
return rate
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
def _save_converted_price(purchase, converted_price, needs_update):
@@ -78,11 +78,11 @@ def convert_prices():
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
continue
year = purchase.date_purchased.year
currency_from = purchase.price_currency.upper()
exchange_rate = _get_exchange_rate(currency_from, currency_to, year)
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
if exchange_rate:
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
rate = _get_exchange_rate(currency_from, currency_to, year)
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
if rate:
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
_save_converted_price(
purchase,
floatformat(purchase.price * exchange_rate, 0),
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
floatformat(purchase.price * rate, 0),
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
needs_update,
)
lukas marked this conversation as resolved
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
Review

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to rate.

_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
Review

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.

Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
+2 -9
View File
@@ -1,6 +1,6 @@
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
from datetime import date
from django.test import TestCase, override_settings
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
from django.test import TestCase
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
from games.models import Game, Platform, Purchase
from games.tasks import convert_prices
@@ -29,14 +29,7 @@ class PurchaseNeedsPriceUpdateTest(TestCase):
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
purchase.games.add(self.game)
self.assertTrue(purchase.needs_price_update)
with override_settings(
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
CACHES={
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
"default": {
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
"BACKEND": "django.core.cache.backends.locmem.LocMemCache"
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
}
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
}
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
):
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
convert_prices()
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
convert_prices()
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
purchase.refresh_from_db()
self.assertFalse(purchase.needs_price_update)
lukas marked this conversation as resolved
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.
Review

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.

override_settings(CACHES=...) seems unnecessary since convert_prices() doesn't use caching. Could be removed if left from an earlier version.