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): def _get_exchange_rate(currency_from, currency_to, year):
logger.info( 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.
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}" f"[convert_prices]: Looking for exchange rate in database: {currency_from}->{currency_to}"
) )
exchange_rate = ExchangeRate.objects.filter( 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.
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 currency_from=currency_from, currency_to=currency_to, year=year
).first() ).first()
if not exchange_rate: 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.
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( 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.
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}..." f"[convert_prices]: Getting exchange rate from {currency_from} to {currency_to} for {year}..."
) )
try: 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, year=year,
rate=floatformat(rate, 2), rate=floatformat(rate, 2),
) )
exchange_rate = exchange_rate.rate 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.
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: else:
logger.info("[convert_prices]: Could not get an exchange rate.") logger.info("[convert_prices]: Could not get an exchange rate.")
except requests.RequestException as e: except requests.RequestException as e:
logger.info( logger.info(
f"[convert_prices]: Failed to fetch exchange rate for {currency_from}->{currency_to} in {year}: {e}" f"[convert_prices]: Failed to fetch exchange rate for {currency_from}->{currency_to} in {year}: {e}"
) )
elif exchange_rate: 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.
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 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.
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 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.
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): 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 continue
year = purchase.date_purchased.year year = purchase.date_purchased.year
currency_from = purchase.price_currency.upper() currency_from = purchase.price_currency.upper()
exchange_rate = _get_exchange_rate(currency_from, currency_to, year) 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.
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: 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.
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( _save_converted_price(
purchase, purchase,
floatformat(purchase.price * exchange_rate, 0), 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.
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, 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 datetime import date
from django.test import TestCase, override_settings 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.
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.models import Game, Platform, Purchase
from games.tasks import convert_prices 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) purchase.games.add(self.game)
self.assertTrue(purchase.needs_price_update) self.assertTrue(purchase.needs_price_update)
with override_settings( 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.
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.
purchase.refresh_from_db() purchase.refresh_from_db()
self.assertFalse(purchase.needs_price_update) 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.