Add needs_price_update field to Purchase model #94
@@ -0,0 +1,22 @@
|
|||||||
|
lukas marked this conversation as resolved
|
|||||||
|
# Generated by Django 6.0.1 on 2026-05-12 11:57
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
from django.db import migrations, models
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
class Migration(migrations.Migration):
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
dependencies = [
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
('games', '0015_alter_purchase_date_purchased_and_more'),
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
]
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
operations = [
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
migrations.AddField(
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
model_name='purchase',
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
name='needs_price_update',
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
field=models.BooleanField(db_index=True, default=True),
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
),
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
migrations.RunSQL(
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
"UPDATE games_purchase SET needs_price_update = FALSE WHERE converted_price IS NOT NULL AND converted_currency != ''",
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
reverse_sql="UPDATE games_purchase SET needs_price_update = TRUE WHERE converted_price IS NOT NULL AND converted_currency != ''",
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
),
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
|
]
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly. The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
|
|||||||
@@ -179,6 +179,7 @@ class Purchase(models.Model):
|
|||||||
price_currency = models.CharField(max_length=3, default="USD")
|
price_currency = models.CharField(max_length=3, default="USD")
|
||||||
converted_price = models.FloatField(null=True)
|
converted_price = models.FloatField(null=True)
|
||||||
converted_currency = models.CharField(max_length=3, blank=True, default="")
|
converted_currency = models.CharField(max_length=3, blank=True, default="")
|
||||||
|
needs_price_update = models.BooleanField(default=True, db_index=True)
|
||||||
price_per_game = GeneratedField(
|
price_per_game = GeneratedField(
|
||||||
expression=Coalesce(F("converted_price"), F("price"), 0) / F("num_purchases"),
|
expression=Coalesce(F("converted_price"), F("price"), 0) / F("num_purchases"),
|
||||||
output_field=models.FloatField(),
|
output_field=models.FloatField(),
|
||||||
@@ -240,12 +241,6 @@ class Purchase(models.Model):
|
|||||||
def is_game(self):
|
def is_game(self):
|
||||||
return self.type == self.GAME
|
return self.type == self.GAME
|
||||||
|
|
||||||
def price_or_currency_differ_from(self, purchase_to_compare):
|
|
||||||
return (
|
|
||||||
self.price != purchase_to_compare.price
|
|
||||||
or self.price_currency != purchase_to_compare.price_currency
|
|
||||||
)
|
|
||||||
|
|
||||||
def refund(self):
|
def refund(self):
|
||||||
self.date_refunded = timezone.now()
|
self.date_refunded = timezone.now()
|
||||||
self.save()
|
self.save()
|
||||||
@@ -255,19 +250,6 @@ class Purchase(models.Model):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
f"{self.get_type_display()} must have a related purchase."
|
f"{self.get_type_display()} must have a related purchase."
|
||||||
)
|
)
|
||||||
if self.pk is not None:
|
|
||||||
# Retrieve the existing instance from the database
|
|
||||||
existing_purchase = Purchase.objects.get(pk=self.pk)
|
|
||||||
# If price has changed, reset converted fields
|
|
||||||
if existing_purchase.price_or_currency_differ_from(self):
|
|
||||||
from games.tasks import currency_to
|
|
||||||
|
|
||||||
exchange_rate = get_or_create_rate(
|
|
||||||
self.price_currency, currency_to, self.date_purchased.year
|
|
||||||
)
|
|
||||||
if exchange_rate:
|
|
||||||
self.converted_price = floatformat(self.price * exchange_rate, 0)
|
|
||||||
self.converted_currency = currency_to
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,29 @@ from games.models import Game, GameStatusChange, Purchase, Session
|
|||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
logger = logging.getLogger("games")
|
logger = logging.getLogger("games")
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(pre_save, sender=Purchase)
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
def store_purchase_price_snapshot(sender, instance, **kwargs):
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
"""Store old price values before save so we can detect changes."""
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
if instance.pk is not None:
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
try:
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
old_instance = sender.objects.get(pk=instance.pk)
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
instance._old_price = old_instance.price
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
instance._old_currency = old_instance.price_currency
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
except sender.DoesNotExist:
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
pass
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
@receiver(post_save, sender=Purchase)
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
def mark_needs_price_update(sender, instance, created, **kwargs):
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
"""Mark purchase for price update if price or currency changed."""
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
if not created and hasattr(instance, "_old_price"):
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
if (
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
instance.price != instance._old_price
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
or instance.price_currency != instance._old_currency
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
):
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
sender.objects.filter(pk=instance.pk).update(needs_price_update=True)
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
|
|
||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
@receiver(m2m_changed, sender=Purchase.games.through)
|
@receiver(m2m_changed, sender=Purchase.games.through)
|
||||||
def update_num_purchases(sender, instance, action, reverse, **kwargs):
|
def update_num_purchases(sender, instance, action, reverse, **kwargs):
|
||||||
if not reverse and action.startswith("post_"):
|
if not reverse and action.startswith("post_"):
|
||||||
|
|||||||
|
lukas marked this conversation as resolved
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
lukas
commented
This signal handler fetches the old instance from the DB on every update. The old code in This signal handler fetches the old instance from the DB on every update. The old code in `save()` also fetched from DB, so it's a wash query-wise — not strictly fewer queries. Just worth noting the trade-off.
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
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.
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
from django.db import models
|
||||||
|
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.
|
|||||||
from django.template.defaultfilters import floatformat
|
from django.template.defaultfilters import floatformat
|
||||||
|
|
||||||
logger = logging.getLogger("games")
|
logger = logging.getLogger("games")
|
||||||
@@ -12,68 +13,77 @@ currency_to = "CZK"
|
|||||||
|
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.
|
|||||||
currency_to = currency_to.upper()
|
currency_to = currency_to.upper()
|
||||||
|
|
||||||
|
|
||||||
def save_converted_info(purchase, converted_price, converted_currency):
|
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 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.info(
|
||||||
f"Setting converted price of {purchase} to {converted_price} {converted_currency} (originally {purchase.price} {purchase.price_currency})"
|
f"[convert_prices]: Looking for exchange rate in database: {currency_from}->{currency_to}"
|
||||||
|
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.
|
|||||||
|
)
|
||||||
|
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 = 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
|
||||||
|
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.
|
|||||||
|
).first()
|
||||||
|
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 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.
|
|||||||
|
f"[convert_prices]: Getting exchange rate from {currency_from} to {currency_to} for {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.
|
|||||||
|
try:
|
||||||
|
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.
|
|||||||
|
response = requests.get(
|
||||||
|
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"https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{year}-01-01/v1/currencies/{currency_from.lower()}.json"
|
||||||
|
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.
|
|||||||
|
response.raise_for_status()
|
||||||
|
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.
|
|||||||
|
data = response.json()
|
||||||
|
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_data = data.get(currency_from.lower())
|
||||||
|
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 = currency_from_data.get(currency_to.lower())
|
||||||
|
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.
|
|||||||
|
logger.info(f"[convert_prices]: Got {rate}, saving...")
|
||||||
|
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 = ExchangeRate.objects.create(
|
||||||
|
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,
|
||||||
|
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_to=currency_to,
|
||||||
|
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.
|
|||||||
|
year=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.
|
|||||||
|
rate=floatformat(rate, 2),
|
||||||
|
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
|
||||||
|
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:
|
||||||
|
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("[convert_prices]: Could not get an 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.
|
|||||||
|
except requests.RequestException as e:
|
||||||
|
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.
|
|||||||
|
f"[convert_prices]: Failed to fetch exchange rate for {currency_from}->{currency_to} in {year}: {e}"
|
||||||
|
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.
|
|||||||
|
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.
|
|||||||
|
|
||||||
|
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):
|
||||||
|
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.
|
|||||||
|
f"Setting converted price of {purchase} to {converted_price} {currency_to} (originally {purchase.price} {purchase.price_currency})"
|
||||||
|
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.
|
|||||||
)
|
)
|
||||||
purchase.converted_price = converted_price
|
purchase.converted_price = converted_price
|
||||||
purchase.converted_currency = converted_currency
|
purchase.converted_currency = currency_to
|
||||||
|
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.
|
|||||||
purchase.save()
|
if 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 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.
|
|||||||
|
purchase.needs_price_update = False
|
||||||
|
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.
|
|||||||
|
purchase.save(update_fields=["converted_price", "converted_currency", "needs_price_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.
|
|||||||
|
|
||||||
|
|
||||||
def convert_prices():
|
def convert_prices():
|
||||||
purchases = Purchase.objects.filter(
|
purchases = Purchase.objects.filter(
|
||||||
converted_price__isnull=True, converted_currency=""
|
models.Q(needs_price_update=True) | models.Q(converted_price__isnull=True)
|
||||||
|
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.
|
|||||||
)
|
).distinct()
|
||||||
|
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 purchases.count() == 0:
|
if purchases.count() == 0:
|
||||||
logger.info("[convert_prices]: No prices to convert.")
|
logger.info("[convert_prices]: No prices to convert.")
|
||||||
|
return
|
||||||
|
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.
|
|||||||
|
|
||||||
for purchase in purchases:
|
for purchase in purchases:
|
||||||
|
needs_update = purchase.needs_price_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.
|
|||||||
if purchase.price_currency.upper() == currency_to or purchase.price == 0:
|
if purchase.price_currency.upper() == currency_to or purchase.price == 0:
|
||||||
save_converted_info(purchase, purchase.price, currency_to)
|
_save_converted_price(purchase, purchase.price, 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 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.
|
|||||||
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)
|
||||||
|
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 = 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
|
|
||||||
|
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.
|
|||||||
).first()
|
|
||||||
|
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.
|
|||||||
f"[convert_prices]: Looking for exchange rate in database: {currency_from}->{currency_to}"
|
|
||||||
|
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 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.
|
|||||||
f"[convert_prices]: Getting exchange rate from {currency_from} to {currency_to} for {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.
|
|||||||
try:
|
|
||||||
|
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.
|
|||||||
# this API endpoint only accepts lowercase currency string
|
|
||||||
|
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.
|
|||||||
response = requests.get(
|
|
||||||
|
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"https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{year}-01-01/v1/currencies/{currency_from.lower()}.json"
|
|
||||||
|
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.
|
|||||||
response.raise_for_status()
|
|
||||||
|
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.
|
|||||||
data = response.json()
|
|
||||||
|
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_data = data.get(currency_from.lower())
|
|
||||||
|
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 = currency_from_data.get(currency_to.lower())
|
|
||||||
|
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 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(f"[convert_prices]: Got {rate}, saving...")
|
|
||||||
|
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 = ExchangeRate.objects.create(
|
|
||||||
|
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,
|
|
||||||
|
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_to=currency_to,
|
|
||||||
|
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.
|
|||||||
year=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.
|
|||||||
rate=floatformat(rate, 2),
|
|
||||||
|
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:
|
|
||||||
|
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("[convert_prices]: Could not get an 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.
|
|||||||
except requests.RequestException as e:
|
|
||||||
|
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.
|
|||||||
f"[convert_prices]: Failed to fetch exchange rate for {currency_from}->{currency_to} in {year}: {e}"
|
|
||||||
|
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 exchange_rate:
|
||||||
save_converted_info(
|
_save_converted_price(
|
||||||
|
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.
|
|||||||
purchase,
|
purchase,
|
||||||
floatformat(purchase.price * exchange_rate.rate, 0),
|
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.
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_to,
|
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 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.
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,3 +1,109 @@
|
|||||||
|
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 django.test import TestCase
|
from datetime import date
|
||||||
|
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.
|
|||||||
|
|
||||||
# Create your tests here.
|
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.
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
|
||||||
|
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.tasks import 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.
|
|||||||
|
|
||||||
|
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.
|
|||||||
|
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.
|
|||||||
|
def setUp(self):
|
||||||
|
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.
|
|||||||
|
self.platform = Platform.objects.create(name="PC", icon="pc", group="PC")
|
||||||
|
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.
|
|||||||
|
self.game = Game.objects.create(name="Test Game", platform=self.platform)
|
||||||
|
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.
|
|||||||
|
def test_new_purchase_has_needs_price_update_true(self):
|
||||||
|
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 = Purchase.objects.create(
|
||||||
|
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.
|
|||||||
|
price=50.0,
|
||||||
|
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.
|
|||||||
|
price_currency="USD",
|
||||||
|
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.
|
|||||||
|
date_purchased=date(2025, 1, 1),
|
||||||
|
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.
|
|||||||
|
purchase.games.add(self.game)
|
||||||
|
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.
|
|||||||
|
self.assertTrue(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 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.
|
|||||||
|
def test_convert_prices_sets_flag_to_false(self):
|
||||||
|
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 = Purchase.objects.create(
|
||||||
|
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.
|
|||||||
|
price=50.0,
|
||||||
|
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.
|
|||||||
|
price_currency="USD",
|
||||||
|
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.
|
|||||||
|
date_purchased=date(2025, 1, 1),
|
||||||
|
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.
|
|||||||
|
purchase.games.add(self.game)
|
||||||
|
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.
|
|||||||
|
self.assertTrue(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 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.
|
|||||||
|
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()
|
||||||
|
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.
|
|||||||
|
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.
|
|||||||
|
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 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.
|
|||||||
|
def test_price_change_sets_needs_price_update(self):
|
||||||
|
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 = Purchase.objects.create(
|
||||||
|
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.
|
|||||||
|
price=50.0,
|
||||||
|
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.
|
|||||||
|
price_currency="USD",
|
||||||
|
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.
|
|||||||
|
date_purchased=date(2025, 1, 1),
|
||||||
|
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.
|
|||||||
|
purchase.games.add(self.game)
|
||||||
|
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.converted_price = 1000
|
||||||
|
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.converted_currency = "CZK"
|
||||||
|
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.needs_price_update = False
|
||||||
|
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.save()
|
||||||
|
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.
|
|||||||
|
purchase.price = 60.0
|
||||||
|
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.save()
|
||||||
|
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()
|
||||||
|
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.
|
|||||||
|
self.assertTrue(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 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.
|
|||||||
|
def test_currency_change_sets_needs_price_update(self):
|
||||||
|
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 = Purchase.objects.create(
|
||||||
|
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.
|
|||||||
|
price=50.0,
|
||||||
|
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.
|
|||||||
|
price_currency="USD",
|
||||||
|
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.
|
|||||||
|
date_purchased=date(2025, 1, 1),
|
||||||
|
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.
|
|||||||
|
purchase.games.add(self.game)
|
||||||
|
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.converted_price = 1000
|
||||||
|
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.converted_currency = "CZK"
|
||||||
|
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.needs_price_update = False
|
||||||
|
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.save()
|
||||||
|
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.
|
|||||||
|
purchase.price_currency = "EUR"
|
||||||
|
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.save()
|
||||||
|
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()
|
||||||
|
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.
|
|||||||
|
self.assertTrue(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 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.
|
|||||||
|
def test_name_change_does_not_set_needs_price_update(self):
|
||||||
|
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 = Purchase.objects.create(
|
||||||
|
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.
|
|||||||
|
price=50.0,
|
||||||
|
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.
|
|||||||
|
price_currency="USD",
|
||||||
|
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.
|
|||||||
|
date_purchased=date(2025, 1, 1),
|
||||||
|
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.
|
|||||||
|
purchase.games.add(self.game)
|
||||||
|
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.converted_price = 1000
|
||||||
|
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.converted_currency = "CZK"
|
||||||
|
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.needs_price_update = False
|
||||||
|
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.save()
|
||||||
|
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.
|
|||||||
|
purchase.name = "New Name"
|
||||||
|
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.save()
|
||||||
|
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()
|
||||||
|
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.
|
|||||||
|
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 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.
|
|||||||
|
def test_convert_prices_skips_already_converted(self):
|
||||||
|
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 = Purchase.objects.create(
|
||||||
|
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.
|
|||||||
|
price=50.0,
|
||||||
|
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.
|
|||||||
|
price_currency="USD",
|
||||||
|
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.
|
|||||||
|
date_purchased=date(2025, 1, 1),
|
||||||
|
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.
|
|||||||
|
purchase.games.add(self.game)
|
||||||
|
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.converted_price = 1000
|
||||||
|
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.converted_currency = "CZK"
|
||||||
|
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.needs_price_update = False
|
||||||
|
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.save()
|
||||||
|
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()
|
||||||
|
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.
|
|||||||
|
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 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.
|
|||||||
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.
The raw SQL UPDATE in this migration could lock the table on large datasets. Consider chunked updates if the table grows significantly.