fix: Fix money decimal

This commit is contained in:
Setyo Nugroho 2022-11-21 22:12:27 +07:00
parent 505eadc6af
commit d80500f15f
3 changed files with 32 additions and 7 deletions

View file

@ -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:

View file

@ -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),
),
]

View file

@ -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):