move CurrencyField to counter

This commit is contained in:
imperosol
2025-03-14 16:04:16 +01:00
committed by Thomas Girod
parent 6dfd4e16e2
commit 002554b802
11 changed files with 55 additions and 53 deletions

View File

@ -4,7 +4,7 @@ import django.core.validators
import django.db.models.deletion
from django.db import migrations, models
import accounting.models
import counter.fields
class Migration(migrations.Migration):
@ -142,7 +142,7 @@ class Migration(migrations.Migration):
),
(
"amount",
accounting.models.CurrencyField(
counter.fields.CurrencyField(
decimal_places=2,
default=0,
verbose_name="amount",
@ -151,7 +151,7 @@ class Migration(migrations.Migration):
),
(
"effective_amount",
accounting.models.CurrencyField(
counter.fields.CurrencyField(
decimal_places=2,
default=0,
verbose_name="effective_amount",
@ -176,7 +176,7 @@ class Migration(migrations.Migration):
("number", models.IntegerField(verbose_name="number")),
(
"amount",
accounting.models.CurrencyField(
counter.fields.CurrencyField(
decimal_places=2, max_digits=12, verbose_name="amount"
),
),

View File

@ -13,7 +13,6 @@
#
#
from decimal import Decimal
from django.conf import settings
from django.core import validators
@ -23,34 +22,7 @@ from phonenumber_field.modelfields import PhoneNumberField
from club.models import Club
from core.models import SithFile
class CurrencyField(models.DecimalField):
"""Custom database field used for currency."""
def __init__(self, *args, **kwargs):
kwargs["max_digits"] = 12
kwargs["decimal_places"] = 2
super().__init__(*args, **kwargs)
def to_python(self, value):
try:
return super().to_python(value).quantize(Decimal("0.01"))
except AttributeError:
return None
if settings.TESTING:
from model_bakery import baker
baker.generators.add(
CurrencyField,
lambda: baker.random_gen.gen_decimal(max_digits=8, decimal_places=2),
)
else: # pragma: no cover
# baker is only used in tests, so we don't need coverage for this part
pass
from counter.fields import CurrencyField
# Accounting classes