|
@@ -0,0 +1,80 @@
|
|
|
+import datetime
|
|
|
+from src.errors.argument_exception import argument_exception
|
|
|
+from src.models.transaction_model import transaction_model
|
|
|
+from src.storage.storage_prototype import storage_prototype
|
|
|
+from src.export.exporter_factory import exporter_factory
|
|
|
+from src.logic.process_factory import process_factory
|
|
|
+from src.storage.storage import storage
|
|
|
+from src.validation.validator import validator
|
|
|
+import json
|
|
|
+
|
|
|
+
|
|
|
+class storage_service:
|
|
|
+ __data = []
|
|
|
+
|
|
|
+ def __init__(self, data: list):
|
|
|
+ self.__data = data
|
|
|
+ self.__vtor = validator()
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def create_response(data, app):
|
|
|
+ """Создать JSON"""
|
|
|
+ data = exporter_factory().create("json").export_models(data)
|
|
|
+ data = json.dumps(data, indent=4, ensure_ascii=False)
|
|
|
+
|
|
|
+ result = app.response_class(
|
|
|
+ response=data, status=200, mimetype="application/json; charset=utf-8"
|
|
|
+ )
|
|
|
+ return result
|
|
|
+
|
|
|
+ def create_turns_nomen(self, strg, nomen, **kwargs):
|
|
|
+ """Отфильтровать по номенклатуре"""
|
|
|
+ prototype = storage_prototype(self.__data)
|
|
|
+ transactions = prototype.filter_nom(nomen).data
|
|
|
+ processing = process_factory().create(storage.process_turn_key(), strg)
|
|
|
+ rests = processing.create(transactions)
|
|
|
+ return rests
|
|
|
+
|
|
|
+ def create_turns_dt(self, strg, from_dt, to_dt, **kwargs):
|
|
|
+ """Отфильтровать по временному диапазону"""
|
|
|
+ prototype = storage_prototype(self.__data)
|
|
|
+ transactions = prototype.filter_dt(from_dt, to_dt).data
|
|
|
+ processing = process_factory().create(storage.process_turn_key(), strg)
|
|
|
+ rests = processing.create(transactions)
|
|
|
+ return rests
|
|
|
+
|
|
|
+ def create_turns_recipe(self, strg, recipe, **kwargs):
|
|
|
+ """Отфильтровать по рецепту"""
|
|
|
+ prototype = storage_prototype(self.__data)
|
|
|
+ transactions = prototype.filter_recipe(recipe).data
|
|
|
+ processing = process_factory().create(storage.process_turn_key(), strg)
|
|
|
+ rests = processing.create(transactions)
|
|
|
+ return rests
|
|
|
+
|
|
|
+ def take_recipe(self, recipe, turns, storage_, strg):
|
|
|
+ recipe_need = {}
|
|
|
+ for recipe_row in recipe.rows:
|
|
|
+ recipe_need[recipe_row.nomenclature.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(),
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ strg.data[storage.transaction_key()] += transactions
|
|
|
+
|
|
|
+ @property
|
|
|
+ def data(self) -> list:
|
|
|
+ return self.__data
|