Notes:
-
Problem Solved: Automates the order processing workflow, from order creation to inventory update.
-
Benefits: Streamlines order handling, reduces manual errors, and ensures timely updates to inventory.
-
Adoption: Integrate this system with e-commerce platforms or use it for internal order processing.
Python Code:
import pandas as pd
class OrderProcessor:
def __init__(self, inventory_data):
self.inventory_data = pd.DataFrame(inventory_data)
def process_order(self, order):
for product_id, quantity in order.items():
if product_id in self.inventory_data['ProductID'].values:
stock = self.inventory_data.loc[self.inventory_data['ProductID'] == product_id, 'Quantity'].values[0]
if stock >= quantity:
self.inventory_data.loc[self.inventory_data['ProductID'] == product_id, 'Quantity'] -= quantity
print(f"Order for {quantity} units of {product_id} processed.")
else:
print(f"Insufficient stock for {product_id}. Only {stock} units available.")
else:
print(f"Product {product_id} not found in inventory.")
def get_inventory(self):
return self.inventory_data
# Sample inventory data
inventory_data = [
{'ProductID': 'A101', 'Quantity': 100},
{'ProductID': 'B202', 'Quantity': 150},
{'ProductID': 'C303', 'Quantity': 50},
]
# Initialize processor
processor = OrderProcessor(inventory_data)
# Sample order
order = {'A101': 20, 'B202': 30, 'C303': 60}
# Process order
processor.process_order(order)
# Display updated inventory
print(processor.get_inventory())
No comments:
Post a Comment