User Authentication and Inventory System
User Authentication and Inventory System
Yes, an admin can update selective attributes of a product by using the edit_product method of the Inventory class. This method allows updating specific product attributes by passing a dictionary of new values, ignoring `None` values or skipped inputs . This approach ensures partial updates can be conducted without altering unchanged data, maintaining the accuracy of the inventory.
The system requires a valid username and password for a user to log in successfully. The AuthSystem verifies these credentials against stored values in its user dictionary . This requirement is necessary to prevent unauthorized access, ensuring that only authenticated users can perform role-specific operations, thereby maintaining system security integrity.
The system facilitates product searches by name or category through the InventoryManager methods search_by_name and filter_by_category. These methods iterate over the inventory, printing products that match the search criteria . Such functionality enhances efficiency in managing large inventories, enabling quick access to specific products for restocking, adjustments, or customer inquiries, thereby optimizing operational workflows.
An admin might choose to view all products to oversee inventory status comprehensively or perform audits. This is implemented in the InventoryManager class via the view_all_products method of the Inventory class, which iterates through all products and outputs their details . It provides a transparent overview, aiding in informed decision-making and strategic planning.
The InventoryError class serves as a custom exception type to handle specific inventory-related errors, such as product not found scenarios . Its importance lies in offering a centralized and meaningful way to manage error conditions, enhancing code readability and allowing for precise error handling and user feedback, thus contributing to robust system operation.
The AuthSystem class distinguishes roles by associating each user with a specific role ('Admin' or 'User') via the User class, which stores username, password, and role information . This differentiation allows the system to grant permissions based on the user's role. Admins can add, edit, delete, and view products or check stock levels, whereas users can only view products . This role-based access is critical for maintaining security and operational integrity within the inventory management system.
The InventoryManager class monitors stock levels using the check_stock_levels method, which compares each product's stock quantity against a specified threshold and alerts when stock is low . This functionality is vital for businesses to maintain optimal inventory levels, preventing stockouts that could lead to lost sales and customer dissatisfaction, while also avoiding overstocking that could increase storage costs.
When a product is not found during a search operation, the system raises an InventoryError with the message "Product not found." This exception handling is encapsulated within a try-except block when attempting to retrieve a product, allowing the system to gracefully manage search errors without crashing . This mechanism ensures users are informed about the issue and can take corrective actions.
To add a product to the inventory, an admin must input the product ID, name, category, price, and stock quantity. This information is then used to instantiate a Product object, which is added to the inventory using the add_product method of the Inventory class . These steps ensure all products are consistently cataloged, facilitating accurate inventory tracking and preventing discrepancies.
A user is prompted to logout during inventory viewing in the main method, specifically when a user with the role 'User' chooses to end their session. The system asks, "Do you want to logout? (yes/no)" and logs out upon a 'yes' response . This illustrates a design focus on user session management, providing clear exit options to ensure secure access termination.