-
Notifications
You must be signed in to change notification settings - Fork 1
/
super.py
189 lines (172 loc) · 7.45 KB
/
super.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
# Imports from python library
import datetime
# Imports from rich library
from rich import print
# Imports from core folder
from core.parser import create_parser
# Imports from functions folder
from functions.files import create_data_files
from functions.dates import get_today, set_today, advance_time
from functions.reports import get_inventory_report, get_expired_report, get_revenue_report, get_profit_report
from functions.inventory import update_inventory
from functions.buy import buy_product
from functions.sell import sell_product
from functions.richtable import output_table
# Do not change these lines.
__winc_id__ = "a2bc36ea784242e4989deb157d527ba0"
__human_name__ = "superpy"
# Your code below this line.
def main():
create_data_files()
args = create_parser()
# Check which command was given
# and call the corresponding function
# with the given arguments
# the set_today function is added to the parser
if args.command == "set_today":
if args.date:
set_today(datetime.datetime.strptime(args.date, "%Y-%m-%d").date())
date = get_today()
if args.now or args.today:
set_today(datetime.date.today())
date = get_today()
print(f'Today\'s fictive date is now set to {date}.')
update_inventory()
# the get_today function is added to the parser
elif args.command == "get_today":
date = get_today()
print(f'Today\'s fictive date is {date}.')
update_inventory()
# the advance_time function is added to the parser
elif args.command == "advance_time":
print(f"Advancing time with {args.days} days...")
advance_time(args.days)
date = get_today()
print(f'Today\'s fictive date is now set to {date}.')
update_inventory()
# the buy function is added to the parser
elif args.command == "buy":
update_inventory()
buy_product(args.product_name, args.price,
args.expiration_date, args.quantity)
output_table("bought")
# the sell function is added to the parser
elif args.command == "sell":
update_inventory()
sell_product(args.product_name, args.price, args.quantity)
output_table("sold")
# the report function is added to the parser
elif args.command == "report":
# Check which report type was given
# the inventory report is added to the parser
if args.report_type == "inventory":
today = get_today()
if args.now:
print(f"Inventory report for {today}:")
get_inventory_report(today, "inventory")
if args.yesterday:
yesterday = today - datetime.timedelta(days=1)
print(f"Inventory report for {yesterday}:")
get_inventory_report(yesterday, "inventory")
if args.date:
report_date = datetime.datetime.strptime(args.date, "%Y-%m-%d").date()
print(f"Inventory report for {report_date}:")
current_date = get_today()
set_today(report_date)
get_inventory_report(report_date, "inventory")
set_today(current_date)
# the expired report is added to the parser
elif args.report_type == "expired":
today = get_today()
if args.now:
print(f"Expired products report for {today}:")
get_expired_report(today, "expired")
if args.yesterday:
yesterday = today - datetime.timedelta(days=1)
print(f"Expired products report for {yesterday}:")
get_expired_report(yesterday, "expired")
if args.date:
report_date = datetime.datetime.strptime(args.date, "%Y-%m-%d").date()
print(f"Expired products report for {report_date}:")
current_date = get_today()
set_today(report_date)
get_expired_report(report_date, "expired")
set_today(current_date)
# the revenue report is added to the parser
elif args.report_type == "revenue":
today = get_today()
print(f"\nRevenue report per {today}:")
if args.today:
get_revenue_report(today, "day")
if args.date or args.day:
if args.date:
report_date = datetime.datetime.strptime(
args.date, "%Y-%m-%d").date()
elif args.day:
report_date = datetime.datetime.strptime(
args.day, "%Y-%m-%d").date()
print(f"for {report_date}:")
current_date = get_today()
set_today(report_date)
get_revenue_report(report_date, "day")
set_today(current_date)
if args.month:
report_date = datetime.datetime.strptime(args.month, "%Y-%m").date()
print(f"for month {report_date.month} of {report_date.year}:")
current_date = get_today()
set_today(report_date)
get_revenue_report(report_date, "month")
set_today(current_date)
if args.year:
report_date = datetime.datetime.strptime(args.year, "%Y").date()
print(f"for {report_date.year}:")
current_date = get_today()
set_today(report_date)
get_revenue_report(report_date, "year")
set_today(current_date)
if args.all:
print(f"for all time:")
get_revenue_report(today, "all")
# the profit report is added to the parser
elif args.report_type == "profit":
today = get_today()
print(f"\nProfit report for {today}:")
if args.today:
get_profit_report(today, "day")
if args.date or args.day:
if args.date:
report_date = datetime.datetime.strptime(
args.date, "%Y-%m-%d").date()
elif args.day:
report_date = datetime.datetime.strptime(args.day, "%Y-%m-%d").date()
print(f"for {report_date}:")
current_date = get_today()
set_today(report_date)
get_profit_report(report_date, "day")
set_today(current_date)
if args.month:
report_date = datetime.datetime.strptime(args.month, "%Y-%m").date()
print(f"for month {report_date.month} of {report_date.year}:")
current_date = get_today()
set_today(report_date)
get_profit_report(report_date, "month")
set_today(current_date)
if args.year:
report_date = datetime.datetime.strptime(args.year, "%Y").date()
print(f"for {report_date.year}:")
current_date = get_today()
set_today(report_date)
get_profit_report(report_date, "year")
set_today(current_date)
if args.all:
print(f"for all time:")
get_profit_report(today, "all")
else:
args.parser.print_help()
else:
date = get_today()
print("We pretent today's date is", date)
update_inventory()
output_table("inventory")
if __name__ == "__main__":
main()