Skip to content

Commit 00d4acd

Browse files
committed
adding pdf generation
1 parent 9de1987 commit 00d4acd

File tree

11 files changed

+346
-13
lines changed

11 files changed

+346
-13
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ views2.py
1919

2020
media
2121
static
22-
static_cdn
22+
static_cdn
23+
.env
24+
data.json

firstapp/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class CustomUserAdmin(UserAdmin):
2222
list_display = ('email', 'is_staff', 'is_active',)
2323
list_filter = ('email', 'is_staff', 'is_active',)
2424
fieldsets = (
25-
(None, {'fields': ('email','name','type', 'password')}),
25+
(None, {'fields': ('email', 'phone', 'name','type', 'password')}),
2626
('Permissions', {'fields': ('is_staff', 'is_active')}), #'is_customer' , 'is_seller'
2727
)
2828
add_fieldsets = (
2929
(None, {
3030
'classes': ('wide',),
31-
'fields': ('email', 'name', 'type', 'password1', 'password2', 'is_staff', 'is_active')}
31+
'fields': ('email', 'phone', 'name', 'type', 'password1', 'password2', 'is_staff', 'is_active')}
3232
),
3333
)
3434
search_fields = ('email',)

firstapp/logo.png

30.4 KB
Loading

firstapp/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
5555

5656
# if you require phone number field in your project
5757
phone_regex = RegexValidator( regex = r'^\d{10}$',message = "phone number should exactly be in 10 digits")
58-
phone = models.CharField(max_length=255, validators=[phone_regex], blank = True, null=True) # you can it set unique = True
58+
phone = models.CharField(max_length=255, validators=[phone_regex], blank = True, null=True) # you can set it unique = True
5959

