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:
+35
-2
@@ -12,6 +12,8 @@ from azbankgateways.models.banks import Bank
|
||||
from unfold.decorators import action
|
||||
from django.shortcuts import redirect
|
||||
from .permissons import ShopOrderAdminPermission
|
||||
from django.urls import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
class OrderItemModelInline(StackedInline):
|
||||
model = OrderItemModel
|
||||
@@ -97,6 +99,22 @@ class ShopOrderItemInline(StackedInline):
|
||||
@admin.register(ShopOrderModel)
|
||||
class ShopOrderModelAdmin(ShopOrderAdminPermission, ModelAdmin):
|
||||
inlines = [ShopOrderItemInline]
|
||||
list_display = ['id', 'shop', 'order', 'customer_name', 'status', 'is_paid', 'is_settled', 'download_invoice_button']
|
||||
readonly_fields = ['download_invoice_link']
|
||||
|
||||
def download_invoice_button(self, obj):
|
||||
if obj.pk:
|
||||
url = reverse('download-shop-order-invoice', args=[obj.pk])
|
||||
return mark_safe(f'<a class="button" href="{url}" target="_blank" style="background-color: #28a745; color: white; border-color: #28a745;">دانلود فاکتور</a>')
|
||||
return '-'
|
||||
download_invoice_button.short_description = 'فاکتور'
|
||||
|
||||
def download_invoice_link(self, obj):
|
||||
if obj.pk:
|
||||
url = reverse('download-shop-order-invoice', args=[obj.pk])
|
||||
return mark_safe(f'<a href="{url}" target="_blank" style="background-color: #28a745; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; display: inline-block;">دانلود فاکتور PDF</a>')
|
||||
return '-'
|
||||
download_invoice_link.short_description = 'دانلود فاکتور'
|
||||
|
||||
|
||||
def get_queryset(self, request):
|
||||
@@ -118,8 +136,8 @@ class OrderAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
search_fields = ['user__phone', 'user__first_name', 'user__last_name', 'user__email']
|
||||
list_filter = ['is_paid', 'status']
|
||||
actions_list = ['redirect_to_learn', 'udpate_bank_status']
|
||||
list_display = ['order_id', 'user', 'is_paid', 'status', 'discount_code', 'address',]
|
||||
readonly_fields = ('created_at', 'tax', 'final_price', 'cart_total', 'discount_amount', 'discount_code', 'user', 'address', 'is_paid')
|
||||
list_display = ['order_id', 'user', 'is_paid', 'status', 'discount_code', 'address', 'download_invoice_button']
|
||||
readonly_fields = ('created_at', 'tax', 'final_price', 'cart_total', 'discount_amount', 'discount_code', 'user', 'address', 'is_paid', 'download_invoice_link')
|
||||
compressed_fields = True
|
||||
warn_unsaved_form = True
|
||||
# exclude = ('bank_records',)
|
||||
@@ -129,9 +147,24 @@ class OrderAdmin(ModelAdmin, ImportExportModelAdmin):
|
||||
}
|
||||
}
|
||||
inlines = [OrderItemModelInline, BankRecordInline]
|
||||
|
||||
def order_id(self, obj):
|
||||
return f"سفارش {obj.pk + 1000}"
|
||||
order_id.short_description = "شماره سفارش"
|
||||
|
||||
def download_invoice_button(self, obj):
|
||||
if obj.pk:
|
||||
url = reverse('download-order-invoice', args=[obj.pk])
|
||||
return mark_safe(f'<a class="button" href="{url}" target="_blank" style="background-color: #28a745; color: white; border-color: #28a745;">دانلود فاکتور</a>')
|
||||
return '-'
|
||||
download_invoice_button.short_description = 'فاکتور'
|
||||
|
||||
def download_invoice_link(self, obj):
|
||||
if obj.pk:
|
||||
url = reverse('download-order-invoice', args=[obj.pk])
|
||||
return mark_safe(f'<a href="{url}" target="_blank" style="background-color: #28a745; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; display: inline-block;">دانلود فاکتور PDF</a>')
|
||||
return '-'
|
||||
download_invoice_link.short_description = 'دانلود فاکتور'
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user