Guest User

inventory.py

a guest
Feb 12th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. from typing import Dict
  2. from ansi import BRIGHT_YELLOW, BRIGHT_RED, RESET
  3. import buy
  4. import deliveries
  5. import help_menus
  6. from footer import get_user_choice, invalid_choice
  7.  
  8. class InventoryManager:
  9.     """
  10.    Manage drug inventory.
  11.    """
  12.     def __init__(self) -> None:
  13.         self.inventory_data: Dict[str, int] = {}
  14.  
  15.     def add_to_inventory(self, drug: str, quantity: int) -> None:
  16.         """
  17.        Add a specified quantity of a drug to inventory.
  18.  
  19.        Raises:
  20.            ValueError: If quantity is negative.
  21.        """
  22.         if quantity < 0:
  23.             raise ValueError("Cannot add a negative quantity to inventory.")
  24.         if drug in self.inventory_data:
  25.             self.inventory_data[drug] += quantity
  26.         else:
  27.             self.inventory_data[drug] = quantity
  28.  
  29.     def display_inventory(self) -> None:
  30.         """
  31.        Display the inventory menu.
  32.        """
  33.         while True:
  34.             self.print_inventory_header()
  35.             self.display_inventory_list()
  36.             if self.inventory_data:
  37.                 for drug, qty in self.inventory_data.items():
  38.                     print(f"{drug:<25} {qty:<25}")
  39.             else:
  40.                 print(f"{BRIGHT_RED}No drugs in inventory.{RESET}")
  41.             self.display_menu()
  42.  
  43.             choice = get_user_choice()
  44.            
  45.             if choice == "B":
  46.                 buy.buy_drugs()
  47.             elif choice == "D":
  48.                 # Changed from 'deliveries.show_deliveries()' to the correct menu call.
  49.                 deliveries.deliveries_menu()
  50.             elif choice == "H":
  51.                 help_menus.show_help("INVENTORY")
  52.             elif choice == "X":
  53.                 break
  54.             else:
  55.                 invalid_choice()
  56.  
  57.     def print_inventory_header(self) -> None:
  58.         """
  59.        Print the inventory header.
  60.        """
  61.         print(f"\n{BRIGHT_YELLOW}INVENTORY{RESET}\n")
  62.         from header import game_stats
  63.         game_stats.display_header()
  64.  
  65.     def display_inventory_list(self) -> None:
  66.         """
  67.        Display the title row for the inventory list.
  68.        """
  69.         print(f"{BRIGHT_YELLOW}{'DRUG':<25} {'QUANTITY':<25}{RESET}")
  70.         print("-" * 50)
  71.  
  72.     def display_menu(self) -> None:
  73.         """
  74.        Display inventory menu options.
  75.        """
  76.         print(f"\n{BRIGHT_YELLOW}B{RESET} - Buy")
  77.         print(f"{BRIGHT_YELLOW}D{RESET} - Deliveries")
  78.         print(f"{BRIGHT_YELLOW}H{RESET} - Help")
  79.         print(f"{BRIGHT_YELLOW}X{RESET} - Back")
Add Comment
Please, Sign In to add comment