Browse Source

Created logic for taking items for recipe to storage_service

Vsevolod Levitan 1 year ago
parent
commit
c79390636e
2 changed files with 28 additions and 22 deletions
  1. 1 22
      main.py
  2. 27 0
      src/storage/storage_service.py

+ 1 - 22
main.py

@@ -117,28 +117,7 @@ def debits_recipe(recipe_name):
     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.transaction_key()] += transactions
+    service.take_recipe(recipe, turns, storage_, strg)
 
     return app.response_class(
         response=json.dumps({"success": True}),

+ 27 - 0
src/storage/storage_service.py

@@ -1,3 +1,6 @@
+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
@@ -48,6 +51,30 @@ class storage_service:
         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