Untitled

 avatar
unknown
plain_text
a year ago
3.5 kB
4
Indexable
# Inventory Management

def print_message(message):
    print("*" * len(message))
    print(message)
    print("*" * len(message))

def product_setting_choice():
    print("1. View / Update Blooms")
    print("2. Add New Bloom")
    print("3. View / Update Add-ons")
    print("4. Add New Add-on")
    print("5. Back to Main Menu")

    choice = input(">>> ")

    if choice == "1":
        return "View / Update Blooms"
    elif choice == "2":
        return "Add New Bloom"
    elif choice == "3":
        return "View / Update Add-ons"
    elif choice == "4":
        return "Add New Add-on"
    elif choice == "5":
        return "Back to Main Menu"

def view_items(file_path):
    with open(file_path, "r") as file:
        next(file)
        for line in file:
            new_line = line.replace(",", ", ")
            print(new_line)

def check_bloom_id(input_bloom_id):
    with open("blooms.txt", "r") as file:
        next(file)
        for line in file:
            recorded_bloom_id = line.split(",")[0].strip()
            if input_bloom_id == recorded_bloom_id:
                return True
        return False

def update_item(file_path, input_item_id, for_update, choice):
    with open(file_path, "r+") as file:
        lines = file.readlines()
        for index, line in enumerate(lines):
            if input_item_id == line.split(",")[0].strip():
                recorded = line.split(",")[choice].strip()
                updated_line = line.replace(recorded, for_update)
                lines[index] = updated_line
        file.seek(0)
        for line in lines:
            file.write(line)
        file.truncate()
    print("Update Successfully!")

print_message("Welcome To Beautiful Blooms 🌺")

while True:

    choice = product_setting_choice()

    if choice == "View / Update Blooms":
        while True:
            view_items("blooms.txt")
            print("-" * 30)
            print("1. Update")
            print("2. Back")
            print("-" * 30)

            choice = input(">>> ")

            if choice == "1":

                input_bloom_id = input("Enter the Bloom ID: ")
                while not check_bloom_id(input_bloom_id):
                    print_message("Invalid Bloom ID! Please Try Again!")
                    input_bloom_id = input("Enter the Bloom ID: ")

                while True:
                    print("-" * 30)
                    print("1. Price")
                    print("2. Status")
                    print("-" * 30)

                    choice = input(">>> ")

                    if choice == "1":
                        input_bloom_price = input("Enter new price: ")
                        update_item("blooms.txt", input_bloom_id, input_bloom_price, -2)
                    elif choice == "2":
                        input_bloom_status = input("Enter new status: ")
                        update_item("blooms.txt", input_bloom_id, input_bloom_status, -1)
                    else:
                        print_message("Invalid Input! Please Try Again!")
                        continue
                    break

            elif choice == "2":
                break
            else:
                print_message("Invalid Input! Please Try Again!")
    elif choice == "Add New Bloom":
        None
    elif choice == "View / Update Add-ons":
        view_items("addons.txt")
    elif choice == "Add New Add-on":
        None
    elif choice == "Back to Main Manu":
        None
    else:
        print("Invalid Input! Please Try Again!")


Editor is loading...