Update app.py
Browse files
app.py
CHANGED
|
@@ -60,20 +60,21 @@ activity_log.columns = [
|
|
| 60 |
|
| 61 |
# Function to get options for part numbers or size and description
|
| 62 |
def get_options(preferred, search_by):
|
| 63 |
-
if preferred
|
| 64 |
filtered_inventory = inventory[inventory['Preferred'] == "Yes"]
|
| 65 |
else:
|
| 66 |
filtered_inventory = inventory
|
| 67 |
-
|
| 68 |
if search_by == "Part Number":
|
| 69 |
options = filtered_inventory['Part Number'].unique().tolist()
|
| 70 |
else:
|
| 71 |
sizes = filtered_inventory['Size'].unique().tolist()
|
| 72 |
descriptions = filtered_inventory['Description'].unique().tolist()
|
| 73 |
options = (sizes, descriptions)
|
| 74 |
-
|
| 75 |
return options
|
| 76 |
|
|
|
|
| 77 |
# Function to dynamically add quantity columns if needed
|
| 78 |
def add_quantity_columns(df):
|
| 79 |
current_qty_columns = [col for col in df.columns if 'QTY ' in col]
|
|
@@ -85,7 +86,7 @@ def update_inventory_and_reservation(preferred, search_by, action, part_number=N
|
|
| 85 |
global reservation # Ensure reservation is accessible
|
| 86 |
global activity_log
|
| 87 |
|
| 88 |
-
if preferred
|
| 89 |
inventory_to_use = inventory[inventory['Preferred'] == "Yes"]
|
| 90 |
else:
|
| 91 |
inventory_to_use = inventory
|
|
@@ -122,7 +123,7 @@ def update_inventory_and_reservation(preferred, search_by, action, part_number=N
|
|
| 122 |
reservation.loc[reservation_data.index[0], 'Reserved'] -= used_length
|
| 123 |
if reservation.loc[reservation_data.index[0], 'Reserved'] <= 0:
|
| 124 |
reservation = reservation.drop(reservation_data.index[0])
|
| 125 |
-
|
| 126 |
# Update quantity for all matching rows
|
| 127 |
if search_by == "Part Number":
|
| 128 |
reservation.loc[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length), 'Quantity'] -= used_length
|
|
@@ -149,7 +150,7 @@ def update_inventory_and_reservation(preferred, search_by, action, part_number=N
|
|
| 149 |
available_data = reservation[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length)]
|
| 150 |
else:
|
| 151 |
available_data = reservation[(reservation['Size'] == size) & (reservation['Description'] == description) & (reservation['Quantity'] == from_length)]
|
| 152 |
-
|
| 153 |
if not available_data.empty:
|
| 154 |
available_length = available_data['Available'].values[0]
|
| 155 |
if used_length > available_length:
|
|
@@ -222,6 +223,7 @@ def update_inventory_and_reservation(preferred, search_by, action, part_number=N
|
|
| 222 |
else:
|
| 223 |
return "Length not found."
|
| 224 |
|
|
|
|
| 225 |
# Save updated inventory and reservation to local files
|
| 226 |
updated_inventory_path = "updated_inventory.xlsx"
|
| 227 |
updated_reservation_path = "updated_reservation.xlsx"
|
|
@@ -296,7 +298,7 @@ def reload_sheets():
|
|
| 296 |
activity_log = download_and_load(activity_log_file_id)
|
| 297 |
|
| 298 |
with gr.Blocks() as demo:
|
| 299 |
-
preferred = gr.
|
| 300 |
search_by = gr.Radio(choices=["Part Number", "Size and Description"], label="Search By")
|
| 301 |
part_number = gr.Dropdown(label="Part Number", interactive=True, visible=False)
|
| 302 |
size = gr.Dropdown(label="Size", interactive=True, visible=False)
|
|
@@ -341,9 +343,9 @@ with gr.Blocks() as demo:
|
|
| 341 |
# Modify update_lengths to reload sheets before updating lengths
|
| 342 |
def update_lengths(preferred, search_by, part_number=None, size=None, description=None):
|
| 343 |
if search_by == "Part Number":
|
| 344 |
-
part_data = inventory[(inventory['Part Number'] == part_number) & (inventory['Preferred'] == preferred)]
|
| 345 |
else:
|
| 346 |
-
part_data = inventory[(inventory['Size'] == size) & (inventory['Description'] == description) & (inventory['Preferred'] == preferred)]
|
| 347 |
|
| 348 |
if part_data.empty:
|
| 349 |
return gr.update(choices=[], visible=False) # No data found
|
|
@@ -390,7 +392,7 @@ with gr.Blocks() as demo:
|
|
| 390 |
if action_value == "Consume":
|
| 391 |
return gr.update(visible=True), gr.update(visible=True)
|
| 392 |
else:
|
| 393 |
-
return gr.update(visible=False), gr.update(visible
|
| 394 |
|
| 395 |
from_length.change(handle_from_length_change, inputs=[action], outputs=[job_number, used_length])
|
| 396 |
|
|
@@ -457,8 +459,6 @@ with gr.Blocks() as demo:
|
|
| 457 |
return html_message, gr.update(visible=True), part_number
|
| 458 |
|
| 459 |
|
| 460 |
-
|
| 461 |
-
|
| 462 |
|
| 463 |
submit.click(
|
| 464 |
fn=show_confirmation,
|
|
@@ -496,6 +496,8 @@ demo.launch()
|
|
| 496 |
|
| 497 |
|
| 498 |
|
|
|
|
|
|
|
| 499 |
|
| 500 |
|
| 501 |
|
|
|
|
| 60 |
|
| 61 |
# Function to get options for part numbers or size and description
|
| 62 |
def get_options(preferred, search_by):
|
| 63 |
+
if preferred:
|
| 64 |
filtered_inventory = inventory[inventory['Preferred'] == "Yes"]
|
| 65 |
else:
|
| 66 |
filtered_inventory = inventory
|
| 67 |
+
|
| 68 |
if search_by == "Part Number":
|
| 69 |
options = filtered_inventory['Part Number'].unique().tolist()
|
| 70 |
else:
|
| 71 |
sizes = filtered_inventory['Size'].unique().tolist()
|
| 72 |
descriptions = filtered_inventory['Description'].unique().tolist()
|
| 73 |
options = (sizes, descriptions)
|
| 74 |
+
|
| 75 |
return options
|
| 76 |
|
| 77 |
+
|
| 78 |
# Function to dynamically add quantity columns if needed
|
| 79 |
def add_quantity_columns(df):
|
| 80 |
current_qty_columns = [col for col in df.columns if 'QTY ' in col]
|
|
|
|
| 86 |
global reservation # Ensure reservation is accessible
|
| 87 |
global activity_log
|
| 88 |
|
| 89 |
+
if preferred:
|
| 90 |
inventory_to_use = inventory[inventory['Preferred'] == "Yes"]
|
| 91 |
else:
|
| 92 |
inventory_to_use = inventory
|
|
|
|
| 123 |
reservation.loc[reservation_data.index[0], 'Reserved'] -= used_length
|
| 124 |
if reservation.loc[reservation_data.index[0], 'Reserved'] <= 0:
|
| 125 |
reservation = reservation.drop(reservation_data.index[0])
|
| 126 |
+
|
| 127 |
# Update quantity for all matching rows
|
| 128 |
if search_by == "Part Number":
|
| 129 |
reservation.loc[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length), 'Quantity'] -= used_length
|
|
|
|
| 150 |
available_data = reservation[(reservation['Part Number'] == part_number) & (reservation['Quantity'] == from_length)]
|
| 151 |
else:
|
| 152 |
available_data = reservation[(reservation['Size'] == size) & (reservation['Description'] == description) & (reservation['Quantity'] == from_length)]
|
| 153 |
+
|
| 154 |
if not available_data.empty:
|
| 155 |
available_length = available_data['Available'].values[0]
|
| 156 |
if used_length > available_length:
|
|
|
|
| 223 |
else:
|
| 224 |
return "Length not found."
|
| 225 |
|
| 226 |
+
|
| 227 |
# Save updated inventory and reservation to local files
|
| 228 |
updated_inventory_path = "updated_inventory.xlsx"
|
| 229 |
updated_reservation_path = "updated_reservation.xlsx"
|
|
|
|
| 298 |
activity_log = download_and_load(activity_log_file_id)
|
| 299 |
|
| 300 |
with gr.Blocks() as demo:
|
| 301 |
+
preferred = gr.Checkbox(label="Show Preferred Materials Only")
|
| 302 |
search_by = gr.Radio(choices=["Part Number", "Size and Description"], label="Search By")
|
| 303 |
part_number = gr.Dropdown(label="Part Number", interactive=True, visible=False)
|
| 304 |
size = gr.Dropdown(label="Size", interactive=True, visible=False)
|
|
|
|
| 343 |
# Modify update_lengths to reload sheets before updating lengths
|
| 344 |
def update_lengths(preferred, search_by, part_number=None, size=None, description=None):
|
| 345 |
if search_by == "Part Number":
|
| 346 |
+
part_data = inventory[(inventory['Part Number'] == part_number) & (inventory['Preferred'] == ("Yes" if preferred else "No"))]
|
| 347 |
else:
|
| 348 |
+
part_data = inventory[(inventory['Size'] == size) & (inventory['Description'] == description) & (inventory['Preferred'] == ("Yes" if preferred else "No"))]
|
| 349 |
|
| 350 |
if part_data.empty:
|
| 351 |
return gr.update(choices=[], visible=False) # No data found
|
|
|
|
| 392 |
if action_value == "Consume":
|
| 393 |
return gr.update(visible=True), gr.update(visible=True)
|
| 394 |
else:
|
| 395 |
+
return gr.update(visible=False), gr.update(visible=False)
|
| 396 |
|
| 397 |
from_length.change(handle_from_length_change, inputs=[action], outputs=[job_number, used_length])
|
| 398 |
|
|
|
|
| 459 |
return html_message, gr.update(visible=True), part_number
|
| 460 |
|
| 461 |
|
|
|
|
|
|
|
| 462 |
|
| 463 |
submit.click(
|
| 464 |
fn=show_confirmation,
|
|
|
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
+
|
| 500 |
+
|
| 501 |
|
| 502 |
|
| 503 |
|