diff --git a/osinaweb/billing/__pycache__/urls.cpython-310.pyc b/osinaweb/billing/__pycache__/urls.cpython-310.pyc index 4897b3ec..f1898f91 100644 Binary files a/osinaweb/billing/__pycache__/urls.cpython-310.pyc and b/osinaweb/billing/__pycache__/urls.cpython-310.pyc differ diff --git a/osinaweb/billing/__pycache__/views.cpython-310.pyc b/osinaweb/billing/__pycache__/views.cpython-310.pyc index ede15e76..e0ac4cb8 100644 Binary files a/osinaweb/billing/__pycache__/views.cpython-310.pyc and b/osinaweb/billing/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/billing/urls.py b/osinaweb/billing/urls.py index 44891bcc..2565e7b6 100644 --- a/osinaweb/billing/urls.py +++ b/osinaweb/billing/urls.py @@ -8,7 +8,7 @@ from billing import views urlpatterns = [ - path('check', views.create_charges_for_recurring_services, name='check'), + # LISTING path('items', views.items, name='items'), @@ -28,4 +28,9 @@ urlpatterns = [ path('invoice-details//', views.invoice_details, name='invoicedetails'), + path('generate-pdf/', views.generate_pdf, name='generate-pdf'), + + + + ] diff --git a/osinaweb/billing/views.py b/osinaweb/billing/views.py index 518dcc22..468230f9 100644 --- a/osinaweb/billing/views.py +++ b/osinaweb/billing/views.py @@ -3,27 +3,9 @@ from django.utils import timezone from datetime import timedelta from .models import * from django.http import JsonResponse - - -def create_charges_for_recurring_services(request): - today = timezone.now().date() - active_recurring_services = Service.objects.filter(active=True, recurring=True) - - for service in active_recurring_services: - # Get the last charge for the service - last_charge = service.charge_set.order_by('-due_date').first() - - if last_charge and last_charge.due_date <= today: - # Calculate the new due date for the charge based on the recurring cycle - new_due_date = today + timedelta(days=service.recurring_cycle.number_of_months * 30) - - # Create a new charge for the service - Charge.objects.create( - service=service, - amount=service.amount, - due_date=new_due_date - ) - return JsonResponse({'status': 'success'}) +from django.http import HttpResponse +from django.template.loader import get_template +from weasyprint import HTML # LISTING def items (request, *args, **kwargs): @@ -128,3 +110,18 @@ def invoice_details (request, invoice_id): return render(request, 'invoice-details.html', context) + + + +def generate_pdf(request): + # Render the template + template = get_template('invoice.html') + html = template.render() + + # Create a PDF file + pdf_file = HTML(string=html).write_pdf() + + # Prepare HTTP response + response = HttpResponse(pdf_file, content_type='application/pdf') + response['Content-Disposition'] = 'filename="invoice.pdf"' + return response diff --git a/osinaweb/customercore/__pycache__/urls.cpython-310.pyc b/osinaweb/customercore/__pycache__/urls.cpython-310.pyc index 786b047b..72ffedd5 100644 Binary files a/osinaweb/customercore/__pycache__/urls.cpython-310.pyc and b/osinaweb/customercore/__pycache__/urls.cpython-310.pyc differ diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index dbd97d24..84e97bda 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc index 9a96a255..4e5439e8 100644 Binary files a/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/settings.cpython-310.pyc differ