帮我添加一个库存管理
时间: 2024-02-03 21:11:33 浏览: 22
好的,库存管理一般包括以下几个方面:
1. 添加商品:可以通过输入商品名称、数量、价格等信息来添加商品到库存中。
2. 查询商品:可以通过关键词查询库存中的商品信息,如名称、编号、价格等。
3. 修改商品信息:可以对库存中的商品进行修改,如修改商品名称、数量、价格等信息。
4. 删除商品:可以将库存中的商品删除。
5. 库存统计:可以统计库存中的商品数量、总价值等信息。
下面是一个简单的库存管理的示例代码,你可以参考一下:
```
class Product:
def __init__(self, name: str, quantity: int, price: float):
self.name = name
self.quantity = quantity
self.price = price
class Inventory:
def __init__(self):
self.products = []
def add_product(self, product: Product):
self.products.append(product)
def remove_product(self, product: Product):
self.products.remove(product)
def search_product(self, keyword: str):
results = []
for product in self.products:
if keyword in product.name or keyword == str(product.quantity) or keyword == str(product.price):
results.append(product)
return results
def update_product(self, product: Product, new_name: str, new_quantity: int, new_price: float):
product.name = new_name
product.quantity = new_quantity
product.price = new_price
def inventory_summary(self):
total_quantity = sum([product.quantity for product in self.products])
total_value = sum([product.quantity * product.price for product in self.products])
return f"Total quantity: {total_quantity}, Total value: {total_value}"
# Example usage
inventory = Inventory()
# add products
product1 = Product("T-Shirt", 10, 20.0)
inventory.add_product(product1)
product2 = Product("Jeans", 5, 50.0)
inventory.add_product(product2)
# search products
results = inventory.search_product("T-Shirt")
print(results)
# update product
inventory.update_product(product1, "Shirt", 20, 30.0)
print(product1.name, product1.quantity, product1.price)
# remove product
inventory.remove_product(product2)
# inventory summary
summary = inventory.inventory_summary()
print(summary)
```
这只是一个简单的示例,你可以根据你的具体需求自定义相应的逻辑和功能。