-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtote.py
128 lines (108 loc) · 6.25 KB
/
tote.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
from constants import COLOR, COLOR_RED, COLOR_GREEN
from num_to_asin import num_to_asin
class Tote:
"""
Create Tote object with .audit() method.
"""
def __init__(self, tote_code, df_content):
"""
:param tote_code: str (e.g.: tsX... )
:param df_content: pd DataFrame
"""
self.tote_code = tote_code
self.df_content = df_content # pd DataFrame
self.asins_dict = False # will become dict of ASINs in tote
self.asins_checked = False # will become deep copy of self.asins_dict to count ASINs audited
self.missing_asins = False # will become deep copy of asins_checked but keys with value == 0 removed
self.audited = False
def audit(self, escalation_msg, fc):
print(COLOR + f"Auditing {self.tote_code}. Please scan all items in tote. Insert 'exit' to stop.")
self.df_content = self.df_content.reset_index(drop=True) # reset index to allow enumerate to work
# create dict with ASINs
self.asins_dict = dict() # {Scannable ID: Quantity} add duplicates in pd DataFrame
self.asins_checked = dict() # deep copy of self.asins_dict
# str.rstrip() removes whitespace at end of ASINs
for row, elem in enumerate(self.df_content["FN SKU"].str.rstrip()):
if elem in self.asins_dict:
self.asins_dict[elem] += self.df_content["Quantity"][row]
self.asins_checked[elem] += self.df_content["Quantity"][row]
else:
self.asins_dict[elem] = self.df_content["Quantity"][row]
self.asins_checked[elem] = self.df_content["Quantity"][row]
#
print(COLOR + f"{self.tote_code} contains:")
for asin in self.asins_dict:
print(COLOR + f"{asin} : {self.asins_dict[asin]}")
while sum(self.asins_checked.values()) > 0:
print(COLOR + f"{self.tote_code} contains ", end="")
print(COLOR_GREEN + f"{sum(self.asins_checked.values())}", end="")
print(COLOR + " products that have not been audited. Please scan a product or insert 'exit' to stop.\n->",
end="")
item = input()
if item.lower() == "exit":
for elem in self.asins_checked:
if self.asins_checked[elem] != 0:
print(COLOR + f"{elem} : {self.asins_checked[elem]}")
print(COLOR + f"are still missing. If these items are not in {self.tote_code}, {escalation_msg}")
print(COLOR + f"Do you want to stop auditing {self.tote_code}?(yes/no)\n->", end="")
confirmation = input().strip().lower()
if confirmation == "yes":
break
else:
print(COLOR + f"Please keep auditing {self.tote_code}.")
elif item in self.asins_checked:
if self.asins_checked[item] > 0:
print(COLOR_GREEN + "\nSUCCESS!")
print(COLOR + f"Audited: {item}")
self.asins_checked[item] -= 1
else: # elif tote_content[item] == 0: # over quantity
print(COLOR_RED + "\nERROR!!!")
print(COLOR_RED + f"All the items with this ASIN have been already scanned. {escalation_msg}")
else: # elif item != "exit" and item not in tote_content:
try:
right_code = num_to_asin(item, fc)
if right_code is None:
print(COLOR_RED + f"This product number or ASIN was not recognised. {escalation_msg}")
elif right_code in self.asins_checked:
if self.asins_checked[right_code] > 0:
print(COLOR_GREEN + f"{item} converted to {right_code}.\nSUCCESS!!")
self.asins_checked[right_code] -= 1
else: # over quantity
print(COLOR_RED + f"All the items with this ASIN have been already scanned "
f"{escalation_msg}")
else:
print(COLOR_RED + f"{item} was recognized as ASIN {right_code}, but this item should not be in "
f"{self.tote_code}. {escalation_msg}")
except BaseException as e:
print(COLOR_RED + f"\nERROR!! {e}\n. Wrong ASIN: {item}. {escalation_msg}")
print(COLOR + f"Finished auditing {self.tote_code}")
if sum(self.asins_checked.values()) == 0:
print(COLOR_GREEN + f"{self.tote_code} audit was successful!")
self.audited = "Audit Passed"
else:
answer = False
while not answer:
print(COLOR_RED + f"{self.tote_code} audit was not completed. Please start audit again or start "
f"escalation procedure. Was audit interrupted because audit FAILED? (yes/no)\n->",
end="")
is_failed = input()
is_failed = is_failed.lower()
if 'y' in is_failed:
print(COLOR_RED + f"These items were not found in {self.tote_code}:")
self.missing_asins = dict()
for elem in self.asins_checked:
if self.asins_checked[elem] != 0:
self.missing_asins[elem] = self.asins_checked[elem]
print(COLOR + f"{elem} : {self.asins_checked[elem]}")
self.audited = "Failed. Missing:" + str(self.missing_asins)
answer = True
elif 'n' in is_failed:
self.audited = "Interrupted"
print(COLOR + f"At the end of pallet audit, please explain why {self.tote_code} audit was "
f"interrupted (e.g.: @login requested the pallet to be transshipped immediately).")
answer = True
if __name__ == "__main__":
import pandas as pd
df = pd.DataFrame({"FN SKU": [1, 2], "Quantity": [3, 4]})
a = Tote("a", df)
a.audit("AA", "MXP5")