add new field to order
This commit is contained in:
80
core/apps/orders/filters/party.py
Normal file
80
core/apps/orders/filters/party.py
Normal file
@@ -0,0 +1,80 @@
|
||||
from calendar import monthrange
|
||||
|
||||
from django.utils.timezone import timedelta, now
|
||||
|
||||
import django_filters
|
||||
|
||||
from core.apps.orders.models import Party
|
||||
|
||||
|
||||
class PartyFilter(django_filters.FilterSet):
|
||||
DATE_CHOICES = (
|
||||
('today', 'bugun'),
|
||||
('last_week', 'oxirgi hafta'),
|
||||
('last_month', 'oxirgi oy'),
|
||||
('last_year', 'oirgi yil'),
|
||||
|
||||
)
|
||||
delivery_date = django_filters.ChoiceFilter(
|
||||
choices=DATE_CHOICES, method='filter_by_deliveyer_date'
|
||||
)
|
||||
start_date = django_filters.DateFilter(field_name="delivery_date", lookup_expr="gte")
|
||||
end_date = django_filters.DateFilter(field_name="delivery_date", lookup_expr="lte")
|
||||
|
||||
payment_date = django_filters.ChoiceFilter(
|
||||
choices=DATE_CHOICES, method='filter_by_payment_date'
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Party
|
||||
fields = [
|
||||
'delivery_date', 'start_date', 'end_date',
|
||||
]
|
||||
|
||||
def filter_by_delivery_date(self, queryset, name, value):
|
||||
today = now().date()
|
||||
|
||||
if value == 'today':
|
||||
return queryset.filter(delivery_date=today)
|
||||
|
||||
elif value == 'last_week':
|
||||
start_date = today - timedelta(days=today.weekday() + 7)
|
||||
end_date = start_date + timedelta(days=6)
|
||||
return queryset.filter(delivery_date__range=(start_date, end_date))
|
||||
|
||||
elif value == 'last_year':
|
||||
if today.month == 1:
|
||||
last_month_year = today.year - 1
|
||||
last_month = 12
|
||||
else:
|
||||
last_month_year = today.year
|
||||
last_month = today.moth - 1
|
||||
|
||||
start_last_month = today.replace(year=last_month_year, month=last_month, day=1)
|
||||
days_in_last_month = monthrange(last_month_year, last_month)[1]
|
||||
end_last_month = start_last_month.replace(day=days_in_last_month)
|
||||
|
||||
return queryset.filter(delivery_date__range=(start_last_month, end_last_month))
|
||||
|
||||
elif value == 'last_year':
|
||||
start_year = today.replace(year=today.year - 1, month=1, day=1)
|
||||
end_year = today.replace(year=today.year - 1, month=12, day=31)
|
||||
return queryset.filter(delivery_date__range=(start_year, end_year))
|
||||
return queryset
|
||||
|
||||
def filter_by_payment_date(self, queryset, name, value):
|
||||
today = now().date()
|
||||
|
||||
if value == 'today':
|
||||
return queryset.filter(payment_date=today)
|
||||
elif value == 'last_week':
|
||||
start_date = today - timedelta(days=today.weekday() + 7)
|
||||
end_date = start_date + timedelta(days=6)
|
||||
return queryset.filter(payment_date__range=(start_date, end_date))
|
||||
elif value == 'last_month':
|
||||
...
|
||||
elif value == 'last_year':
|
||||
...
|
||||
return queryset
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Generated by Django 5.2.4 on 2025-08-22 10:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('orders', '0012_party_discount_party_qqs_price'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='order',
|
||||
name='qqs_price',
|
||||
field=models.PositiveBigIntegerField(blank=True, default=0, null=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='party',
|
||||
name='payment_percentage',
|
||||
field=models.FloatField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='party',
|
||||
name='payment_status',
|
||||
field=models.CharField(choices=[('PAID', "to'langan"), ('PARTIALLY', 'qisman'), ('NOT_PAID', "to'lanmagan"), ('OVERPAID', "ortiqcha to'langan")], default='NOT_PAID', max_length=20),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='party',
|
||||
name='status',
|
||||
field=models.CharField(choices=[('NEW', 'yangi'), ('PARTY_IS_MADE', 'partiya qilingan'), ('EXPECTED', 'kutilmoqda'), ('DRAFT', 'qoralama'), ('CANCELLED', 'bekor qilingan'), ('PURCHASED', 'sotib olinmoqda'), ('PROCESS', 'jarayonda')], default='NEW', max_length=20),
|
||||
),
|
||||
]
|
||||
@@ -43,6 +43,7 @@ class Order(BaseModel):
|
||||
choices=[('uzs', 'uzs'), ('usd', 'usd')], default='uzs', null=True, blank=True, max_length=3
|
||||
)
|
||||
total_price = models.PositiveBigIntegerField(default=0, null=True, blank=True)
|
||||
qqs_price = models.PositiveBigIntegerField(default=0, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.product} {self.unity} quantity order"
|
||||
|
||||
@@ -6,6 +6,22 @@ from core.apps.accounts.models import User
|
||||
|
||||
|
||||
class Party(BaseModel):
|
||||
STATUS = [
|
||||
('NEW', 'yangi'),
|
||||
('PARTY_IS_MADE', 'partiya qilingan'),
|
||||
("EXPECTED", 'kutilmoqda'),
|
||||
('DRAFT', 'qoralama'),
|
||||
('CANCELLED', 'bekor qilingan'),
|
||||
('PURCHASED', 'sotib olinmoqda'),
|
||||
('PROCESS', 'jarayonda'),
|
||||
]
|
||||
PAYMENT_STATUS = (
|
||||
('PAID', "to'langan"),
|
||||
('PARTIALLY', 'qisman'),
|
||||
('NOT_PAID', "to'lanmagan"),
|
||||
('OVERPAID', "ortiqcha to'langan"),
|
||||
)
|
||||
|
||||
number = models.PositiveIntegerField(default=1)
|
||||
orders = models.ManyToManyField(Order, related_name='parties', null=True, blank=True)
|
||||
mediator = models.ForeignKey(User, on_delete=models.CASCADE, related_name='parties')
|
||||
@@ -14,14 +30,13 @@ class Party(BaseModel):
|
||||
closed_date = models.DateField(null=True, blank=True)
|
||||
order_date = models.DateField(auto_now_add=True)
|
||||
payment_date = models.DateField()
|
||||
|
||||
status = models.CharField(
|
||||
max_length=20, choices=[('ORDERED', 'yetkazildi'), ('PROCESS', 'jarayonda')],
|
||||
null=True, blank=True
|
||||
)
|
||||
payment_status = models.FloatField(null=True, blank=True)
|
||||
process = models.FloatField(null=True, blank=True)
|
||||
# choices
|
||||
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.BooleanField(default=False)
|
||||
# percentages
|
||||
payment_percentage = models.FloatField(null=True, blank=True)
|
||||
process = models.FloatField(null=True, blank=True)
|
||||
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
audit = models.CharField(
|
||||
|
||||
@@ -129,6 +129,8 @@ class MultipleOrderAddSerializer(serializers.Serializer):
|
||||
currency = serializers.ChoiceField(choices=[('uzs', 'uzs'), ('usd', 'usd')])
|
||||
amount = serializers.IntegerField()
|
||||
date = serializers.DateField()
|
||||
total_price = serializers.IntegerField(requird=False)
|
||||
qqs_summa = serializers.IntegerField(required=False)
|
||||
|
||||
def validate(self, data):
|
||||
product = Product.objects.filter(id=data['product_id']).first()
|
||||
|
||||
@@ -46,6 +46,8 @@ class PartyCreateSerializer(serializers.Serializer):
|
||||
total_price=resource.get('amount'),
|
||||
date=resource.get('date'),
|
||||
employee=self.context.get('user'),
|
||||
qqs_price=resource.get('qqs_price'),
|
||||
total_price=resource.get('total_price'),
|
||||
))
|
||||
total_price += resource.get('amount')
|
||||
created_orders = Order.objects.bulk_create(orders)
|
||||
|
||||
Reference in New Issue
Block a user