Exploring the World of Car Rental Management: Building a Python Application - Part 13

Exploring the World of Car Rental Management: Building a Python Application - Part 13

Article 13: Adding Cars to the Inventory

Welcome back to our journey of building a Python-based car rental management system. In Part 13, we'll focus on a critical aspect of any car rental business: adding new cars to the inventory. This functionality is essential for keeping the fleet up-to-date and ensuring a diverse range of vehicles for customers.

The Significance of Adding Cars

For any car rental service, regularly introducing new cars to the inventory is crucial. It allows businesses to offer the latest models, update their fleets with more fuel-efficient or eco-friendly options, and meet the changing needs and preferences of their customers.

Steps to Add New Cars

Let's walk through the steps of adding new cars to our Python application:

  1. Gathering Car Information:

    Begin by collecting essential information about the new car, such as company, model, year, engine type, features, and cost per day.

     company = input("Enter the company: ")
     model = input("Enter the model: ")
     year = int(input("Enter the manufacturing year: "))
     engine_type = input("Enter the engine type (E/P/D): ").upper()
     # Collect other car features and cost per day
    
  2. Checking Availability:

    Ensure that the new car is not already in the system and is available for rental.

     sql = "SELECT * FROM cars WHERE company = %s AND model = %s AND year = %s AND status = 'A'"
     mycursor.execute(sql, (company, model, year))
     if mycursor.rowcount > 0:
         print("This car already exists in the system and is available for rental.")
         return
    
  3. Display Car Information and Confirm:

    Show the details of the new car to the user and confirm if they want to proceed with adding it to the inventory.

     print("\nCar Details:")
     # Display car details here
     confirm = input("Do you want to add this car to the inventory? [Y/N]: ").upper()
    

    Ensure to handle user input appropriately.

  4. Inserting into the Database:

    If the user confirms, insert the new car details into the database.

     if confirm == 'Y':
         sql = "INSERT INTO cars (company, model, year, engine, status, ...) VALUES (%s, %s, %s, %s, 'A', ...)"
         mycursor.execute(sql, (company, model, year, engine_type, ...))
         mycon.commit()
         print("New car successfully added to the inventory.")
    

    Adjust the SQL query based on your database schema.

  5. Updating Car Status:

    Ensure to set the status of the new car to 'Available' (status 'A').

     sql = "UPDATE cars SET status = 'A' WHERE company = %s AND model = %s AND year = %s"
     mycursor.execute(sql, (company, model, year))
     mycon.commit()
    

    This ensures that the new car is ready for rental.

  6. Optional: Add More Features

    Depending on your business requirements, you might want to include additional features like setting prices, specifying the number of seats, and configuring infotainment systems.

Conclusion

Part 13 has guided us through the process of adding new cars to our car rental management system. This functionality is vital for keeping the fleet diverse and up-to-date.

In Part 14, we'll explore how to view details of individual cars.

The Link to my code -> [github.com/bryanspacex/Rentals] (constantly updated)