-
Notifications
You must be signed in to change notification settings - Fork 4
/
carrentalsystem.py
330 lines (243 loc) · 8.04 KB
/
carrentalsystem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
from abc import ABC, abstractmethod
class Vehicle(ABC):
def __init__(self):
self.vehicle_id = 0
self.vehicle_number = 0
self.vehicle_type = None
self.company_name = None
self.model_name = None
self.km_driven = 0
self.manufacturing_date = None
self.average = 0
self.cc = 0
self.daily_rental_cost = 0
self.hourly_rental_cost = 0
self.no_of_seat = 0
self.status = None
def get_vehicle_id(self):
return self.vehicle_id
def set_vehicle_id(self, vehicle_id):
self.vehicle_id = vehicle_id
def get_vehicle_number(self):
return self.vehicle_number
def set_vehicle_number(self, vehicle_number):
self.vehicle_number = vehicle_number
def get_vehicle_type(self):
return self.vehicle_type
def set_vehicle_type(self, vehicle_type):
self.vehicle_type = vehicle_type
def get_company_name(self):
return self.company_name
def set_company_name(self, company_name):
self.company_name = company_name
def get_model_name(self):
return self.model_name
def set_model_name(self, model_name):
self.model_name = model_name
def get_km_driven(self):
return self.km_driven
def set_km_driven(self, km_driven):
self.km_driven = km_driven
def get_manufacturing_date(self):
return self.manufacturing_date
def set_manufacturing_date(self, manufacturing_date):
self.manufacturing_date = manufacturing_date
def get_average(self):
return self.average
def set_average(self, average):
self.average = average
def get_cc(self):
return self.cc
def set_cc(self, cc):
self.cc = cc
def get_daily_rental_cost(self):
return self.daily_rental_cost
def set_daily_rental_cost(self, daily_rental_cost):
self.daily_rental_cost = daily_rental_cost
def get_hourly_rental_cost(self):
return self.hourly_rental_cost
def set_hourly_rental_cost(self, hourly_rental_cost):
self.hourly_rental_cost = hourly_rental_cost
def get_no_of_seat(self):
return self.no_of_seat
def set_no_of_seat(self, no_of_seat):
self.no_of_seat = no_of_seat
def get_status(self):
return self.status
def set_status(self, status):
self.status = status
class Bike(Vehicle):
pass
class Car(Vehicle):
pass
from enum import Enum
class Status(Enum):
ACTIVE = 'ACTIVE'
INACTIVE = 'INACTIVE'
class VehicleType(Enum):
CAR = 'CAR'
class Bill:
def __init__(self, reservation):
self.reservation = reservation
self.total_bill_amount = self.compute_bill_amount()
self.is_bill_paid = False
def compute_bill_amount(self):
return 100.0
class Location:
def __init__(self, address, pincode, city, state, country):
self.address = address
self.pincode = pincode
self.city = city
self.state = state
self.country = country
class Payment:
def pay_bill(self, bill):
# do payment processing and update the bill status
pass
class PaymentDetails:
def __init__(self):
self.paymentId = 0
self.amountPaid = 0
self.dateOfPayment = None
self.isRefundable = False
self.paymentMode = None
class PaymentMode(Enum):
CASH = 'CASH'
ONLINE = 'ONLINE'
class Reservation:
def __init__(self):
self.reservation_id = 0
self.user = None
self.vehicle = None
self.booking_date = None
self.date_booked_from = None
self.date_booked_to = None
self.from_time_stamp = 0
self.to_time_stamp = 0
self.pick_up_location = None
self.drop_location = None
self.reservation_type = None
self.reservation_status = None
self.location = None
def create_reservation(self, user, vehicle):
# generate new id
self.reservation_id = 12232
self.user = user
self.vehicle = vehicle
self.reservation_type = ReservationType.DAILY
self.reservation_status = ReservationStatus.SCHEDULED
return self.reservation_id
# CRUD operations
class ReservationStatus(Enum):
SCHEDULED = 'SCHEDULED'
INPROGRESS = 'INPROGRESS'
COMPLETED = 'COMPLETED'
CANCELLED = 'CANCELLED'
class ReservationType(Enum):
HOURLY = 'HOURLY'
DAILY = 'DAILY'
class Store:
def __init__(self):
self.store_id = 0
self.inventory_management = None
self.store_location = None
self.reservations = []
def get_vehicles(self, vehicle_type):
return self.inventory_management.get_vehicles()
# addVehicles, update vehicles, use inventory management to update those.
def set_vehicles(self, vehicles):
self.inventory_management = VehicleInventoryManagement(vehicles)
def create_reservation(self, vehicle, user):
reservation = Reservation()
reservation.create_reserve(user, vehicle)
self.reservations.append(reservation)
return reservation
def complete_reservation(self, reservation_id):
# take out the reservation from the list and call complete the reservation method.
return True
# update reservation
class User:
def __init__(self):
self.user_id = 0
self.user_name = 0
self.drivingLicense = 0
def get_user_id(self):
return self.user_id
def set_user_id(self, user_id):
self.user_id = user_id
def get_user_name(self):
return self.user_name
def set_user_name(self, user_name):
self.user_name = user_name
def get_driving_license(self):
return self.driving_license
def set_driving_license(self, driving_license):
self.driving_license = driving_license
class VehicleInventoryManagement:
def __init__(self, vehicles):
self.vehicles = vehicles
def get_vehicles(self):
# filtering
return self.vehicles
def set_vehicles(self, vehicles):
self.vehicles = vehicles
class VehicleRentalSystem:
def __init__(self, stores, users):
self.store_list = stores
self.user_list = users
def get_store(self, location):
# based on location, we will filter out the Store from storeList.
return self.store_list[0]
# addUsers
# remove users
# add stores
# remove stores
class Main:
def main(self):
users = self.addUsers()
vehicles = self.addVehicles()
stores = self.addStores(vehicles)
rentalSystem = VehicleRentalSystem(stores, users)
# 0. User comes
user = users[0]
# 1. user search store based on location
location = Location(403012, "Bangalore", "Karnataka", "India")
store = rentalSystem.getStore(location)
# 2. get All vehicles you are interested in (based upon different filters)
storeVehicles = store.getVehicles(VehicleType.CAR)
# 3.reserving the particular vehicle
reservation = store.createReservation(storeVehicles[0], users[0])
# 4. generate the bill
bill = Bill(reservation)
# 5. make payment
payment = Payment()
payment.payBill(bill)
# 6. trip completed, submit the vehicle and close the reservation
store.completeReservation(reservation.reservationId)
def addVehicles():
vehicles = []
vehicle1 = Car()
vehicle1.setVehicleID(1)
vehicle1.setVehicleType(VehicleType.CAR)
vehicle2 = Car()
vehicle1.setVehicleID(2)
vehicle1.setVehicleType(VehicleType.CAR)
vehicles.add(vehicle1)
vehicles.add(vehicle2)
return vehicles
def addUsers():
users = []
user1 = User()
user1.setUserId(1)
users.add(user1)
return users
def addStores(self, vehicles):
stores = []
store1 = Store()
store1.storeId = 1
store1.setVehicles(vehicles)
stores.add(store1)
return stores
if __name__ == '__main__':
main = Main()
main.main()