diff --git a/api/routers/__pycache__/stocks.cpython-313.pyc b/api/routers/__pycache__/stocks.cpython-313.pyc index e75b551..d2f120b 100644 Binary files a/api/routers/__pycache__/stocks.cpython-313.pyc and b/api/routers/__pycache__/stocks.cpython-313.pyc differ diff --git a/api/routers/__pycache__/toolkit.cpython-313.pyc b/api/routers/__pycache__/toolkit.cpython-313.pyc index f6e933b..660a310 100644 Binary files a/api/routers/__pycache__/toolkit.cpython-313.pyc and b/api/routers/__pycache__/toolkit.cpython-313.pyc differ diff --git a/api/routers/stocks.py b/api/routers/stocks.py index 8a9d990..a5cb75c 100644 --- a/api/routers/stocks.py +++ b/api/routers/stocks.py @@ -49,14 +49,20 @@ async def post_requests( action = request_data.get("body").get("action").get("operation") logger.info(f"Получение запроса на перемещение ({action}) инструмента") userId = request_data.get("body").get("userData").get("id") - sourceTollboxId = ( + sourceTollboxId = int( request_data.get("body").get("action").get("selectedItem").get("toolboxId") ) - toolkitId = request_data.get("body").get("action").get("selectedItem").get("id") + toolkitId = int( + request_data.get("body").get("action").get("selectedItem").get("id") + ) quantity = request_data.get("body").get("action").get("quantity") price = round( - request_data.get("body").get("action").get("selectedItem").get("totalCost") - / request_data.get("body").get("action").get("selectedItem").get("available"), + float( + request_data.get("body").get("action").get("selectedItem").get("totalCost") + ) + / int( + request_data.get("body").get("action").get("selectedItem").get("available") + ), 2, ) reason = request_data.get("body").get("action").get("comment") @@ -78,6 +84,7 @@ async def post_requests( if result: resonse["status"] = "ok" case "get": + logger.info(f"Получение инструмента {toolkitId} из ящика {sourceTollboxId}") targetTollboxId = await ToolboxHandler.getIdByOwner(userId) result = await StocksActions.takeToolkit( sourceTollboxId, diff --git a/api/routers/toolkit.py b/api/routers/toolkit.py index b3cf6e5..a519130 100644 --- a/api/routers/toolkit.py +++ b/api/routers/toolkit.py @@ -28,6 +28,7 @@ async def toolkit_request( if not toolboxes: return response toolboxesTitles = {toolbox["id"]: toolbox["title"] for toolbox in toolboxes} + toolboxesOwners = {toolbox["id"]: toolbox["owner_id"] for toolbox in toolboxes} stocksData = {"count": 0, "toolboxes": {}} for stock in stocks: toolboxTitle = toolboxesTitles.get(stock["toolbox_id"], None) @@ -39,8 +40,18 @@ async def toolkit_request( "count": stock["quantity"], "placement": stock["placement"], } + logger.info(stock.keys()) + if not toolboxesOwners.get(stock["toolbox_id"]): + stocksData["toolboxes"][toolboxTitle]["id"] = stock["toolbox_id"] + stocksData["toolboxes"][toolboxTitle]["totalCost"] = ( + stock["price"] * stock["quantity"] + ) else: stocksData["toolboxes"][toolboxTitle]["count"] += stock["quantity"] + if not toolboxesOwners.get(stock["toolbox_id"]): + stocksData["toolboxes"][toolboxTitle]["totalCost"] += ( + stock["price"] * stock["quantity"] + ) response["status"] = "ok" response["data"] = stocksData return response diff --git a/api/static/js/index.js b/api/static/js/index.js index c21c8e5..4f61fea 100644 --- a/api/static/js/index.js +++ b/api/static/js/index.js @@ -1732,7 +1732,15 @@ async function showToolkitDetailsModal(item) { ${Object.entries(toolkitStocks.toolboxes).map(([key, value]) => ` ${key}: - ${value.count} шт. + ${value.count} шт.${value.id && accessData.available_own_toolbox ? ` + + ` : ''} + ${value.placement || ''} `).join('')} @@ -1754,6 +1762,24 @@ async function showToolkitDetailsModal(item) { `; + // Добавляем обработчики для кнопок в строке + modal.querySelectorAll('button[data-action]').forEach(button => { + button.addEventListener('click', async (e) => { + e.stopPropagation(); + const action = e.currentTarget.dataset.action; + const id = e.currentTarget.dataset.id; + const toolboxId = e.currentTarget.dataset.toolbox_id; + const available = e.currentTarget.dataset.available; + const totalQuantity = available; + const title = item.title; + const totalCost = e.currentTarget.dataset.totalcost; + const skipRefresh = true; + const selectedItem = { id, toolboxId, available, totalQuantity, title, totalCost, skipRefresh }; + await showOperationModal(action, selectedItem); + modal.querySelector('button[data-bs-dismiss="modal"]').click(); + }); + }); + document.body.appendChild(modal); const bsModal = new bootstrap.Modal(modal); @@ -1874,7 +1900,9 @@ async function showOperationModal(operation, selectedItem) { if (success) { bsModal.hide(); showInfo(`Запрос на ${operationTitles[operation]} успешно создан`, 'success'); - await loadToolboxContent(selectedItem.toolboxId); + if (!selectedItem.skipRefresh) { + await loadToolboxContent(selectedItem.toolboxId); + } } else { showError('Ошибка выполнения операции'); resetButton();