-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturnVehicle.py
58 lines (48 loc) · 2.76 KB
/
returnVehicle.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
import contextlib
import sqlite3
def returnvehicle(vehicle, newmiles, qsp=''):
"""Return the vehicle"""
if vehicle['status'] == 'rented':
with contextlib.closing(sqlite3.connect('rental.db')) as con:
with con as cur:
formatted = "{}:{}".format(vehicle['id'], vehicle['vin'])
cur.execute('UPDATE vehicles SET status = "returned", mileage = ? WHERE id = ?',
(newmiles, vehicle['id'])) # Set the vehicle to returned
print(formatted + " is being returned with {} miles.".format(newmiles))
if qsp != '':
cur.execute('UPDATE vehicles SET code = ? WHERE id = ?',
(qsp, vehicle['id']))
elif newmiles > vehicle['nextService']: # Set the vehicle to PM if it needs service
cur.execute('UPDATE vehicles SET code = ? next service = ? WHERE id = ?',
('PM', vehicle['nextService'] + 5000, vehicle['id']))
print(formatted + " is now a PM")
def rentvehicle(vehicle):
"""Rent the vehicle"""
if vehicle['status'] == 'returned':
with contextlib.closing(sqlite3.connect('rental.db')) as con:
with con as cur:
code = vehicle['code']
formatted = "{}:{}".format(vehicle['id'], vehicle['vin'])
if code == '':
print(formatted + " is being rented.")
cur.execute('UPDATE vehicles SET status = "rented" WHERE id = ?',
(vehicle['id'],))
else:
if code == 'PM':
print(formatted + " is under maintenance.")
elif code == 'GLAS':
print(formatted + " glass is being replaced.")
cur.execute('UPDATE vehicles SET code = "" WHERE id = ?', (vehicle['id'],))
def codes(vehicle):
"""Perform maintenance, etc"""
with contextlib.closing(sqlite3.connect('rental.db')) as con:
with con as cur:
cur.execute('UPDATE vehicles SET code = "" WHERE id = ?',
(vehicle['id'],))
def auditvehicles(vehicles):
for vehicle in vehicles:
print("{}:{} {} {} {}, {}, mileage: {}, status: {} code: {}".format(vehicle['id'], vehicle['vin'],
vehicle['year'], vehicle['make'],
vehicle['model'], vehicle['color'],
vehicle['mileage'],
vehicle['status'], vehicle['code']))