channel-app 0.0.157a13__py3-none-any.whl → 0.0.157a14__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ from channel_app.core.settings import OmnitronIntegration
4
4
  from channel_app.logs.services import LogService
5
5
  from channel_app.omnitron.integration import OmnitronIntegration as IOmnitronIntegration
6
6
  from channel_app.omnitron.constants import ContentType
7
- from omnisdk.omnitron.models import Product
7
+ from omnisdk.omnitron.models import Product, ProductStock
8
8
 
9
9
 
10
10
  class ReportService:
@@ -182,3 +182,117 @@ class ReportService:
182
182
  raise
183
183
  finally:
184
184
  log_service.save()
185
+
186
+
187
+ class DashboardService:
188
+ @staticmethod
189
+ def get_total_sku_from_catalog(limit: int = 10) -> List[Product]:
190
+ """
191
+ Get total SKU from catalog.
192
+ """
193
+
194
+ log_service = LogService()
195
+ log_service.create_flow(name="Get Total SKU from Catalog")
196
+
197
+ try:
198
+ with OmnitronIntegration(
199
+ content_type=ContentType.product.value,
200
+ ) as omnitron_integration:
201
+ omnitron_integration: IOmnitronIntegration
202
+
203
+ with log_service.step("get_total_sku_from_catalog"):
204
+ products: List[Product] = omnitron_integration.do_action(
205
+ key="get_inserted_products",
206
+ objects={
207
+ "limit": limit,
208
+ },
209
+ )
210
+
211
+ return products
212
+ except Exception as fatal:
213
+ log_service.add_exception(fatal)
214
+ raise
215
+ finally:
216
+ log_service.save()
217
+
218
+ @staticmethod
219
+ def get_total_sku_on_sale_from_catalog(limit: int = 10) -> List[Product]:
220
+ """
221
+ Get total SKU on sale from catalog.
222
+ """
223
+
224
+ log_service = LogService()
225
+ log_service.create_flow(name="Get Total SKU on Sale from Catalog")
226
+
227
+ try:
228
+ with OmnitronIntegration(
229
+ content_type=ContentType.product.value,
230
+ ) as omnitron_integration:
231
+ omnitron_integration: IOmnitronIntegration
232
+
233
+ with log_service.step("get_total_sku_on_sale_from_catalog"):
234
+ products: List[Product] = omnitron_integration.do_action(
235
+ key="get_inserted_products",
236
+ params={
237
+ "catalogitem__isnull": False,
238
+ },
239
+ objects={
240
+ "limit": limit,
241
+ },
242
+ )
243
+
244
+ return products
245
+ except Exception as fatal:
246
+ log_service.add_exception(fatal)
247
+ raise
248
+ finally:
249
+ log_service.save()
250
+
251
+ @staticmethod
252
+ def get_product_stocks_from_catalog() -> List[ProductStock]:
253
+ """
254
+ Get product stocks from catalog.
255
+ """
256
+ log_service = LogService()
257
+ log_service.create_flow(name="Get Product Stocks from Catalog")
258
+
259
+ try:
260
+ with OmnitronIntegration(
261
+ content_type=ContentType.product_stock.value,
262
+ ) as omnitron_integration:
263
+ omnitron_integration: IOmnitronIntegration
264
+
265
+ with log_service.step("get_product_stocks_from_catalog"):
266
+ stocks = omnitron_integration.do_action(
267
+ key="get_product_stocks",
268
+ objects={
269
+ "limit": 9999,
270
+ },
271
+ )
272
+
273
+ return stocks
274
+ except Exception as fatal:
275
+ log_service.add_exception(fatal)
276
+ raise
277
+ finally:
278
+ log_service.save()
279
+
280
+ @staticmethod
281
+ def get_total_stock_from_product_stocks(product_stocks: List[ProductStock]) -> int:
282
+ """
283
+ Get total stock from catalog.
284
+ """
285
+ log_service = LogService()
286
+ log_service.create_flow(name="Get Total Stock from Catalog")
287
+
288
+ try:
289
+ total_stock = 0
290
+ for stock in product_stocks:
291
+ total_stock += stock.productstock.stock if stock.productstock else 0
292
+
293
+ return total_stock
294
+ except Exception as fatal:
295
+ log_service.add_exception(fatal)
296
+ raise
297
+ finally:
298
+ log_service.save()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: channel-app
3
- Version: 0.0.157a13
3
+ Version: 0.0.157a14
4
4
  Summary: Channel app for Sales Channels
5
5
  Home-page: https://github.com/akinon/channel_app
6
6
  Author: akinonteam
@@ -72,8 +72,8 @@ channel_app/omnitron/commands/tests/test_product_prices.py,sha256=5HPX9PmjGw6gk3
72
72
  channel_app/omnitron/commands/tests/test_product_stocks.py,sha256=q4RGlrCNUUJyN5CBL1fzrvdd4Q3xt816mbMRQT0XEd0,3496
73
73
  channel_app/omnitron/commands/tests/test_products.py,sha256=uj5KLaubY3XNu0hidOH-u-Djfboe81Hj7-lP--01Le0,103494
74
74
  channel_app/reports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
75
- channel_app/reports/services.py,sha256=9zN9UhBPPbgCxnhLGqoc-kBaCHlNp1iunvKBc8Si3C4,7247
76
- channel_app-0.0.157a13.dist-info/METADATA,sha256=Wx_oj1LfeOMQrgUg_HLbiYtgbC8kbWwansKznSzMaEY,442
77
- channel_app-0.0.157a13.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
78
- channel_app-0.0.157a13.dist-info/top_level.txt,sha256=JT-gM6L5Cwxr1xEoN7NHrREDs-d6iGFGfRnK-NrJ3tU,12
79
- channel_app-0.0.157a13.dist-info/RECORD,,
75
+ channel_app/reports/services.py,sha256=AxBBC_v3CKDAbbSaT7pY1tAwRi5htqg5PmLFg9yEBJE,10977
76
+ channel_app-0.0.157a14.dist-info/METADATA,sha256=ldOVtQLZMWO2QnqjR837cV5X8kgEGDyrZuoNP4_6LSk,442
77
+ channel_app-0.0.157a14.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
78
+ channel_app-0.0.157a14.dist-info/top_level.txt,sha256=JT-gM6L5Cwxr1xEoN7NHrREDs-d6iGFGfRnK-NrJ3tU,12
79
+ channel_app-0.0.157a14.dist-info/RECORD,,