-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
623f574
commit 80f3085
Showing
7 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from apps.banking.admin.currency_rate import CurrencyRateAdmin | ||
|
||
__all__ = [ | ||
"CurrencyRateAdmin", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.contrib.admin.models import CHANGE, LogEntry | ||
from django.http import HttpRequest | ||
from traitlets import Any | ||
|
||
from apps.banking.models import CurrencyRate | ||
from core.admin import ModelAdmin, admin | ||
from core.tasks import write_admin_log | ||
|
||
|
||
@admin.register(CurrencyRate) | ||
class CurrencyRateAdmin(ModelAdmin): | ||
list_display = ["name", "rate"] | ||
|
||
def get_object(self, request: HttpRequest, object_id: str, from_field: str | None = None) -> CurrencyRate | None: | ||
obj = super().get_object(request, object_id, from_field) | ||
if obj: | ||
obj.__original_rate = obj.rate | ||
return obj | ||
|
||
def log_change(self, request: HttpRequest, obj: CurrencyRate, message: Any) -> LogEntry: | ||
if obj.rate != obj.__original_rate: # type: ignore[attr-defined] | ||
return write_admin_log( | ||
action_flag=CHANGE, | ||
app="banking", | ||
change_message=f"Currency rate was changed from {obj.__original_rate} to {obj.rate}", # type: ignore[attr-defined] | ||
model="CurrencyRate", | ||
object_id=obj.id, | ||
user_id=request.user.id, | ||
) | ||
else: | ||
return super().log_change(request, obj, message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 4.2.17 on 2024-12-24 10:08 | ||
|
||
from django.db import migrations, models | ||
|
||
import core.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
("banking", "0002_drop_recipient_model"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="CurrencyRate", | ||
fields=[ | ||
("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("name", models.CharField(help_text="Currency name in ISO 4217 format. E.g. USD", max_length=4, unique=True)), | ||
("rate", models.DecimalField(decimal_places=2, max_digits=6, verbose_name="Rate")), | ||
], | ||
options={ | ||
"verbose_name": "Currency", | ||
"verbose_name_plural": "Currencies", | ||
}, | ||
bases=(core.models.TestUtilsMixin, models.Model), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from django.db import models | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from core.models import DefaultModel | ||
|
||
|
||
class CurrencyRate(DefaultModel): | ||
name = models.CharField(max_length=4, unique=True, help_text=_("Currency name in ISO 4217 format. E.g. USD")) | ||
rate = models.DecimalField(max_digits=6, decimal_places=2, verbose_name=_("Rate")) | ||
|
||
class Meta: | ||
verbose_name = _("Currency") | ||
verbose_name_plural = _("Currencies") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.17 on 2024-12-24 11:29 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("orders", "0038_alter_order_bank_id_alter_refund_bank_id"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="order", | ||
name="ue_rate", | ||
field=models.DecimalField(decimal_places=2, max_digits=6, verbose_name="Purchase-time UE rate"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters