Add needs_price_update field to Purchase model #94
@@ -14,14 +14,14 @@ currency_to = currency_to.upper()
|
||||
|
lukas marked this conversation as resolved
|
||||
|
||||
|
||||
def _get_exchange_rate(currency_from, currency_to, year):
|
||||
logger.info(
|
||||
|
lukas marked this conversation as resolved
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
lukas
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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
commented
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to _get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to `rate`.
lukas
commented
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.
|
||||
@@ -1,6 +1,6 @@
|
||||
|
lukas marked this conversation as resolved
lukas
commented
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
commented
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
lukas
commented
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
lukas
commented
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,13 +29,6 @@ class PurchaseNeedsPriceUpdateTest(TestCase):
|
||||
|
lukas marked this conversation as resolved
lukas
commented
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
commented
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
lukas
commented
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
lukas
commented
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
lukas
commented
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
lukas
commented
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
lukas
commented
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
lukas
commented
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
lukas
commented
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()
|
||||
|
||||
purchase.refresh_from_db()
|
||||
|
||||
|
lukas marked this conversation as resolved
lukas
commented
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
commented
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.
|
||||
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to
rate.Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.
_get_exchange_rate() returns a bare float (not an ExchangeRate object), but the variable name is misleading. Consider renaming to
rate.Exchange rate lookups use logger.info() — consider logger.debug() for these routine operations.