|
@@ -1,12 +1,15 @@
|
|
|
+from datetime import datetime
|
|
|
+import json
|
|
|
import os
|
|
|
-import sys
|
|
|
-from flask import Flask
|
|
|
+from flask import Flask, request
|
|
|
+from src.models.transaction_model import transaction_model
|
|
|
from src.errors.argument_exception import argument_exception
|
|
|
from src.export.exporter_factory import exporter_factory
|
|
|
|
|
|
from src.settings.settings_manager import settings_manager
|
|
|
from src.logic.start_factory import start_factory
|
|
|
from src.storage.storage import storage
|
|
|
+from src.storage.storage_service import storage_service
|
|
|
|
|
|
|
|
|
setman = settings_manager()
|
|
@@ -54,6 +57,91 @@ def get_export(storage_key: str):
|
|
|
)
|
|
|
|
|
|
|
|
|
+@app.route("/api/export/rests", methods=["GET"])
|
|
|
+def get_rests():
|
|
|
+ args = request.args
|
|
|
+ if "start_period" not in args.keys() or "stop_period" not in args.keys():
|
|
|
+ raise argument_exception("Нет дат!")
|
|
|
+
|
|
|
+ start_date = datetime.strptime(args["start_period"], "%Y-%m-%d")
|
|
|
+ stop_date = datetime.strptime(args["stop_period"], "%Y-%m-%d")
|
|
|
+
|
|
|
+ service = storage_service(start.storage.data[storage.transaction_key()])
|
|
|
+ result = service.create_turns_dt(strg, start_date, stop_date, strg)
|
|
|
+
|
|
|
+ return storage_service.create_response(result, app)
|
|
|
+
|
|
|
+
|
|
|
+@app.route("/api/storage/<nomenclature_name>/turns")
|
|
|
+def get_nomens_rests(nomenclature_name):
|
|
|
+ nomen = [
|
|
|
+ nomen
|
|
|
+ for nomen in start.storage.data[storage.nomenclature_key()]
|
|
|
+ if nomen.name == nomenclature_name
|
|
|
+ ][0]
|
|
|
+
|
|
|
+ service = storage_service(start.storage.data[storage.transaction_key()])
|
|
|
+ result = service.create_turns_nomen(strg, nomen)
|
|
|
+
|
|
|
+ return storage_service.create_response(result, app)
|
|
|
+
|
|
|
+
|
|
|
+@app.route("/api/storage/<recipe_name>/debits")
|
|
|
+def debits_recipe(recipe_name):
|
|
|
+ args = request.args
|
|
|
+ if "storage" not in args:
|
|
|
+ raise argument_exception("Не указан склад!")
|
|
|
+
|
|
|
+ recipe = [
|
|
|
+ recipe
|
|
|
+ for recipe in start.storage.data[storage.recipe_key()]
|
|
|
+ if recipe.name == recipe_name
|
|
|
+ ]
|
|
|
+ storage_ = [
|
|
|
+ storage
|
|
|
+ for storage in start.storage.data[storage.storage_key()]
|
|
|
+ if storage.name == args["storage"]
|
|
|
+ ]
|
|
|
+
|
|
|
+ if len(recipe) == 0 or len(storage_) == 0:
|
|
|
+ return ""
|
|
|
+
|
|
|
+ recipe = recipe[0]
|
|
|
+ storage_ = storage_[0]
|
|
|
+
|
|
|
+ service = storage_service(start.storage.data[storage.transaction_key()])
|
|
|
+ turns = service.create_turns(recipe, storage=storage_)
|
|
|
+
|
|
|
+ recipe_need = {}
|
|
|
+ for recipe_row in recipe.rows:
|
|
|
+ recipe_need[recipe_row.nomenculature.name] = recipe_row.size
|
|
|
+
|
|
|
+ transactions = []
|
|
|
+ for turn in turns:
|
|
|
+ if recipe_need[turn.nomen.name] > turn.remains:
|
|
|
+ raise argument_exception(
|
|
|
+ "Не удалось произвести списание! Остатков на складе не достаточно!"
|
|
|
+ )
|
|
|
+ transactions.append(
|
|
|
+ transaction_model(
|
|
|
+ storage=storage_,
|
|
|
+ nomen=turn.nomen,
|
|
|
+ operation=False,
|
|
|
+ countes=recipe_need[turn.nomen.name],
|
|
|
+ unit=turn.unit,
|
|
|
+ period=datetime.now(),
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ start.storage.data[storage.journal_key()] += transactions
|
|
|
+
|
|
|
+ return app.response_class(
|
|
|
+ response=json.dumps({"success": True}),
|
|
|
+ status=200,
|
|
|
+ mimetype="application/json; charset=utf-8",
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
# Инициализация приложения
|
|
|
def run():
|
|
|
global setman, start, strg
|