-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
53 lines (41 loc) · 1.73 KB
/
app.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
import os
import pandas as pd
from flask import Flask, render_template, request, redirect, url_for
from pandas.errors import EmptyDataError
app = Flask(__name__)
EXCEL_FILE = 'Inventory List.xlsx'
def load_inventory():
try:
return pd.read_excel(EXCEL_FILE)
except (FileNotFoundError, EmptyDataError):
return pd.DataFrame(columns=["Property_Tag", "Serial_Number", "Service_Tag", "Type", "Location", "Status"])
def save_inventory(inventory_df):
try:
inventory_df.to_excel(EXCEL_FILE, index=False)
print(f"Inventory updated successfully and saved to {EXCEL_FILE}")
except Exception as e:
print(f"Error saving inventory to Excel: {e}")
@app.route('/')
def index():
inventory_df = load_inventory()
return render_template("index.html", items=inventory_df.to_dict(orient="records"))
@app.route('/check_out/<int:Property_Tag>', methods=['POST'])
def check_out(Property_Tag):
inventory_df = load_inventory()
item = inventory_df[inventory_df['Property_Tag'] == Property_Tag].iloc[0]
print(item)
if item['Status'] == 'Avaliable':
inventory_df.loc[inventory_df['Property_Tag'] == Property_Tag, 'Status'] = 'Unavaliable'
print(inventory_df)
save_inventory(inventory_df)
return redirect(url_for('index'))
@app.route('/check_in/<int:Property_Tag>', methods=['POST'])
def check_in(Property_Tag):
inventory_df = load_inventory()
item = inventory_df[inventory_df['Property_Tag'] == Property_Tag].iloc[0]
if item['Status'] == 'Unavaliable':
inventory_df.loc[inventory_df['Property_Tag'] == Property_Tag, 'Status'] = 'Avaliable'
save_inventory(inventory_df)
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True)