import json
class Product:
def __init__(self, name, price, year, quantity):
self.name = name
self.price = price
self.year = year
self.quantity = quantity
class Warehouse:
def __init__(self):
self.products = []
def add(self, product):
for p in self.products:
if p.name == product.name:
p.quantity += product.quantity
return
self.products.append(product)
def remove(self, name, quantity):
for p in self.products:
if p.name == name:
if p.quantity >= quantity:
p.quantity -= quantity
return True
else:
print("Ошибка. Такого продукта не существует")
return False
class Supply:
def __init__(self, supplier, products):
self.supplier = supplier
self.products = products
def apply(self, warehouse):
for p in self.products:
warehouse.add(p)
class Request:
def __init__(self, organization, product_name, quantity):
self.organization = organization
self.product_name = product_name
self.quantity = quantity
def process(self, warehouse):
return warehouse.remove(self.product_name, self.quantity)
file = open("products.txt", "r", encoding="utf-8")
content = file.read()
file.close()
products = json.loads(content)
warehouse = Warehouse()
for item in products:
warehouse.add(Product(item["name"], item["price"], item["year"], item["quantity"]))
supply = Supply("Поставщик", [
Product("Ноутбук", 78000, 2024, 6),
Product("SSD", 8500, 2024, 15)
])
supply.apply(warehouse)
requests = [
Request("Техносервис", "Принтер", 2),
Request("Иванов", "SSD", 20)
]
print("Склад:")
for p in warehouse.products:
print(f"{p.name} - {p.quantity}")