работа с перемещением и списанием

This commit is contained in:
2025-12-01 22:32:57 +03:00
parent dc85e7c0c9
commit f3213c696f
6 changed files with 404 additions and 13 deletions
+31 -4
View File
@@ -27,7 +27,7 @@ def filterQuantity(stocksData, filtered):
class StockHandler:
async def add(**kwargs):
async def add(**kwargs) -> dict:
newStock = await Stock(**kwargs).save()
logger.info(
f"Новая запись об инструменте {newStock.toolkit_data.title} на складе {newStock.toolbox_data.title} успешно создана"
@@ -40,14 +40,14 @@ class StockHandler:
stocks = await CRUD.read(select(Stock), all=True)
return filterQuantity(stocks, filtered)
async def get(stockId: int, filtered: bool = True):
async def get(stockId: int, filtered: bool = True, record: bool = False):
from db import CRUD
stock = await CRUD.read(select(Stock).where(Stock.id == stockId))
if not stock:
logger.error("Запись об остатках не найдена")
return {}
return filterQuantity(stock, filtered)
return filterQuantity(stock, filtered) if not record else stock
async def getByToolboxId(toolboxId: int, filtered: bool = True):
from db import CRUD
@@ -63,7 +63,34 @@ class StockHandler:
stocks = await CRUD.read(query, True)
return filterQuantity(stocks, filtered)
async def edit(stockId: int, **kwargs):
async def getByToolboxIdAndToolkitId(
toolboxId: int, toolkitId: int, filtered: bool = True
) -> list[dict]:
from db import CRUD
query = (
select(Stock)
.where(Stock.toolbox_id == toolboxId)
.where(Stock.toolkit_id == toolkitId)
)
stocks = await CRUD.read(query, True)
return filterQuantity(stocks, filtered)
async def getByToolboxIdAndToolkitIdAndQPrice(
toolboxId: int, toolkitId: int, price: float, filtered: bool = True
) -> list[dict]:
from db import CRUD
query = (
select(Stock)
.where(Stock.toolbox_id == toolboxId)
.where(Stock.toolkit_id == toolkitId)
.where(Stock.price == price)
)
stocks = await CRUD.read(query, True)
return filterQuantity(stocks, filtered)
async def edit(stockId: int, **kwargs) -> dict:
from db import CRUD
stock = await CRUD.read(select(Stock).where(Stock.id == stockId))