change order list serialzier class

This commit is contained in:
behruz-dev
2025-08-23 12:16:34 +05:00
parent 9a5508de81
commit 8e436233ef
12 changed files with 132 additions and 6 deletions

View File

@@ -5,5 +5,4 @@ from core.apps.orders.models import Order
@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
list_display = ['quantity', 'product', 'unity', 'project', 'wherehouse']
list_display = ['unity', 'project', 'wherehouse']
list_display = ['unity', 'project', 'wherehouse', 'currency']

View File

@@ -7,4 +7,4 @@ class OrdersConfig(AppConfig):
def ready(self):
from . import admin
from . import signals

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.2.4 on 2025-08-23 11:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('orders', '0020_party_discount_currency'),
]
operations = [
migrations.AddField(
model_name='party',
name='currency',
field=models.CharField(choices=[('usd', 'usd'), ('uzs', 'uzs')], default='uzs', max_length=3),
),
]

View File

@@ -39,6 +39,7 @@ class Party(BaseModel):
status = models.CharField(max_length=20, choices=STATUS, default='NEW')
payment_status = models.CharField(max_length=20, choices=PAYMENT_STATUS, default='NOT_PAID')
confirmation = models.CharField(max_length=20, choices=CONFIRMATION, default='EXPECTED')
currency = models.CharField(choices=[('usd', 'usd'), ('uzs', 'uzs')], max_length=3, default='uzs')
# percentages
payment_percentage = models.FloatField(null=True, blank=True)
process = models.FloatField(null=True, blank=True)

View File

@@ -92,12 +92,13 @@ class OrderListSerializer(serializers.ModelSerializer):
wherehouse = WhereHouseListSerializer()
project_folder = ProjectFolderListSerializer()
employee = serializers.SerializerMethodField(method_name='get_employee')
counterparty = serializers.SerializerMethodField(method_name='get_counterparty')
class Meta:
model = Order
fields = [
'id', 'product', 'unity', 'quantity', 'project', 'project_folder',
'wherehouse', 'date', 'status', 'employee'
'wherehouse', 'date', 'status', 'employee', 'counterparty'
]
def get_employee(self, obj):
@@ -107,6 +108,12 @@ class OrderListSerializer(serializers.ModelSerializer):
"phone_number": obj.employee.phone_number
} if obj.employee else None
def get_counterparty(self, obj):
return {
'id': obj.counterparty.id,
'name': obj.counterparty.name,
} if obj.counterparty else None
class OrderUpdateSerializer(serializers.ModelSerializer):
class Meta:

View File

@@ -0,0 +1 @@
from .party import *

View File

@@ -0,0 +1,36 @@
from django.db.models.signals import m2m_changed, post_save
from django.dispatch import receiver
from core.apps.orders.models.party import Party, PartyAmount
# @receiver(m2m_changed, sender=Party)
# def change_party_currency(sender, instance, action, **kwargs):
# currencies = set(instance.orders.values_list("currency", flat=True))
# print(instance.orders)
# for order in instance.orders.all():
# print(order.currency)
# print(currencies)
# if "usd" in currencies and "uzs" in currencies:
# instance.currency = "uzs"
# elif currencies == {"usd"}:
# instance.currency = "usd"
# elif currencies == {"uzs"}:
# instance.currency = "uzs"
# instance.save()
# @receiver(post_save, sender=Party)
# def change_party_currency(sender, instance, created, **kwargs):
# currencies = set()
# for order in instance.orders.all():
# currencies.add(order.currency)
# print(order.currency)
# if "usd" in currencies and "uzs" in currencies:
# instance.currency = "uzs"
# elif currencies == {"usd"}:
# instance.currency = "usd"
# elif currencies == {"uzs"}:
# instance.currency = "uzs"
# instance.save(update_fields=["currency"])