1+ """ 
2+ Core business logic and domain model for the warehouse management system. 
3+ 
4+ This module defines the central `WareHouse` class responsible for inventory 
5+ management, including procuring, selling, and searching for items. 
6+ It depends on the entity definitions from `warehouse.core.entities`. 
7+ """ 
8+ from  warehouse .core .entities  import  WarehouseItem 
9+ 
10+ 
11+ class  WareHouse :
12+     """Manages the inventory and operations of a physical warehouse. 
13+ 
14+     This class provides methods for adding, removing, and finding items 
15+     based on their unique identifiers or names. 
16+ 
17+     Attributes: 
18+         wid: A unique identifier for the warehouse. 
19+         name: The human-readable name of the warehouse. 
20+         location: The physical address or location of the warehouse. 
21+         items: A dictionary mapping product IDs (str) to :class:`WarehouseItem` objects 
22+                currently in stock. 
23+     """ 
24+ 
25+     def  __init__ (self , wid : str , name : str , location : str ):
26+         """Initializes a new WareHouse instance. 
27+ 
28+         Args: 
29+             wid: A unique identifier for the warehouse (e.g., 'WH-001'). 
30+             name: The human-readable name of the warehouse (e.g., 'Central Depot'). 
31+             location: The physical address or location of the warehouse. 
32+         """ 
33+         self .wid  =  wid 
34+         self .name  =  name 
35+         self .location  =  location 
36+         self .items : dict [str , WarehouseItem ] =  {}
37+ 
38+     def  add_new_item (self , item_id : str , name : str , price : float , quantity : int ):
39+         """Creates and registers a brand new item in the warehouse inventory. 
40+ 
41+         This method should only be used for items that are not yet tracked. 
42+ 
43+         Args: 
44+             item_id: The unique identifier for the new product. 
45+             name: The name of the new product. 
46+             price: The selling price of the new product. 
47+             quantity: The initial stock quantity of the new product. 
48+ 
49+         Raises: 
50+             KeyError: If an item with the given `item_id` already exists in the inventory. 
51+         """ 
52+         if  item_id  in  self .items :
53+             # throw error 
54+             print (f"item with { item_id }   already exists" )
55+         else :
56+             self .items [item_id ] =  WarehouseItem (
57+                 id = item_id ,
58+                 name = name ,
59+                 price = price ,
60+                 quantity = quantity 
61+             )
62+ 
63+     def  procure_item (self , item_id : str , quantity : int ):
64+         """Increases the stock quantity of an existing item in the inventory. 
65+ 
66+         This method is used when purchasing or receiving stock. For adding 
67+         a completely new product, use :meth:`add_new_item`. 
68+ 
69+         Args: 
70+             item_id: The ID of the existing item to increase stock for. 
71+             quantity: The amount to add to the current stock. 
72+ 
73+         Raises: 
74+             KeyError: If the `item_id` is not found in the inventory. 
75+             ValueError: If the `quantity` is less than or equal to zero. 
76+         """ 
77+         if  item_id  in  self .items :
78+             self .items [item_id ].quantity  +=  quantity 
79+         else :
80+             print (f"item with { item_id }   does not exist" )
81+ 
82+     def  sell_item (self , item_id : str , quantity : int ):
83+         """Reduces the stock of a specified item. 
84+ 
85+         Raises: 
86+             ValueError: If the `item_id` is not found or if the requested 
87+                         `quantity` is greater than the available stock. 
88+ 
89+         Args: 
90+             item_id: The ID of the item to be sold. 
91+             quantity: The amount to subtract from the stock. 
92+         """ 
93+         if  item_id  in  self .items :
94+             self .items [item_id ].quantity  -=  quantity 
95+         else :
96+             print (f"item with { item_id }   does not exist" )
97+ 
98+     def  find_item_by_id (self , item_id : str ) ->  WarehouseItem  |  None :
99+         """Retrieves an item from the inventory using its unique ID. 
100+ 
101+         Args: 
102+             item_id: The unique identifier of the item to find. 
103+ 
104+         Returns: 
105+             The matching :class:`WarehouseItem` object, or None if the item is not found. 
106+         """ 
107+         pass 
108+ 
109+     def  find_item_by_name (self , name : str ) ->  list [WarehouseItem ]:
110+         """Finds items in the inventory that match the given name. 
111+ 
112+         This method supports partial or case-insensitive matching. 
113+ 
114+         Args: 
115+             name: The name or partial name of the item to search for. 
116+ 
117+         Returns: 
118+             A list of matching :class:`WarehouseItem` objects. Returns an empty list 
119+             if no matches are found. 
120+         """ 
121+         pass 
0 commit comments