feat: Add Telegram chat ID to ShopModel for automatic invoice sending

chore: Update Dockerfile to install WeasyPrint dependencies

feat: Enhance ShopOrderModelAdmin with invoice download buttons

feat: Implement invoice generation for OrderModel and ShopOrderModel

feat: Send invoice to shop's Telegram chat upon ShopOrderModel creation

feat: Create Celery task to send shop order invoice via Telegram

feat: Add invoice download endpoints for OrderModel and ShopOrderModel

feat: Implement views for downloading order and shop order invoices

chore: Update requirements.txt to include necessary packages for PDF generation

feat: Create HTML templates for order and shop order invoices
This commit is contained in:
Parsa Nazer
2025-12-28 11:43:33 +03:30
parent 6a7e526f23
commit 34715994ce
12 changed files with 1168 additions and 5 deletions
+36 -1
View File
@@ -6,7 +6,8 @@ from django.dispatch import receiver
from .models import OrderModel
from account.models import PushSubscription, UserAddressModel
import ghasedak_sms
from .tasks import send_change_status_notif, send_change_status_sms
from .tasks import send_change_status_notif, send_change_status_sms, send_shop_order_invoice_telegram_task
from django.conf import settings
@receiver(pre_save, sender=OrderModel)
@@ -180,3 +181,37 @@ def create_shop_orders_on_payment(sender, instance: OrderModel, created, **kwarg
special_discount_amount=int(
it.special_discount_amount or 0),
)
@receiver(post_save, sender=ShopOrderModel)
def send_invoice_to_shop_telegram(sender, instance: ShopOrderModel, created, **kwargs):
"""Automatically send invoice to shop's Telegram chat when ShopOrderModel is created.
This handler triggers when a new ShopOrderModel is created and the shop has a telegram_chat_id configured.
It sends the invoice PDF asynchronously via Celery task.
"""
if not created:
return
# Check if shop has telegram_chat_id configured
if not instance.shop or not instance.shop.telegram_chat_id:
return
# Get bot token from settings
bot_token = getattr(settings, 'TELEGRAM_BOT_TOKEN', None)
if not bot_token:
return
# Send invoice asynchronously
try:
send_shop_order_invoice_telegram_task.delay(
shop_order_id=instance.pk,
chat_id=instance.shop.telegram_chat_id,
bot_token=bot_token
)
except Exception as e:
send_shop_order_invoice_telegram_task(
shop_order_id=instance.pk,
chat_id=instance.shop.telegram_chat_id,
bot_token=bot_token
)