работа с перемещением и списанием
This commit is contained in:
+31
-4
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user