-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_customer.py
84 lines (75 loc) · 2.7 KB
/
app_customer.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
from consumer.connect import DataConsumer
from consumer.credentials import getCredentials
from basic_display import BasicDisplay
from cli.select import Selecter
from cli.pass_asker import PassAsker
from cli.customer_action_asker import CustomerActionAsker
from cli.book_asker import BookAsker
from cli.product_select import ProductSelecter
from cli.house_asker import HouseAsker
from cli.confirm import Confirmer
from cli.quantity_asker import QuantityAsker
from datetime import date, timedelta
display = BasicDisplay()
display.title('Customer application')
credentials = getCredentials()
consumer = DataConsumer(credentials)
companyAsker = Selecter('Choose your company')
passAsker = PassAsker()
actionAsker = CustomerActionAsker()
bookAsker = BookAsker()
productAsker = ProductSelecter()
houseAsker = HouseAsker()
confirmAsker = Confirmer()
quantityAsker = QuantityAsker()
# Login phase
compList = consumer.getCompanyNames()
compList.append('dev')
login = companyAsker.selectInto(compList)
pwd = passAsker.ask()
# Dummy password check
if pwd != "":
print('Successfully logged as', login)
else:
print('Name', login, 'not recognized.')
print('(dummy password check : enter an non-empty password)')
exit()
# Action phase
running = True
while running:
ans = actionAsker.ask()
action = ans['action']
if action == 'quit':
running = False
elif action == 'list orders':
bookList = consumer.getOrdersOfCompany(login)
if len(bookList) == 0:
display.error('No book order for', login, 'yet.')
else:
bookId = bookAsker.select(bookList)
itemList = consumer.getItemsOfOrder(bookId)
if len(itemList) == 0:
display.error('No item found for order', bookId)
else:
display.orderedItemList(itemList)
elif action == 'list warehouses':
houseList = consumer.getWarehousesOfCompany(login)
if len(houseList) == 0:
display.error('No warehouse for', login, 'yet.')
else:
display.warehouseList(houseList)
elif action == 'new order':
houseList = consumer.getWarehousesOfCompany(login)
targetHouseId = houseAsker.select(houseList)
proList = consumer.getProductSet()
proSelectNameList = productAsker.selectInto(proList)
productQuantityList = quantityAsker.askForEachOf(proSelectNameList)
dueDate = date.today() + timedelta(15)
if (confirmAsker.confirm()):
consumer.addOrder(login, targetHouseId, proSelectNameList, productQuantityList, dueDate)
consumer.commit()
else:
display.error('Order creation aborted')
else:
display.notImplemented(action)
display.end()