This commit is contained in:
behruz-dev
2025-09-04 18:33:56 +05:00
parent a56a62acfa
commit fdf0c9808b
11 changed files with 115 additions and 11 deletions

View File

@@ -1 +1,2 @@
from .order import *
from .order import *
from .supplier import *

View File

@@ -0,0 +1,6 @@
from django.contrib import admin
from core.apps.orders.models import Supplier
admin.site.register(Supplier)

View File

@@ -0,0 +1,28 @@
# Generated by Django 5.2 on 2025-09-04 18:27
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('orders', '0006_remove_order_status'),
]
operations = [
migrations.CreateModel(
name='Supplier',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('phone', models.CharField(max_length=20)),
('full_name', models.CharField(max_length=50)),
('tg_id', models.CharField(max_length=200)),
],
options={
'verbose_name': 'yetkazib beruvchi',
'verbose_name_plural': 'yetkazib beruvchilar',
},
),
]

View File

@@ -1 +1,2 @@
from .order import *
from .order import *
from .supplier import *

View File

@@ -0,0 +1,16 @@
from django.db import models
from core.apps.shared.models import BaseModel
class Supplier(BaseModel):
phone = models.CharField(max_length=20)
full_name = models.CharField(max_length=50)
tg_id = models.CharField(max_length=200)
def __str__(self):
return self.full_name
class Meta:
verbose_name = 'yetkazib beruvchi'
verbose_name_plural = 'yetkazib beruvchilar'

View File

@@ -26,7 +26,7 @@ class OrderCreateSerializer(serializers.Serializer):
payment_type = serializers.ChoiceField(choices=Order.PAYMENT_TYPE)
delivery_type = serializers.ChoiceField(choices=Order.DELIVERY_TYPE)
delivery_price = serializers.IntegerField(required=False)
contact_number = serializers.IntegerField()
contact_number = serializers.CharField()
address = serializers.CharField()
comment = serializers.CharField(required=False)
name = serializers.CharField(required=False)
@@ -59,9 +59,15 @@ class OrderCreateSerializer(serializers.Serializer):
chat_id=item.get('product').tg_id,
product_name=item.get('product').name,
quantity=item.get('quantity'),
price=item.get('price')
price=item.get('price'),
payment_type=validated_data.get('payment_type'),
delivery_type=validated_data.get('delivery_type'),
contact_number=validated_data.get('contact_number'),
address=validated_data.get('address'),
comment=validated_data.get('comment'),
name=validated_data.get('name')
)
OrderItem.objects.bulk_create(items)
order.total_price = total_price
order.save()

View File

@@ -7,12 +7,24 @@ from config.env import env
token = env.str("BOT_TOKEN")
@shared_task
def send_orders_to_tg_bot(chat_id, product_name, quantity, price):
def send_orders_to_tg_bot(
chat_id, product_name, quantity, price, payment_type,
delivery_type, contact_number, address, comment, name
):
if payment_type == 'CASH':
payment_type = "Naqd to'lov"
elif payment_type == 'CARD':
payment_type = "Karta orqali to'lov"
elif payment_type == 'ACCOUNT_NUMBER':
payment_type = "Hisob raqam orqali to'lov"
url = f"https://api.telegram.org/bot{token}/sendMessage"
message = (
f"Mahsulot nomi: {product_name}\n"
f"Mahsulot soni: {quantity}\n"
f"Summa: {price}"
f"📦 Mahsulot nomi: {product_name}\n"
f"🔢 Mahsulot soni: {quantity}\n"
f"💰 Summa: {price}\n\n"
f"📞 Aloqa uchun: (99) 099-91-92"
)
payload = {
"chat_id": chat_id,

View File

@@ -1,8 +1,11 @@
from django.urls import path, include
from core.apps.orders.views import order as order_views
from core.apps.orders.views import supplier as supp_views
urlpatterns = [
path('order/create/', order_views.OrderCreateApiView.as_view()),
path('order/list/', order_views.OrderListApiView.as_view()),
path('supplier/create/', supp_views.SupplierCreateApiView.as_view()),
path('supplier/<str:tg_id>/', supp_views.SupplierGetApiView.as_view()),
]

View File

@@ -0,0 +1,28 @@
from rest_framework import views
from rest_framework.response import Response
from core.apps.orders.models import Supplier
class SupplierCreateApiView(views.APIView):
def post(self, request):
data = request.data
phone = data.get('phone')
full_name = data.get('full_name')
tg_id = data.get('tg_id')
Supplier.objects.create(
phone=phone,
full_name=full_name,
tg_id=tg_id
)
return Response({'success': True, 'message': 'created'}, status=200)
class SupplierGetApiView(views.APIView):
def get(self, request, tg_id):
supp = Supplier.objects.filter(tg_id=tg_id).first()
if supp:
return Response({'success': True}, status=200)
else:
return Response({"success": False},status=404)