Skip to content

Commit 0854477

Browse files
committed
version 1.0.2
1 parent 81bd340 commit 0854477

File tree

3 files changed

+233
-5
lines changed

3 files changed

+233
-5
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Generated by Django 4.2 on 2023-04-24 23:34
2+
3+
from django.conf import settings
4+
import django.core.validators
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name="Appointment",
20+
fields=[
21+
(
22+
"id",
23+
models.BigAutoField(
24+
auto_created=True,
25+
primary_key=True,
26+
serialize=False,
27+
verbose_name="ID",
28+
),
29+
),
30+
(
31+
"phone",
32+
models.CharField(
33+
blank=True,
34+
default="",
35+
help_text="Phone number must not contain spaces, letters, parentheses or dashes. It must contain 10 digits.",
36+
max_length=10,
37+
null=True,
38+
validators=[
39+
django.core.validators.RegexValidator(
40+
message="Phone number must not contain spaces, letters, parentheses or dashes. It must contain 10 digits.",
41+
regex="^\\d{10}$",
42+
)
43+
],
44+
),
45+
),
46+
(
47+
"address",
48+
models.CharField(
49+
blank=True,
50+
default="",
51+
help_text="Does not have to be specific, just the city and the state",
52+
max_length=255,
53+
null=True,
54+
),
55+
),
56+
("want_reminder", models.BooleanField(default=False)),
57+
("additional_info", models.TextField(blank=True, null=True)),
58+
("paid", models.BooleanField(default=False)),
59+
(
60+
"amount_to_pay",
61+
models.DecimalField(
62+
blank=True, decimal_places=2, max_digits=6, null=True
63+
),
64+
),
65+
("id_request", models.CharField(blank=True, max_length=100, null=True)),
66+
("created_at", models.DateTimeField(auto_now_add=True)),
67+
("updated_at", models.DateTimeField(auto_now=True)),
68+
],
69+
),
70+
migrations.CreateModel(
71+
name="Config",
72+
fields=[
73+
(
74+
"id",
75+
models.BigAutoField(
76+
auto_created=True,
77+
primary_key=True,
78+
serialize=False,
79+
verbose_name="ID",
80+
),
81+
),
82+
(
83+
"slot_duration",
84+
models.PositiveIntegerField(
85+
default=30, help_text="Duration of each slot in minutes"
86+
),
87+
),
88+
(
89+
"lead_time",
90+
models.TimeField(
91+
default="09:00", help_text="Time when slots start"
92+
),
93+
),
94+
(
95+
"finish_time",
96+
models.TimeField(
97+
default="16:30", help_text="Time when we stop working"
98+
),
99+
),
100+
],
101+
),
102+
migrations.CreateModel(
103+
name="Service",
104+
fields=[
105+
(
106+
"id",
107+
models.BigAutoField(
108+
auto_created=True,
109+
primary_key=True,
110+
serialize=False,
111+
verbose_name="ID",
112+
),
113+
),
114+
("name", models.CharField(max_length=100)),
115+
("description", models.TextField(blank=True, null=True)),
116+
("duration", models.DurationField()),
117+
("price", models.DecimalField(decimal_places=2, max_digits=6)),
118+
("currency", models.CharField(default="USD", max_length=3)),
119+
(
120+
"image",
121+
models.ImageField(blank=True, null=True, upload_to="services/"),
122+
),
123+
("created_at", models.DateTimeField(auto_now_add=True)),
124+
("updated_at", models.DateTimeField(auto_now=True)),
125+
],
126+
),
127+
migrations.CreateModel(
128+
name="PaymentInfo",
129+
fields=[
130+
(
131+
"id",
132+
models.BigAutoField(
133+
auto_created=True,
134+
primary_key=True,
135+
serialize=False,
136+
verbose_name="ID",
137+
),
138+
),
139+
("created_at", models.DateTimeField(auto_now_add=True)),
140+
("updated_at", models.DateTimeField(auto_now=True)),
141+
(
142+
"appointment",
143+
models.ForeignKey(
144+
on_delete=django.db.models.deletion.CASCADE,
145+
to="appointment.appointment",
146+
),
147+
),
148+
],
149+
),
150+
migrations.CreateModel(
151+
name="AppointmentRequest",
152+
fields=[
153+
(
154+
"id",
155+
models.BigAutoField(
156+
auto_created=True,
157+
primary_key=True,
158+
serialize=False,
159+
verbose_name="ID",
160+
),
161+
),
162+
("date", models.DateField()),
163+
("start_time", models.TimeField()),
164+
("end_time", models.TimeField()),
165+
("id_request", models.CharField(blank=True, max_length=100, null=True)),
166+
("created_at", models.DateTimeField(auto_now_add=True)),
167+
("updated_at", models.DateTimeField(auto_now=True)),
168+
(
169+
"service",
170+
models.ForeignKey(
171+
on_delete=django.db.models.deletion.CASCADE,
172+
to="appointment.service",
173+
),
174+
),
175+
],
176+
),
177+
migrations.AddField(
178+
model_name="appointment",
179+
name="appointment_request",
180+
field=models.OneToOneField(
181+
on_delete=django.db.models.deletion.CASCADE,
182+
to="appointment.appointmentrequest",
183+
),
184+
),
185+
migrations.AddField(
186+
model_name="appointment",
187+
name="client",
188+
field=models.ForeignKey(
189+
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
190+
),
191+
),
192+
]

