Загрузка данных


Ноутбук;75000;2023;10
Мышь;1200;2024;50
Клавиатура;3500;2023;25
Монитор;22000;2022;8
Принтер;18000;2023;3


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")
lines = file.readlines()
file.close()

warehouse = Warehouse()

for line in lines:
    parts = line.strip().split(";")
    if len(parts) == 4:
        name = parts[0]
        price = float(parts[1])
        year = int(parts[2])
        quantity = int(parts[3])
        warehouse.add(Product(name, price, year, 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} шт.")