🗃 Make order sum a decimal field
This commit is contained in:
1 parent
0726754678
commit
19f58211e7
4 files changed
+26
-4
No files matched your search
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
from decimal import Decimal
|
||||
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
@@ -25,7 +26,7 @@ class UserProfile:
|
||||
balance: auto
|
||||
image: auto
|
||||
last_purchase_date: datetime
|
||||
order_sum_total: float
|
||||
order_sum_total: Decimal
|
||||
|
||||
@strawberry.field()
|
||||
def top_months(self) -> List[TopMonth]:
|
||||
|
||||
+3
-1
@@ -2,9 +2,11 @@ from django import forms
|
||||
|
||||
from bbs.models import InventoryTransaction, Product
|
||||
|
||||
MAX_DIGITS = 9
|
||||
DECIMAL_PLACES = 1
|
||||
|
||||
class InventoryTransactionForm(forms.ModelForm):
|
||||
unit_price = forms.FloatField(required=True, localize=True)
|
||||
unit_price = forms.DecimalField(max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES, required=True, localize=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Only show active products
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.0.2 on 2023-06-28 19:11
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('bbs', '0002_alter_inventorytransaction_amount_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='order',
|
||||
name='order_sum',
|
||||
field=models.DecimalField(db_column='sum', decimal_places=1, max_digits=9),
|
||||
),
|
||||
]
|
||||
+3
-2
@@ -2,6 +2,7 @@ import hashlib
|
||||
from datetime import datetime
|
||||
from itertools import groupby
|
||||
from typing import Type
|
||||
from decimal import Decimal
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
@@ -112,7 +113,7 @@ class Order(models.Model):
|
||||
blank=True,
|
||||
related_name="orders",
|
||||
)
|
||||
order_sum = models.FloatField(db_column="sum")
|
||||
order_sum = models.DecimalField(db_column="sum", max_digits=MAX_DIGITS, decimal_places=DECIMAL_PLACES)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
objects = OrderManager()
|
||||
@@ -234,7 +235,7 @@ class UserProfile(models.Model):
|
||||
def product_order_stats(self):
|
||||
return OrderLine.objects.filter(order__customer__pk=self.pk).product_order_stats()
|
||||
|
||||
def order_sum_total(self) -> float:
|
||||
def order_sum_total(self) -> Decimal:
|
||||
return Order.objects.filter(customer_id=self.user_id).aggregate(sum=Sum("order_sum"))["sum"] or 0
|
||||
|
||||
def image_url(self) -> str:
|
||||
|
||||
Reference in new issue
Block a user