fix: Fix money max digit
This commit is contained in:
parent
acb95b379d
commit
be42c2fd9d
4 changed files with 178 additions and 23 deletions
|
@ -9,7 +9,7 @@ from core.component import component
|
||||||
|
|
||||||
class InvoiceComponentSerializer(serializers.ModelSerializer):
|
class InvoiceComponentSerializer(serializers.ModelSerializer):
|
||||||
adjusted_end_date = serializers.DateTimeField()
|
adjusted_end_date = serializers.DateTimeField()
|
||||||
price_charged = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES)
|
price_charged = MoneyField(max_digits=256, decimal_places=DECIMAL_PLACES)
|
||||||
price_charged_currency = serializers.CharField(source="price_charged.currency")
|
price_charged_currency = serializers.CharField(source="price_charged.currency")
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ def generate_invoice_component_serializer(model):
|
||||||
|
|
||||||
|
|
||||||
class InvoiceSerializer(serializers.ModelSerializer):
|
class InvoiceSerializer(serializers.ModelSerializer):
|
||||||
subtotal = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES)
|
subtotal = MoneyField(max_digits=256, decimal_places=DECIMAL_PLACES)
|
||||||
subtotal_currency = serializers.CharField(source="subtotal.currency")
|
subtotal_currency = serializers.CharField(source="subtotal.currency")
|
||||||
total = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES)
|
total = MoneyField(max_digits=256, decimal_places=DECIMAL_PLACES)
|
||||||
total_currency = serializers.CharField(source="total.currency", required=False)
|
total_currency = serializers.CharField(source="total.currency", required=False)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -47,9 +47,9 @@ class InvoiceSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class SimpleInvoiceSerializer(serializers.ModelSerializer):
|
class SimpleInvoiceSerializer(serializers.ModelSerializer):
|
||||||
subtotal = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES)
|
subtotal = MoneyField(max_digits=256, decimal_places=DECIMAL_PLACES)
|
||||||
subtotal_currency = serializers.CharField(source="subtotal.currency")
|
subtotal_currency = serializers.CharField(source="subtotal.currency")
|
||||||
total = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES)
|
total = MoneyField(max_digits=256, decimal_places=DECIMAL_PLACES)
|
||||||
total_currency = serializers.CharField(source="total.currency", required=False)
|
total_currency = serializers.CharField(source="total.currency", required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -79,7 +79,7 @@ class NotificationSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class BalanceSerializer(serializers.ModelSerializer):
|
class BalanceSerializer(serializers.ModelSerializer):
|
||||||
project = BillingProjectSerializer()
|
project = BillingProjectSerializer()
|
||||||
amount = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES)
|
amount = MoneyField(max_digits=256, decimal_places=DECIMAL_PLACES)
|
||||||
amount_currency = serializers.CharField(source="amount.currency")
|
amount_currency = serializers.CharField(source="amount.currency")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -88,7 +88,7 @@ class BalanceSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class BalanceTransactionSerializer(serializers.ModelSerializer):
|
class BalanceTransactionSerializer(serializers.ModelSerializer):
|
||||||
amount = MoneyField(max_digits=10, decimal_places=DECIMAL_PLACES)
|
amount = MoneyField(max_digits=256, decimal_places=DECIMAL_PLACES)
|
||||||
amount_currency = serializers.CharField(source="amount.currency")
|
amount_currency = serializers.CharField(source="amount.currency")
|
||||||
action = serializers.CharField(required=False)
|
action = serializers.CharField(required=False)
|
||||||
description = serializers.CharField()
|
description = serializers.CharField()
|
||||||
|
|
155
core/migrations/0014_auto_20230926_1515.py
Normal file
155
core/migrations/0014_auto_20230926_1515.py
Normal file
|
@ -0,0 +1,155 @@
|
||||||
|
# Generated by Django 3.2.6 on 2023-09-26 15:15
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
|
from django.db import migrations
|
||||||
|
import djmoney.models.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0013_balance_balancetransaction'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='balance',
|
||||||
|
name='amount',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, default=Decimal('0'), max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='balancetransaction',
|
||||||
|
name='amount',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='flavorprice',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='flavorprice',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='floatingipsprice',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='floatingipsprice',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='imageprice',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='imageprice',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoice',
|
||||||
|
name='tax',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoice',
|
||||||
|
name='total',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicefloatingip',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicefloatingip',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoiceimage',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoiceimage',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoiceinstance',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoiceinstance',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicerouter',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicerouter',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicesnapshot',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicesnapshot',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicevolume',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='invoicevolume',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='routerprice',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='routerprice',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='snapshotprice',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='snapshotprice',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='volumeprice',
|
||||||
|
name='hourly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(decimal_places=2, max_digits=256),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='volumeprice',
|
||||||
|
name='monthly_price',
|
||||||
|
field=djmoney.models.fields.MoneyField(blank=True, decimal_places=2, default=None, max_digits=256, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -18,7 +18,7 @@ from core.utils.model_utils import BaseModel, TimestampMixin, PriceMixin, Invoic
|
||||||
LOG = logging.getLogger("yuyu")
|
LOG = logging.getLogger("yuyu")
|
||||||
|
|
||||||
|
|
||||||
# region Dynamic Setting
|
#region Dynamic Setting
|
||||||
class DynamicSetting(BaseModel):
|
class DynamicSetting(BaseModel):
|
||||||
class DataType(models.IntegerChoices):
|
class DataType(models.IntegerChoices):
|
||||||
BOOLEAN = 1
|
BOOLEAN = 1
|
||||||
|
@ -31,9 +31,9 @@ class DynamicSetting(BaseModel):
|
||||||
type = models.IntegerField(choices=DataType.choices)
|
type = models.IntegerField(choices=DataType.choices)
|
||||||
|
|
||||||
|
|
||||||
# end region
|
#endregion
|
||||||
|
|
||||||
# region Pricing
|
#region Pricing
|
||||||
class FlavorPrice(BaseModel, TimestampMixin, PriceMixin):
|
class FlavorPrice(BaseModel, TimestampMixin, PriceMixin):
|
||||||
flavor_id = models.CharField(max_length=256, unique=True, blank=False)
|
flavor_id = models.CharField(max_length=256, unique=True, blank=False)
|
||||||
|
|
||||||
|
@ -62,9 +62,9 @@ class ImagePrice(BaseModel, TimestampMixin, PriceMixin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# end region
|
#endregion
|
||||||
|
|
||||||
# region Invoicing
|
#region Invoicing
|
||||||
class BillingProject(BaseModel, TimestampMixin):
|
class BillingProject(BaseModel, TimestampMixin):
|
||||||
tenant_id = models.CharField(max_length=256)
|
tenant_id = models.CharField(max_length=256)
|
||||||
email_notification = models.CharField(max_length=512, blank=True, null=True)
|
email_notification = models.CharField(max_length=512, blank=True, null=True)
|
||||||
|
@ -84,8 +84,8 @@ class Invoice(BaseModel, TimestampMixin):
|
||||||
end_date = models.DateTimeField(default=None, blank=True, null=True)
|
end_date = models.DateTimeField(default=None, blank=True, null=True)
|
||||||
finish_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)
|
state = models.IntegerField(choices=InvoiceState.choices)
|
||||||
tax = MoneyField(max_digits=10, default=None, blank=True, null=True)
|
tax = MoneyField(max_digits=256, default=None, blank=True, null=True)
|
||||||
total = MoneyField(max_digits=10, default=None, blank=True, null=True)
|
total = MoneyField(max_digits=256, default=None, blank=True, null=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subtotal(self):
|
def subtotal(self):
|
||||||
|
@ -172,9 +172,9 @@ class Invoice(BaseModel, TimestampMixin):
|
||||||
return sum(map(lambda x: x.price_charged, relation_all_row))
|
return sum(map(lambda x: x.price_charged, relation_all_row))
|
||||||
|
|
||||||
|
|
||||||
# end region
|
#endregion
|
||||||
|
|
||||||
# region Invoice Component
|
#region Invoice Component
|
||||||
class InvoiceInstance(BaseModel, InvoiceComponentMixin):
|
class InvoiceInstance(BaseModel, InvoiceComponentMixin):
|
||||||
invoice = models.ForeignKey('Invoice', on_delete=models.CASCADE, related_name=labels.LABEL_INSTANCES)
|
invoice = models.ForeignKey('Invoice', on_delete=models.CASCADE, related_name=labels.LABEL_INSTANCES)
|
||||||
# Key
|
# Key
|
||||||
|
@ -257,7 +257,7 @@ class InvoiceImage(BaseModel, InvoiceComponentMixin):
|
||||||
return price_without_allocation * math.ceil(self.space_allocation_gb)
|
return price_without_allocation * math.ceil(self.space_allocation_gb)
|
||||||
|
|
||||||
|
|
||||||
# end region
|
#endregion
|
||||||
|
|
||||||
class Notification(BaseModel, TimestampMixin):
|
class Notification(BaseModel, TimestampMixin):
|
||||||
project = models.ForeignKey('BillingProject', on_delete=models.CASCADE, blank=True, null=True)
|
project = models.ForeignKey('BillingProject', on_delete=models.CASCADE, blank=True, null=True)
|
||||||
|
@ -300,10 +300,10 @@ class Notification(BaseModel, TimestampMixin):
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
||||||
# region balance
|
#region balance
|
||||||
class Balance(BaseModel, TimestampMixin):
|
class Balance(BaseModel, TimestampMixin):
|
||||||
project = models.ForeignKey('BillingProject', on_delete=models.CASCADE)
|
project = models.ForeignKey('BillingProject', on_delete=models.CASCADE)
|
||||||
amount = MoneyField(max_digits=10, default=0)
|
amount = MoneyField(max_digits=256, default=0)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_balance_for_project(cls, project):
|
def get_balance_for_project(cls, project):
|
||||||
|
@ -349,8 +349,8 @@ class BalanceTransaction(BaseModel, TimestampMixin):
|
||||||
TOP_DOWN = "top_down"
|
TOP_DOWN = "top_down"
|
||||||
|
|
||||||
balance = models.ForeignKey('Balance', on_delete=models.CASCADE, blank=True, null=True)
|
balance = models.ForeignKey('Balance', on_delete=models.CASCADE, blank=True, null=True)
|
||||||
amount = MoneyField(max_digits=10)
|
amount = MoneyField(max_digits=256)
|
||||||
action = models.CharField(choices=ActionType.choices, max_length=256)
|
action = models.CharField(choices=ActionType.choices, max_length=256)
|
||||||
description = models.CharField(max_length=256)
|
description = models.CharField(max_length=256)
|
||||||
|
|
||||||
# end region
|
#endregion
|
||||||
|
|
|
@ -19,8 +19,8 @@ class TimestampMixin(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class PriceMixin(models.Model):
|
class PriceMixin(models.Model):
|
||||||
hourly_price = MoneyField(max_digits=10)
|
hourly_price = MoneyField(max_digits=256)
|
||||||
monthly_price = MoneyField(max_digits=10, default=None, blank=True, null=True)
|
monthly_price = MoneyField(max_digits=256, default=None, blank=True, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
Loading…
Add table
Reference in a new issue