fix
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
from .celery import app as celery_app
|
||||||
|
|
||||||
|
__all__ = ['celery_app']
|
||||||
@@ -1 +1,2 @@
|
|||||||
from .order import *
|
from .order import *
|
||||||
|
from .supplier import *
|
||||||
6
core/apps/orders/admin/supplier.py
Normal file
6
core/apps/orders/admin/supplier.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from core.apps.orders.models import Supplier
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Supplier)
|
||||||
28
core/apps/orders/migrations/0007_supplier.py
Normal file
28
core/apps/orders/migrations/0007_supplier.py
Normal 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',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1 +1,2 @@
|
|||||||
from .order import *
|
from .order import *
|
||||||
|
from .supplier import *
|
||||||
16
core/apps/orders/models/supplier.py
Normal file
16
core/apps/orders/models/supplier.py
Normal 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'
|
||||||
@@ -26,7 +26,7 @@ class OrderCreateSerializer(serializers.Serializer):
|
|||||||
payment_type = serializers.ChoiceField(choices=Order.PAYMENT_TYPE)
|
payment_type = serializers.ChoiceField(choices=Order.PAYMENT_TYPE)
|
||||||
delivery_type = serializers.ChoiceField(choices=Order.DELIVERY_TYPE)
|
delivery_type = serializers.ChoiceField(choices=Order.DELIVERY_TYPE)
|
||||||
delivery_price = serializers.IntegerField(required=False)
|
delivery_price = serializers.IntegerField(required=False)
|
||||||
contact_number = serializers.IntegerField()
|
contact_number = serializers.CharField()
|
||||||
address = serializers.CharField()
|
address = serializers.CharField()
|
||||||
comment = serializers.CharField(required=False)
|
comment = serializers.CharField(required=False)
|
||||||
name = serializers.CharField(required=False)
|
name = serializers.CharField(required=False)
|
||||||
@@ -59,7 +59,13 @@ class OrderCreateSerializer(serializers.Serializer):
|
|||||||
chat_id=item.get('product').tg_id,
|
chat_id=item.get('product').tg_id,
|
||||||
product_name=item.get('product').name,
|
product_name=item.get('product').name,
|
||||||
quantity=item.get('quantity'),
|
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)
|
OrderItem.objects.bulk_create(items)
|
||||||
|
|||||||
@@ -7,12 +7,24 @@ from config.env import env
|
|||||||
token = env.str("BOT_TOKEN")
|
token = env.str("BOT_TOKEN")
|
||||||
|
|
||||||
@shared_task
|
@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"
|
url = f"https://api.telegram.org/bot{token}/sendMessage"
|
||||||
message = (
|
message = (
|
||||||
f"Mahsulot nomi: {product_name}\n"
|
f"📦 Mahsulot nomi: {product_name}\n"
|
||||||
f"Mahsulot soni: {quantity}\n"
|
f"🔢 Mahsulot soni: {quantity}\n"
|
||||||
f"Summa: {price}"
|
f"💰 Summa: {price}\n\n"
|
||||||
|
|
||||||
|
f"📞 Aloqa uchun: (99) 099-91-92"
|
||||||
)
|
)
|
||||||
payload = {
|
payload = {
|
||||||
"chat_id": chat_id,
|
"chat_id": chat_id,
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from core.apps.orders.views import order as order_views
|
from core.apps.orders.views import order as order_views
|
||||||
|
from core.apps.orders.views import supplier as supp_views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('order/create/', order_views.OrderCreateApiView.as_view()),
|
path('order/create/', order_views.OrderCreateApiView.as_view()),
|
||||||
path('order/list/', order_views.OrderListApiView.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()),
|
||||||
]
|
]
|
||||||
28
core/apps/orders/views/supplier.py
Normal file
28
core/apps/orders/views/supplier.py
Normal 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)
|
||||||
|
|
||||||
@@ -64,5 +64,5 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- horeca
|
- horeca
|
||||||
environment:
|
environment:
|
||||||
- CELERY_BROKER_URL=redis://redis:6379
|
- CELERY_BROKER_URL=redis://redis:6379/0
|
||||||
- CELERY_RESULT_BACKEND=redis://redis:6379
|
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
||||||
Reference in New Issue
Block a user