channel-app 0.0.157a11__py3-none-any.whl → 0.0.157a13__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.
@@ -32,7 +32,7 @@ class LogService:
32
32
  def create_flow(
33
33
  self,
34
34
  name: str,
35
- transaction_id: str,
35
+ transaction_id: str = None,
36
36
  flow_author: LogFlowAuthor = LogFlowAuthor.system,
37
37
  ):
38
38
  self.flow = {
@@ -43,6 +43,10 @@ class GetInsertedProducts(OmnitronCommandInterface):
43
43
 
44
44
  def get_products(self, limit: int) -> List[Product]:
45
45
  params = {"product_type": 0, "limit": limit}
46
+ initialized_params = getattr(self, "param_{}".format("params"), None)
47
+ if initialized_params:
48
+ params.update(initialized_params)
49
+
46
50
  language = getattr(self, "param_language", None)
47
51
  if language:
48
52
  products = self.endpoint(
File without changes
@@ -0,0 +1,184 @@
1
+ from decimal import Decimal
2
+ from typing import List
3
+ from channel_app.core.settings import OmnitronIntegration
4
+ from channel_app.logs.services import LogService
5
+ from channel_app.omnitron.integration import OmnitronIntegration as IOmnitronIntegration
6
+ from channel_app.omnitron.constants import ContentType
7
+ from omnisdk.omnitron.models import Product
8
+
9
+
10
+ class ReportService:
11
+ @staticmethod
12
+ def get_not_for_sale_products(limit: int = 10) -> List[Product]:
13
+ """
14
+ Get not for sale products from Omnitron API.
15
+ """
16
+
17
+ log_service = LogService()
18
+ log_service.create_flow(name="Get Not For Sale Products")
19
+
20
+ try:
21
+ with OmnitronIntegration(
22
+ content_type=ContentType.product.value,
23
+ ) as omnitron_integration:
24
+ omnitron_integration: IOmnitronIntegration
25
+
26
+ with log_service.step("get_not_for_sale_products"):
27
+ products: List[Product] = omnitron_integration.do_action(
28
+ key="get_inserted_products",
29
+ params={
30
+ "catalogitem__isnull": True,
31
+ },
32
+ objects={
33
+ "limit": limit,
34
+ },
35
+ )
36
+
37
+ return products
38
+ except Exception as fatal:
39
+ log_service.add_exception(fatal)
40
+ raise
41
+ finally:
42
+ log_service.save()
43
+
44
+ @staticmethod
45
+ def get_price_differences_from_products(marketplace_products: List[Product]):
46
+ """
47
+ Get price differences from products.
48
+ :param marketplace_products: List of products from marketplace
49
+ :return: List of products with price differences
50
+
51
+ marketplace_products: List[Product] = [
52
+ Product(
53
+ pk=1,
54
+ price=100.0,
55
+ sku="test-sku-1",
56
+ ...
57
+ ),
58
+ Product(
59
+ pk=3,
60
+ price=200.0,
61
+ sku="test-sku-2",
62
+ ...
63
+ ),
64
+ ]
65
+ """
66
+
67
+ log_service = LogService()
68
+ log_service.create_flow(name="Get Price Differences")
69
+
70
+ try:
71
+ with OmnitronIntegration(
72
+ content_type=ContentType.product_price.value,
73
+ ) as omnitron_integration:
74
+ omnitron_integration: IOmnitronIntegration
75
+
76
+ with log_service.step("get_product_prices"):
77
+ omnitron_products = omnitron_integration.do_action(
78
+ key="get_product_prices",
79
+ objects=marketplace_products,
80
+ )
81
+
82
+ with log_service.step("get_price_differences"):
83
+ differences = []
84
+ for omnitron_product in omnitron_products:
85
+ if omnitron_product.productprice is None:
86
+ continue
87
+
88
+ if omnitron_product.productprice.price is None:
89
+ continue
90
+
91
+ for marketplace_product in marketplace_products:
92
+ if omnitron_product.sku == marketplace_product.sku:
93
+ if Decimal(
94
+ omnitron_product.productprice.price
95
+ ) != Decimal(marketplace_product.price):
96
+ differences.append(
97
+ {
98
+ "product_pk": omnitron_product.pk,
99
+ "product_sku": omnitron_product.sku,
100
+ "price_difference": abs(
101
+ Decimal(
102
+ omnitron_product.productprice.price
103
+ )
104
+ - Decimal(marketplace_product.price)
105
+ ),
106
+ "updated_at": omnitron_product.productprice.modified_date,
107
+ }
108
+ )
109
+
110
+ return differences
111
+ except Exception as fatal:
112
+ log_service.add_exception(fatal)
113
+ raise
114
+ finally:
115
+ log_service.save()
116
+
117
+ @staticmethod
118
+ def get_stock_differences_from_products(marketplace_products: List[Product]):
119
+ """
120
+ Get stock differences from products.
121
+ :param marketplace_products: List of products from marketplace
122
+ :return: List of products with stock differences
123
+
124
+ marketplace_products: List[Product] = [
125
+ Product(
126
+ pk=1,
127
+ stock=100,
128
+ sku="test-sku-1",
129
+ ...
130
+ ),
131
+ Product(
132
+ pk=3,
133
+ stock=200,
134
+ sku="test-sku-2",
135
+ ...
136
+ ),
137
+ ]
138
+ """
139
+ log_service = LogService()
140
+ log_service.create_flow(name="Get Stock Differences")
141
+
142
+ try:
143
+ with OmnitronIntegration(
144
+ content_type=ContentType.product_stock.value,
145
+ ) as omnitron_integration:
146
+ omnitron_integration: IOmnitronIntegration
147
+
148
+ with log_service.step("get_product_stocks"):
149
+ omnitron_products = omnitron_integration.do_action(
150
+ key="get_product_stocks",
151
+ objects=marketplace_products,
152
+ )
153
+
154
+ with log_service.step("get_stock_differences"):
155
+ differences = []
156
+ for omnitron_product in omnitron_products:
157
+ if omnitron_product.productstock is None:
158
+ continue
159
+
160
+ if omnitron_product.productstock.stock is None:
161
+ continue
162
+
163
+ for marketplace_product in marketplace_products:
164
+ if omnitron_product.sku == marketplace_product.sku:
165
+ if int(omnitron_product.productstock.stock) != int(
166
+ marketplace_product.stock
167
+ ):
168
+ differences.append(
169
+ {
170
+ "product_pk": omnitron_product.pk,
171
+ "product_sku": omnitron_product.sku,
172
+ "stock_difference": abs(
173
+ int(omnitron_product.productstock.stock)
174
+ - int(marketplace_product.stock)
175
+ ),
176
+ "updated_at": omnitron_product.productstock.modified_date,
177
+ }
178
+ )
179
+ return differences
180
+ except Exception as fatal:
181
+ log_service.add_exception(fatal)
182
+ raise
183
+ finally:
184
+ log_service.save()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: channel-app
3
- Version: 0.0.157a11
3
+ Version: 0.0.157a13
4
4
  Summary: Channel app for Sales Channels
5
5
  Home-page: https://github.com/akinon/channel_app
6
6
  Author: akinonteam
@@ -44,7 +44,7 @@ channel_app/database/migrations/versions/6d5ae5b9c541_create_initial_tables.py,s
44
44
  channel_app/logs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
45
45
  channel_app/logs/encoders.py,sha256=6CVgtkV7DrjxGpNXCJgT9bn9B2Ep0lHgtm-0ES7A57I,703
46
46
  channel_app/logs/enums.py,sha256=If6ZjwRTerbJypYI8WjdsleHR7FjlV-TP2nBppFVEc4,214
47
- channel_app/logs/services.py,sha256=ojW6gbYaF2AWt-NgnpEYbFSYUJL6KPZa_lqzQe7WdmI,7168
47
+ channel_app/logs/services.py,sha256=aHop-XqjWeuRXUsPLeH1UTWfxj1xmP2YEFX1W5wGW34,7175
48
48
  channel_app/omnitron/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  channel_app/omnitron/batch_request.py,sha256=S8IHtbI1RtVLbnOwtfXSmkrREGp8wUYW2E-eu5omwyY,3550
50
50
  channel_app/omnitron/constants.py,sha256=WZR6k_k2zZfN7lfi1ZLv1PphsHIq_LiZgw6Nd6LduvE,2793
@@ -58,7 +58,7 @@ channel_app/omnitron/commands/product_categories.py,sha256=XCYJ-G2qxytNNnixnPKHo
58
58
  channel_app/omnitron/commands/product_images.py,sha256=fwUntMOzRvcXrVbZ5Xd5O73w7K009jPakXqVdmWKOuk,5561
59
59
  channel_app/omnitron/commands/product_prices.py,sha256=HZ37Hw7YHKhZg7_kjSR-dNb0g2pz4WQAkcRHIwHLFvQ,12527
60
60
  channel_app/omnitron/commands/product_stocks.py,sha256=tX3EpTYg2Y-l7hwZjPYPk_eUmfAUoWomruUoP0pn9RU,13919
61
- channel_app/omnitron/commands/products.py,sha256=hzEedmOx5GRoPa69Clh5EYqm3Jxi1TuAxhwCngswHmw,32492
61
+ channel_app/omnitron/commands/products.py,sha256=SKqovPvmNG7mrJS_joFZF2mw-2JplHDQJ9XARUhzanA,32648
62
62
  channel_app/omnitron/commands/setup.py,sha256=dcbvvIFDKKeDVziwR2qWJhVd92IlVLEoYIbMrxKjWDE,35220
63
63
  channel_app/omnitron/commands/orders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
64
64
  channel_app/omnitron/commands/orders/addresses.py,sha256=crk4qwhGYBi6-jnJUQ7M7HloDAvaiGw_d3q40VcSR-E,12613
@@ -71,7 +71,9 @@ channel_app/omnitron/commands/tests/test_product_images.py,sha256=y6tmiJ00kd2GTq
71
71
  channel_app/omnitron/commands/tests/test_product_prices.py,sha256=5HPX9PmjGw6gk3oNrwtWLqdrOkfeNx1mYP-pYwOesZU,3496
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
- channel_app-0.0.157a11.dist-info/METADATA,sha256=-OeKhBxlGFeWqTLjnJIzCt1P1IgyK8WnTUvtLhICtec,442
75
- channel_app-0.0.157a11.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
76
- channel_app-0.0.157a11.dist-info/top_level.txt,sha256=JT-gM6L5Cwxr1xEoN7NHrREDs-d6iGFGfRnK-NrJ3tU,12
77
- channel_app-0.0.157a11.dist-info/RECORD,,
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,,