Skip to content

Commit c9fda6c

Browse files
Added warehouse
1 parent b617628 commit c9fda6c

File tree

8 files changed

+179
-0
lines changed

8 files changed

+179
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

Sep25/projects/approach2/warehouse/README.md

Whitespace-only changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[project]
2+
name = "warehouse"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
authors = [
7+
{ name = "shaikkhajaibrahim", email = "shaikkhajaibrahim@gmail.com" }
8+
]
9+
requires-python = ">=3.13"
10+
dependencies = []
11+
12+
[project.scripts]
13+
warehouse = "warehouse:main"
14+
15+
[build-system]
16+
requires = ["uv_build>=0.9.3,<0.10.0"]
17+
build-backend = "uv_build"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main() -> None:
2+
print("Hello from warehouse!")

Sep25/projects/approach2/warehouse/src/warehouse/core/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""This module will have entities defined used for the package
2+
"""
3+
4+
from dataclasses import dataclass
5+
6+
7+
@dataclass
8+
class Product:
9+
"""Represents a generic product.
10+
11+
Attributes:
12+
id: A unique identifier for the product.
13+
name: The name of the product.
14+
price: The selling price of the product.
15+
"""
16+
id: str
17+
name: str
18+
price: float
19+
20+
21+
@dataclass
22+
class WarehouseItem(Product):
23+
"""Represents an item stored in a warehouse.
24+
25+
Inherits attributes from :class:`Product` and adds inventory information.
26+
27+
Attributes:
28+
quantity: The current stock quantity of the item in the warehouse.
29+
"""
30+
quantity: int
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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

Sep25/projects/approach2/warehouse/uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)