diff --git a/api/serializers.py b/api/serializers.py index e47aae4..8cf70c5 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -1,4 +1,5 @@ from djmoney.contrib.django_rest_framework import MoneyField +from djmoney.settings import DECIMAL_PLACES from rest_framework import serializers from api import custom_validator @@ -8,7 +9,7 @@ from core.component import component class InvoiceComponentSerializer(serializers.ModelSerializer): adjusted_end_date = serializers.DateTimeField() - price_charged = MoneyField(max_digits=10, decimal_places=0) + price_charged = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES) price_charged_currency = serializers.CharField(source="price_charged.currency") @@ -30,9 +31,9 @@ def generate_invoice_component_serializer(model): class InvoiceSerializer(serializers.ModelSerializer): - subtotal = MoneyField(max_digits=10, decimal_places=0) + subtotal = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES) subtotal_currency = serializers.CharField(source="subtotal.currency") - total = MoneyField(max_digits=10, decimal_places=0) + total = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES) total_currency = serializers.CharField(source="total.currency", required=False) def __init__(self, *args, **kwargs): @@ -46,9 +47,9 @@ class InvoiceSerializer(serializers.ModelSerializer): class SimpleInvoiceSerializer(serializers.ModelSerializer): - subtotal = MoneyField(max_digits=10, decimal_places=0) + subtotal = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES) subtotal_currency = serializers.CharField(source="subtotal.currency") - total = MoneyField(max_digits=10, decimal_places=0) + total = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES) total_currency = serializers.CharField(source="total.currency", required=False) class Meta: diff --git a/core/migrations/0012_auto_20221121_1511.py b/core/migrations/0012_auto_20221121_1511.py new file mode 100644 index 0000000..bf251b1 --- /dev/null +++ b/core/migrations/0012_auto_20221121_1511.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.6 on 2022-11-21 15:11 + +from django.db import migrations +import djmoney.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0011_auto_20221121_1505'), + ] + + operations = [ + migrations.AlterField( + model_name='invoice', + name='tax', + field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=10, null=True), + ), + migrations.AlterField( + model_name='invoice', + name='total', + field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=10, null=True), + ), + ] diff --git a/core/models.py b/core/models.py index 627f560..2bab5ba 100644 --- a/core/models.py +++ b/core/models.py @@ -84,8 +84,8 @@ class Invoice(BaseModel, TimestampMixin): end_date = models.DateTimeField(default=None, blank=True, null=True) finish_date = models.DateTimeField(default=None, blank=True, null=True) state = models.IntegerField(choices=InvoiceState.choices) - tax = MoneyField(max_digits=10, decimal_places=0, default=None, blank=True, null=True) - total = MoneyField(max_digits=10, decimal_places=0, default=None, blank=True, null=True) + tax = MoneyField(max_digits=10, default=None, blank=True, null=True) + total = MoneyField(max_digits=10, default=None, blank=True, null=True) @property def subtotal(self):