Update app.y
Browse files
app.y
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request, make_response
|
| 2 |
+
import weasyprint # Required for PDF generation
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# Example route for rendering the order summary page
|
| 7 |
+
@app.route("/order-summary", methods=["GET", "POST"])
|
| 8 |
+
def order_summary():
|
| 9 |
+
# Simulate some order data to be passed to the template (this can be dynamic data)
|
| 10 |
+
order_data = {
|
| 11 |
+
'Order_Details__c': "1 x Zafrani Chicken 65 Biryani|Add-On: None|No special instructions|Price: 369",
|
| 12 |
+
'Total_Amount__c': 369.00,
|
| 13 |
+
'Discount__c': 0.00,
|
| 14 |
+
'Total_Bill__c': 387.45
|
| 15 |
+
}
|
| 16 |
+
return render_template("order_summary.html", order=order_data)
|
| 17 |
+
|
| 18 |
+
# Route for creating the invoice PDF
|
| 19 |
+
@app.route("/generate-invoice", methods=["POST"])
|
| 20 |
+
def generate_invoice():
|
| 21 |
+
order_data = request.form
|
| 22 |
+
html = render_template("invoice_template.html", order=order_data) # Generate HTML using template
|
| 23 |
+
|
| 24 |
+
# Convert the HTML to PDF using WeasyPrint
|
| 25 |
+
pdf = weasyprint.HTML(string=html).write_pdf()
|
| 26 |
+
|
| 27 |
+
# Send the PDF as a downloadable response
|
| 28 |
+
response = make_response(pdf)
|
| 29 |
+
response.headers['Content-Type'] = 'application/pdf'
|
| 30 |
+
response.headers['Content-Disposition'] = 'inline; filename=invoice.pdf'
|
| 31 |
+
return response
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
app.run(debug=True)
|