[
{"name": "Ноутбук", "price": 75000, "year": 2023, "quantity": 10},
{"name": "Мышь", "price": 1200, "year": 2024, "quantity": 50},
{"name": "Клавиатура", "price": 3500, "year": 2023, "quantity": 25},
{"name": "Монитор", "price": 22000, "year": 2022, "quantity": 8},
{"name": "Принтер", "price": 18000, "year": 2023, "quantity": 3}
]
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
return False
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_data = json.loads(content)
warehouse = Warehouse()
for item in products_data:
warehouse.add(Product(item["name"], item["price"], item["year"], item["quantity"]))
supply = Supply("Поставщик", [
Product("Ноутбук", 78000, 2024, 5),
Product("SSD", 8500, 2024, 15)
])
supply.apply(warehouse)
requests = [
Request("Ромашка", "Ноутбук", 3),
Request("Техносервис", "Принтер", 2),
Request("Иванов", "SSD", 20),
Request("Глобус", "Клавиатура", 10)
]
print("Склад:")
for p in warehouse.products:
print(f"{p.name} - {p.quantity} шт.")
print("\nОбработка заявок:")
for req in requests:
if req.process(warehouse):
print(f"{req.organization}: {req.product_name} x{req.quantity} - ВЫПОЛНЕНО")
else:
print(f"{req.organization}: {req.product_name} x{req.quantity} - ОТКАЗАНО")
print("\nСклад после заявок:")
for p in warehouse.products:
print(f"{p.name} - {p.quantity} шт.")