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):
|
def _get_exchange_rate(currency_from, currency_to, year):
|
||||||
logger.info(
|
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.
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}"
|
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
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 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
|
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
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 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(
|
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.
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}..."
|
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
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,
|
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
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 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:
|
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
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 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
|
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.
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
|
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.
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):
|
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
|
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
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 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:
|
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.
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(
|
_save_converted_price(
|
||||||
purchase,
|
purchase,
|
||||||
floatformat(purchase.price * exchange_rate, 0),
|
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.
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,
|
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 datetime import date
|
||||||
|
|
||||||
from django.test import TestCase, override_settings
|
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.
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.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
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)
|
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
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.
|
|||||||
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()
|
|
||||||
|
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.
|
|||||||
|
|
||||||
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
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.