6060
# is_customer = models.BooleanField(default=True)
6161
# is_seller = models.BooleanField(default = False)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% autoescape off %}
2+
Hi {{ user.name }},
3+
Your order with order id: {{order.order_id}} has been placed successfully.
4+
5+
Your order consists of -
6+
{% for i in order.productinorder_set.all %}
7+
Product:{{i.product}} Quantity:{{i.quantity}} Price:{{i.price}}
8+
{% endfor %}
9+
Total:{{order.total_amount}}
10+
11+
Order will reach to you in 5-7 days.
12+
13+
We have attached the invoice for your order with this mail.
14+
15+
Thanks for trusting us and using our services!
16+
17+
Sincerely,
18+
WonderShop Team
19+
{% endautoescape %}
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
{% load static %}
4+
<head>
5+
<title>Invoice WonderShop</title>
6+
<style>
7+
.clearfix:after {
8+
content: "";
9+
display: table;
10+
clear: both;
11+
}
12+
13+
a {
14+
text-decoration: underline;
15+
}
16+
17+
body {
18+
position: relative;
19+
margin: 0 auto;
20+
color: #001028;
21+
background: #FFFFFF;
22+
font-family: Arial, sans-serif;
23+
font-size: 14px;
24+
font-family: Arial;
25+
}
26+
27+
header {
28+
padding: 10px 0;
29+
margin-bottom: 30px;
30+
}
31+
32+
#logo {
33+
text-align: center;
34+
margin-bottom: 10px;
35+
}
36+
37+
#logo img {
38+
width: 90px;
39+
}
40+
41+
h1 {
42+
43+
color: #5D6975;
44+
font-size: 2.4em;
45+
line-height: 1.4em;
46+
font-weight: normal;
47+
text-align: center;
48+
margin: 0 0 20px 0;
49+
}
50+
51+
#project {
52+
float: left;
53+
}
54+
55+
#project span {
56+
color: #5D6975;
57+
text-align: right;
58+
width: 52px;
59+
margin-right: 10px;
60+
display: inline-block;
61+
font-size: 14px;
62+
}
63+
64+
#company {
65+
float: right;
66+
text-align: right;
67+
}
68+
69+
#project div,
70+
#company div {
71+
white-space: nowrap;
72+
}
73+
74+
table {
75+
width: 100%;
76+
border-collapse: collapse;
77+
border-spacing: 0;
78+
margin-bottom: 20px;
79+
}
80+
81+
82+
83+
table th,
84+
table td {
85+
text-align: center;
86+
}
87+
88+
table th {
89+
90+
91+
color: #5D6975;
92+
border-bottom: 1px solid #C1CED9;
93+
white-space: nowrap;
94+
font-weight: normal;
95+
}
96+
97+
table .service,
98+
table .desc {
99+
text-align: left;
100+
}
101+
102+
table td {
103+
padding-top:5px;
104+
padding-bottom:5px;
105+
106+
}
107+
108+
table tr {
109+
border-bottom: 1px solid #C1CED9;
110+
}
111+
112+
table td.service,
113+
table td.desc {
114+
vertical-align: top;
115+
}
116+
117+
table td.unit,
118+
table td.qty,
119+
table td.total {
120+
font-size: 1.2em;
121+
}
122+
123+
table td.grand {
124+
border-top: 1px solid #5D6975;;
125+
}
126+
127+
#notices .notice {
128+
color: #5D6975;
129+
font-size: 1.2em;
130+
}
131+
132+
footer {
133+
color: #5D6975;
134+
width: 100%;
135+
height: 30px;
136+
position: absolute;
137+
bottom: 0;
138+
border-top: 1px solid #C1CED9;
139+
padding: 8px 0;
140+
text-align: center;
141+
}
142+
143+
144+
</style>
145+
</head>
146+
147+
<body>
148+
<header class="clearfix">
149+
<div id="logo" style="display:flex; justify-content:center; align-items:center;">
150+
{#<img src="static/firstapp/images/logo.png" class="brand-logo" width=60 height=60>#} <!--not working-->
151+
{#<img src="static/logo.png" class="brand-logo" height="200px">#} <!--not working-->
152+
<img src="D:\Mastering Django\firstproject\firstapp\logo.png" class="brand-logo" width=60 height=60>
153+
<h1 class="brand-name">WonderShop</h1>
154+
</div>
155+
<h1>INVOICE</h1>
156+
<div id="company" class="clearfix">
157+
<div>WonderShop</div>
158+
<div><a href="mailto:company@example.com">company@example.com</a></div>
159+
<div><a href="www.wondershop.in:8000">www.wondershop.in:8000</a></div>
160+
</div>
161+
<div id="project">
162+
<div><span>CLIENT:</span> {{name}}</div>
163+
<div><span>EMAIL:</span> <a href="mailto:{{user_email}}">{{user_email}}</a></div>
164+
<div><span>DATE:</span> {{date}}</div>
165+
<div><span>INVOICE ID:</span> {{order_id}}</div>
166+
<div><span>TRANSACTION ID:</span> {{transaction_id}}</div>
167+
</div>
168+
<br>
169+
<br>
170+
</header>
171+
<div class="table-container" style="overflow-x:auto">
172+
<table class="table" style="width:100%">
173+
<thead>
174+
<tr>
175+
<th scope="col">PRODUCT</th>
176+
<th scope="col">QUANTITY</th>
177+
<th scope="col">PRICE</th>
178+
</tr>
179+
</thead>
180+
<tbody>
181+
{% for i in order.productinorder_set.all %}
182+
<tr>
183+
<td scope="row">{{i.product}}</td>
184+
<td>{{i.quantity}}</td>
185+
<td>{{i.price}}</td>
186+
187+
</tr>
188+
{% endfor %}
189+
<tr>
190+
<td scope="row"></td>
191+
<td>TOTAL: </td>
192+
<td>{{amount}}</td>
193+
194+
</tr>
195+
</tbody>
196+
</table>
197+
198+
</div>
199+
<p style="text-align:right; font-size:12px;">*All values are in INR<p>
200+
</body>
201+
202+
</html>

firstapp/templates/firstapp/payment/paymentsuccess.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<h1>Payment Success</h1>
1515
<br>
1616
<h3>Congratulations! You have successfully done the payment. Your order will reach to you in 5 days.</h3>
17-
17+
<a class="btn btn-primary btn-lg signup-button" href="{% url "generateinvoice" pk=id %}">Print Invoice</a>
1818
</div>
1919
</div>
2020
{% endblock %}

firstapp/urls.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
path('testsessions/', views.testsessions, name="testsessions"),
1717
#path('firstasyncview/', views.firstasyncview, name="firstasyncview"),
1818

19-
path('listproducts/', views.ListProducts.as_view(), name="listproducts"),
20-
#path('listproducts/', views.listProducts, name="listproducts"),
19+
#path('listproducts/', views.ListProducts.as_view(), name="listproducts"),
20+
path('listproducts/', views.listProducts, name="listproducts"),
2121
path('productdetail/<int:pk>/', views.ProductDetail.as_view(), name="productdetail"),
2222
path('addtocart/<int:id>/', views.addToCart, name="addtocart"),
2323
path('displaycart/', views.DisplayCart.as_view(), name="displaycart"),
@@ -30,6 +30,8 @@
3030
# Payment APIs
3131
path('payment/', views.payment, name = 'payment'),
3232
path('handlerequest/', views.handlerequest, name = 'handlerequest'),
33+
# Generating Invoice
34+
path('generateinvoice/<int:pk>/', views.GenerateInvoice.as_view(), name = 'generateinvoice'),
3335

3436

3537
# Authentication Endpoints

0 commit comments

Comments
 (0)