change order list serialzier class
This commit is contained in:
@@ -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']
|
||||
|
||||
@@ -7,4 +7,4 @@ class OrdersConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
from . import admin
|
||||
|
||||
from . import signals
|
||||
18
core/apps/orders/migrations/0021_party_currency.py
Normal file
18
core/apps/orders/migrations/0021_party_currency.py
Normal 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),
|
||||
),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
1
core/apps/orders/signals/__init__.py
Normal file
1
core/apps/orders/signals/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .party import *
|
||||
36
core/apps/orders/signals/party.py
Normal file
36
core/apps/orders/signals/party.py
Normal 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"])
|
||||
@@ -1 +1,2 @@
|
||||
from .region import *
|
||||
from .region import *
|
||||
from .usd_course import *
|
||||
23
core/apps/shared/admin/usd_course.py
Normal file
23
core/apps/shared/admin/usd_course.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.contrib import admin
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import reverse
|
||||
|
||||
from core.apps.shared.models import UsdCourse
|
||||
|
||||
|
||||
@admin.register(UsdCourse)
|
||||
class UsdCourseAdmin(admin.ModelAdmin):
|
||||
def has_add_permission(self, request):
|
||||
return not UsdCourse.objects.exists()
|
||||
|
||||
def has_delete_permission(self, request, obj = ...):
|
||||
return False
|
||||
|
||||
def changelist_view(self, request, extra_context=None):
|
||||
config, created = UsdCourse.objects.get_or_create(
|
||||
defaults=dict(
|
||||
value=0
|
||||
)
|
||||
)
|
||||
url = reverse("admin:shared_usdcourse_change", args=[config.id])
|
||||
return HttpResponseRedirect(url)
|
||||
27
core/apps/shared/migrations/0002_usdcourse.py
Normal file
27
core/apps/shared/migrations/0002_usdcourse.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 5.2.4 on 2025-08-23 11:35
|
||||
|
||||
import uuid
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('shared', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='UsdCourse',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('value', models.PositiveBigIntegerField()),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'dollar kursi',
|
||||
'verbose_name_plural': 'dollar kursi',
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -1,2 +1,3 @@
|
||||
from .base import BaseModel
|
||||
from .region import *
|
||||
from .region import *
|
||||
from .usd_course import *
|
||||
12
core/apps/shared/models/usd_course.py
Normal file
12
core/apps/shared/models/usd_course.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from django.db import models
|
||||
|
||||
from core.apps.shared.models import BaseModel
|
||||
|
||||
|
||||
class UsdCourse(BaseModel):
|
||||
value = models.PositiveBigIntegerField()
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'dollar kursi'
|
||||
verbose_name_plural = 'dollar kursi'
|
||||
|
||||
Reference in New Issue
Block a user