appointment/models.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Service(models.Model):
1919
description = models.TextField(blank=True, null=True)
2020
duration = models.DurationField()
2121
price = models.DecimalField(max_digits=6, decimal_places=2)
22+
currency = models.CharField(max_length=3, default='USD')
2223
image = models.ImageField(upload_to='services/', blank=True, null=True)
2324

2425
# meta data
@@ -40,6 +41,9 @@ def get_duration(self):
4041
def get_price(self):
4142
return self.price
4243

44+
def get_currency(self):
45+
return self.currency
46+
4347
def get_image(self):
4448
return self.image
4549

@@ -123,7 +127,7 @@ class Appointment(models.Model):
123127
want_reminder = models.BooleanField(default=False)
124128
additional_info = models.TextField(blank=True, null=True)
125129
paid = models.BooleanField(default=False)
126-
amount_paid = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True)
130+
amount_to_pay = models.DecimalField(max_digits=6, decimal_places=2, blank=True, null=True)
127131
id_request = models.CharField(max_length=100, blank=True, null=True)
128132

129133
# meta datas
@@ -182,8 +186,11 @@ def get_additional_info(self):
182186
def is_paid(self):
183187
return self.paid
184188

185-
def get_amount_paid(self):
186-
return self.amount_paid
189+
def get_appointment_amount_to_pay(self):
190+
return self.amount_to_pay
191+
192+
def get_appointment_currency(self):
193+
return self.appointment_request.get_service().get_currency()
187194

188195
def get_appointment_id_request(self):
189196
return self.id_request
@@ -220,3 +227,29 @@ def save(self, *args, **kwargs):
220227
def __str__(self):
221228
return f"Config {self.pk}: slot_duration={self.slot_duration}, lead_time={self.lead_time}, " \
222229
f"finish_time={self.finish_time}"
230+
231+
232+
class PaymentInfo(models.Model):
233+
appointment = models.ForeignKey(Appointment, on_delete=models.CASCADE)
234+
235+
# meta data
236+
created_at = models.DateTimeField(auto_now_add=True)
237+
updated_at = models.DateTimeField(auto_now=True)
238+
239+
def __str__(self):
240+
return f"{self.appointment.get_service_name()} - {self.appointment.get_service_price()}"
241+
242+
def get_id_request(self):
243+
return self.appointment.get_appointment_id_request()
244+
245+
def get_amount_to_pay(self):
246+
return self.appointment.get_appointment_amount_to_pay()
247+
248+
def get_currency(self):
249+
return self.appointment.get_appointment_currency()
250+
251+
def get_name(self):
252+
return self.appointment.get_service_name()
253+
254+
def get_img_url(self):
255+
return self.appointment.get_service_img_url()

appointment/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.utils.translation import gettext as _
1212

1313
from appointment.forms import AppointmentRequestForm
14-
from appointment.models import Service, Appointment, AppointmentRequest
14+
from appointment.models import Service, Appointment, AppointmentRequest, PaymentInfo
1515
from appointment.utils import Utility
1616
from .settings import (APPOINTMENT_CLIENT_MODEL, APPOINTMENT_BASE_TEMPLATE, APPOINTMENT_WEBSITE_NAME,
1717
APPOINTMENT_PAYMENT_URL, APPOINTMENT_THANK_YOU_URL)
@@ -158,7 +158,10 @@ def appointment_client_information(request, appointment_request_id, id_request):
158158
f"Redirecting to appointment payment with appointment_id {appointment.id} and id_request {id_request}")
159159
# Redirect to payment or thank you page
160160
if APPOINTMENT_PAYMENT_URL:
161-
payment_url = reverse(APPOINTMENT_PAYMENT_URL, kwargs={'appointment_id': appointment.id})
161+
payment_info = PaymentInfo(appointment=appointment)
162+
payment_info.save()
163+
payment_url = reverse(APPOINTMENT_PAYMENT_URL,
164+
kwargs={'object_id': payment_info.id, 'id_request': payment_info.get_id_request()})
162165
return HttpResponseRedirect(payment_url)
163166
elif APPOINTMENT_THANK_YOU_URL:
164167
thank_you_url = reverse(APPOINTMENT_THANK_YOU_URL, kwargs={'appointment_id': appointment.id})

0 commit comments

Comments
 (0)