From cac613763712b5e5ed52e76d059e6e0e04fbaf97 Mon Sep 17 00:00:00 2001 From: nataly Date: Mon, 10 Jun 2024 15:58:52 +0300 Subject: [PATCH] New changes. --- .../add/__pycache__/views.cpython-312.pyc | Bin 8335 -> 12211 bytes osinaweb/billing/add/urls.py | 2 + osinaweb/billing/add/views.py | 110 ++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/osinaweb/billing/add/__pycache__/views.cpython-312.pyc b/osinaweb/billing/add/__pycache__/views.cpython-312.pyc index 9812757b9a4a785881caa741f42008e56cf311c0..5d74184a4d96ebbe5705c659919e4505034ffab4 100644 GIT binary patch delta 5062 zcmai2Yit|G5k5XekradDxfKlKlxQPHqgQ-lFlr76s5cd z&~SHlc6VlWcfL7Yd1@u%`mCwR&H%mi-?=%a_nNE4Xg6Hj`ASY;gvOXJ?my*^H=k-Y zFk(QkzsB4~RiINr=sW8AEzoz?^;@CeRM&5VzN@a^4t=(+-vNDhUEk9wcwS>pbqQYJ z+ZL^1pW0@~H-(LwdFsT`8O<~?JG=4+!w1G@FPKAo$o$BH$Xe86<~f5${m8t3X9o&u zN}5wr#CSwmOo8f$d&oeaL7ec42EH91h)nj0QDoCn{|AgM>jQyMS>V zr;d4?!G36K4qgx<5FhlAJOYxzm4IWP!7!*6gRLtGr_1EWpo9&Tg-0vxHuWmo8bbRu z+u5`%B}7@)%mS~7VN*r%aTp^{sGqS14I`@8y?^gRRQc(uG7X4kos(h;gq?cs#2K68 zqFJ6H0*v>lZ@CBej-x_-R31hF_4g@kJq=8A=;mN7oK7(=^yN8u8s$;R}Xb@5TD30lbhmVJFFQ6u!I~^8Xu2|J&XNNk| z(5UV*`dV)rDg%O1VA`0hNx|oXr2e)gOtt>fG)a5 zrFiu+mtB7d<8#S` zGBn3WMegOA5C^OBxD;F5o#XnRO{P*(Lhc*eq$HE*ZZ1t?JNr_+axS7IBdLmB1g8UF z$HZYpnd=L~awN_xJNp!p77_OQ!ebma($Aetp(C7fPULV2PD#=>PUmns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?k dUNNU(8GQ==>_5euab1Ka9%~/', views.add_order, name='addorder'), + path('invoice-pdf//', views.add_invoice_pdf, name='addinvoice'), + path('payment-pdf//', views.add_payment_pdf, name='addpayment'), path('service///', views.add_service_in_order, name='addserviceinorder'), diff --git a/osinaweb/billing/add/views.py b/osinaweb/billing/add/views.py index 95118298..628aabe3 100644 --- a/osinaweb/billing/add/views.py +++ b/osinaweb/billing/add/views.py @@ -8,6 +8,7 @@ import os from osinacore.decorators import * from django.core.files.base import ContentFile from django.db.models import Q +from weasyprint import HTML, CSS @@ -212,7 +213,116 @@ def add_payment_comment_modal(request): +def add_invoice_pdf(request, order_id): + order = get_object_or_404(Order, id=order_id) + + current_year = str(timezone.now().year)[-2:] + last_invoice = Invoice.objects.all().last() + if last_invoice: + last_invoice_number = int(last_invoice.invoice_number.split('-')[1].split('+')[0]) + new_invoice_number = f"$0{current_year}-{last_invoice_number + 1}" + else: + new_invoice_number = f"$0{current_year}-1425" + + + + invoice = Invoice.objects.create( + invoice_number = new_invoice_number, + order=order, + date_created=datetime.now(), + ) + + template = get_template('details_templates/invoice-details.html') + context = {'order': order} + html_string = template.render(context) + + # Define the CSS string with Poppins font + css_string = ''' + @font-face { + font-family: 'Poppins'; + src: url('path_to_poppins_font_file.ttf') format('truetype'); /* Update the path to the font file */ + } + + body { + font-family: 'Poppins', sans-serif; /* Use Poppins font for the entire document */ + } + + /* Your existing CSS styles */ + /* Add or modify styles as needed */ + ''' + + # Generate PDF + pdf = HTML(string=html_string).write_pdf( + stylesheets=[ + CSS(string=css_string), + CSS(string='@page { margin: 30px; }') + ], + presentational_hints=True + ) + + filename = f'invoice_{invoice.invoice_number}.pdf' + pdf_content = ContentFile(pdf) + invoice.pdf.save(filename, pdf_content, save=True) + + + # Return PDF + response = HttpResponse(pdf, content_type='application/pdf') + response['Content-Disposition'] = 'attachment; filename="my_pdf.pdf"' + return response + + + + + + + +def add_payment_pdf(request, order_id): + order = get_object_or_404(Order, id=order_id) + payments = OrderPayment.objects.filter(order = order) + paid_amount = OrderPayment.objects.filter(order=order, date_paid__isnull=False).aggregate(total_paid=Sum('amount'))['total_paid'] or 0 + cart_total = order.get_cart_total + remaining_amount = cart_total - paid_amount + + + invoice = order.invoice + + # Render both invoice and payment details templates to HTML + invoice_template = get_template('details_templates/invoice-details.html') + payment_template = get_template('details_templates/payment-details.html') + invoice_html = invoice_template.render({'order': order}) + payment_html = payment_template.render({'order': order, 'payments':payments, 'remaining_amount':remaining_amount,}) + + # Combine the HTML content of both templates + combined_html = f"{invoice_html}
{payment_html}" + + # Define CSS + css_string = ''' + @font-face { + font-family: 'Poppins'; + src: url('path_to_poppins_font_file.ttf') format('truetype'); /* Update the path to the font file */ + } + + body { + font-family: 'Poppins', sans-serif; /* Use Poppins font for the entire document */ + } + + /* Your existing CSS styles */ + /* Add or modify styles as needed */ + ''' + + # Generate PDF + pdf = HTML(string=combined_html).write_pdf( + stylesheets=[ + CSS(string=css_string), + CSS(string='@page { margin: 30px; }') + ], + presentational_hints=True + ) + # Return PDF + response = HttpResponse(pdf, content_type='application/pdf') + response['Content-Disposition'] = 'attachment; filename="my_pdf.pdf"' + return response