generate a Bakery management system in python and make the code capable of transferring…
- User
generate a Bakery management system in python and make the code capable of transferring data to excel sheet
- Assistant
generate a Bakery management system in python and make the code capable of transferring data to excel sheet
Sure! Below is a Python program for a simple Bakery Management System that allows you to manage bakery items, track sales, and update inventory. The program can also transfer data to an Excel sheet using the pandas library.
Before running the code, ensure you have the following Python libraries installed:
pip install pandas openpyxl
import pandas as pd
class BakeryItem:
def __init__(self, item_id, name, price, quantity_in_stock):
self.item_id = item_id
self.name = name
self.price = price
self.quantity_in_stock = quantity_in_stock
class BakeryManagementSystem:
def __init__(self):
self.items = {}
self.sales_history = []
self.next_item_id = 1
def add_item(self, name, price, quantity):
item = BakeryItem(self.next_item_id, name, price, quantity)
self.items[self.next_item_id] = item
self.next_item_id += 1
print(f"Added item: {item.name} (ID: {item.item_id})")
def update_stock(self, item_id, quantity):
if item_id in self.items:
self.items[item_id].quantity_in_stock += quantity
print(f"Updated stock for item ID {item_id}. New quantity: {self.items[item_id].quantity_in_stock}")
else:
print("Item ID not found.")
def sell_item(self, item_id, quantity):
if item_id in self.items:
item = self.items[item_id]
if item.quantity_in_stock >= quantity:
item.quantity_in_stock -= quantity
total_price = item.price * quantity
sale_record = {
'Item ID': item.item_id,
'Item Name': item.name,
'Quantity Sold': quantity,
'Total Price': total_price
}
self.sales_history.append(sale_record)
print(f"Sold {quantity} of {item.name}. Total price: ${total_price:.2f}")
else:
print(f"Not enough stock for {item.name}. Available quantity: {item.quantity_in_stock}")
else:
print("Item ID not found.")
def view_inventory(self):
print("\nCurrent Inventory:")
print("-------------------")
for item in self.items.values():
print(f"ID: {item.item_id} | {item.name} | Price: ${item.price:.2f} | Stock: {item.quantity_in_stock}")
def view_sales(self):
print("\nSales History:")
print("-------------------")
for sale in self.sales_history:
print(sale)
def export_inventory_to_excel(self, filename):
data = [{
'Item ID': item.item_id,
'Item Name': item.name,
'Price': item.price,
'Quantity in Stock': item.quantity_in_stock
} for item in self.items.values()]
df = pd.DataFrame(data)
df.to_excel(filename, index=False)
print(f"Inventory exported to {filename}")
def export_sales_to_excel(self, filename):
df = pd.DataFrame(self.sales_history)
df.to_excel(filename, index=False)
print(f"Sales history exported to {filename}")
def main():
system = BakeryManagementSystem()
while True:
print("\nBakery Management System")
print("1. Add Item")
print("2. Update Stock")
print("3. Sell Item")
print("4. View Inventory")
print("5. View Sales History")
print("6. Export Inventory to Excel")
print("7. Export Sales to Excel")
print("8. Exit")
choice = input("Enter your choice: ")
if choice == '1':
name = input("Enter item name: ")
price = float(input("Enter item price: "))
quantity = int(input("Enter quantity: "))
system.add_item(name, price, quantity)
elif choice == '2':
item_id = int(input("Enter item ID: "))
quantity = int(input("Enter quantity to add: "))
system.update_stock(item_id, quantity)
elif choice == '3':
item_id = int(input("Enter item ID: "))
quantity = int(input("Enter quantity to sell: "))
system.sell_item(item_id, quantity)
elif choice == '4':
system.view_inventory()
elif choice == '5':
system.view_sales()
elif choice == '6':
filename = input("Enter filename to save inventory (e.g., inventory.xlsx): ")
system.export_inventory_to_excel(filename)
elif choice == '7':
filename = input("Enter filename to save sales history (e.g., sales.xlsx): ")
system.export_sales_to_excel(filename)
elif choice == '8':
print("Exiting the system. Goodbye!")
break
else:
print("Invalid choice. Please enter a number between 1 and 8.")
if __name__ == "__main__":
main()
BakeryItem Class: Represents individual bakery items with attributes:
item_id: Unique identifier for each item.name: Name of the bakery item.price: Price per unit of the item.quantity_in_stock: Current stock level.BakeryManagementSystem Class: Manages all operations including:
add_item() method adds new items to the inventory.update_stock() method increases stock quantity.sell_item() method processes sales and updates stock.view_inventory() method displays current stock levels.view_sales() method shows all sales transactions.export_inventory_to_excel() exports current inventory to an Excel file.export_sales_to_excel() exports sales history to an Excel file.Main Function: Provides a simple text-based menu to interact with the system.
Save the Code: Copy the code into a file named bakery_management_system.py.
Install Dependencies:
Open your terminal or command prompt and run:
pip install pandas openpyxl
Run the Program:
python bakery_management_system.py
Use the Menu:
.xlsx.Bakery Management System
1. Add Item
2. Update Stock
3. Sell Item
4. View Inventory
5. View Sales History
6. Export Inventory to Excel
7. Export Sales to Excel
8. Exit
Enter your choice: 1
Enter item name: Croissant
Enter item price: 2.5
Enter quantity: 50
Added item: Croissant (ID: 1)
Bakery Management System
1. Add Item
2. Update Stock
3. Sell Item
4. View Inventory
...
This Bakery Management System provides basic functionality to manage a bakery's inventory and sales while allowing data export to Excel files for record-keeping and analysis. Feel free to modify and expand upon this code to meet your specific needs.
Not yet included in a published release.