channel-app 0.0.131__py3-none-any.whl → 0.0.135__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.
Files changed (61) hide show
  1. channel_app/app/product/service.py +16 -0
  2. channel_app/core/commands.py +3 -1
  3. channel_app/core/tests.py +15 -164
  4. channel_app/omnitron/commands/tests/test_products.py +494 -0
  5. {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/METADATA +1 -1
  6. channel_app-0.0.135.dist-info/RECORD +60 -0
  7. {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/WHEEL +1 -1
  8. channel_app/channel_app/app/__init__.py +0 -0
  9. channel_app/channel_app/app/order/__init__.py +0 -0
  10. channel_app/channel_app/app/order/service.py +0 -230
  11. channel_app/channel_app/app/product/__init__.py +0 -0
  12. channel_app/channel_app/app/product/service.py +0 -237
  13. channel_app/channel_app/app/product_price/__init__.py +0 -0
  14. channel_app/channel_app/app/product_price/service.py +0 -254
  15. channel_app/channel_app/app/product_stock/__init__.py +0 -0
  16. channel_app/channel_app/app/product_stock/service.py +0 -258
  17. channel_app/channel_app/app/setup/__init__.py +0 -0
  18. channel_app/channel_app/app/setup/service.py +0 -61
  19. channel_app/channel_app/channel/__init__.py +0 -0
  20. channel_app/channel_app/channel/commands/__init__.py +0 -0
  21. channel_app/channel_app/channel/commands/orders/__init__.py +0 -0
  22. channel_app/channel_app/channel/commands/orders/orders.py +0 -329
  23. channel_app/channel_app/channel/commands/product_categories.py +0 -1
  24. channel_app/channel_app/channel/commands/product_images.py +0 -1
  25. channel_app/channel_app/channel/commands/product_prices.py +0 -148
  26. channel_app/channel_app/channel/commands/product_stocks.py +0 -220
  27. channel_app/channel_app/channel/commands/products.py +0 -161
  28. channel_app/channel_app/channel/commands/setup.py +0 -948
  29. channel_app/channel_app/channel/integration.py +0 -84
  30. channel_app/channel_app/core/__init__.py +0 -0
  31. channel_app/channel_app/core/clients.py +0 -12
  32. channel_app/channel_app/core/commands.py +0 -364
  33. channel_app/channel_app/core/data.py +0 -227
  34. channel_app/channel_app/core/integration.py +0 -74
  35. channel_app/channel_app/core/products.py +0 -64
  36. channel_app/channel_app/core/settings.py +0 -28
  37. channel_app/channel_app/core/utilities.py +0 -99
  38. channel_app/channel_app/omnitron/__init__.py +0 -0
  39. channel_app/channel_app/omnitron/batch_request.py +0 -82
  40. channel_app/channel_app/omnitron/commands/__init__.py +0 -0
  41. channel_app/channel_app/omnitron/commands/batch_requests.py +0 -281
  42. channel_app/channel_app/omnitron/commands/error_reports.py +0 -86
  43. channel_app/channel_app/omnitron/commands/integration_actions.py +0 -200
  44. channel_app/channel_app/omnitron/commands/orders/__init__.py +0 -0
  45. channel_app/channel_app/omnitron/commands/orders/addresses.py +0 -242
  46. channel_app/channel_app/omnitron/commands/orders/cargo_companies.py +0 -40
  47. channel_app/channel_app/omnitron/commands/orders/customers.py +0 -72
  48. channel_app/channel_app/omnitron/commands/orders/orders.py +0 -450
  49. channel_app/channel_app/omnitron/commands/product_categories.py +0 -1
  50. channel_app/channel_app/omnitron/commands/product_images.py +0 -1
  51. channel_app/channel_app/omnitron/commands/product_prices.py +0 -192
  52. channel_app/channel_app/omnitron/commands/product_stocks.py +0 -229
  53. channel_app/channel_app/omnitron/commands/products.py +0 -735
  54. channel_app/channel_app/omnitron/commands/setup.py +0 -839
  55. channel_app/channel_app/omnitron/constants.py +0 -98
  56. channel_app/channel_app/omnitron/exceptions.py +0 -42
  57. channel_app/channel_app/omnitron/integration.py +0 -159
  58. channel_app/setup.py +0 -21
  59. channel_app-0.0.131.dist-info/RECORD +0 -110
  60. /channel_app/{channel_app → omnitron/commands/tests}/__init__.py +0 -0
  61. {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/top_level.txt +0 -0
@@ -1,229 +0,0 @@
1
- from typing import List
2
-
3
- from omnisdk.omnitron.endpoints import (ChannelProductStockEndpoint,
4
- ChannelIntegrationActionEndpoint,
5
- ChannelBatchRequestEndpoint,
6
- ChannelExtraProductStockEndpoint)
7
- from omnisdk.omnitron.models import ProductStock
8
-
9
- from channel_app.core.commands import OmnitronCommandInterface
10
- from channel_app.core.data import BatchRequestResponseDto
11
- from channel_app.omnitron.commands.batch_requests import ProcessBatchRequests
12
- from channel_app.omnitron.constants import (ContentType, BatchRequestStatus,
13
- IntegrationActionStatus,
14
- FailedReasonType)
15
-
16
-
17
- class GetUpdatedProductStocks(OmnitronCommandInterface):
18
- """
19
- Fetches updated and not sent stock objects from Omnitron
20
-
21
- Batch request state transition to fail or done
22
- :return: List[ProductStock] as output of do_action
23
- """
24
- endpoint = ChannelProductStockEndpoint
25
- path = "updates"
26
- BATCH_SIZE = 100
27
- content_type = ContentType.product_stock.value
28
-
29
- def get_data(self) -> List[ProductStock]:
30
- stocks = self.get_product_stocks()
31
- stocks = self.get_stocks_with_available(stocks)
32
- return stocks
33
-
34
- def get_product_stocks(self) -> List[ProductStock]:
35
- stocks = self.endpoint(
36
- path=self.path,
37
- channel_id=self.integration.channel_id
38
- ).list(
39
- params={"limit": self.BATCH_SIZE}
40
- )
41
- stocks = stocks[:self.BATCH_SIZE]
42
- objects_data = self.create_batch_objects(data=stocks,
43
- content_type=self.content_type)
44
- self.update_batch_request(objects_data=objects_data)
45
- return stocks
46
-
47
- def get_stocks_with_available(self, stocks: List[ProductStock]):
48
- endpoint = ChannelIntegrationActionEndpoint(
49
- channel_id=self.integration.channel_id)
50
- stock_integration_actions = endpoint.list(
51
- params={
52
- "local_batch_id": self.integration.batch_request.local_batch_id,
53
- "status": IntegrationActionStatus.processing,
54
- "channel_id": self.integration.channel_id
55
- })
56
- for stock_batch in endpoint.iterator:
57
- stock_integration_actions.extend(stock_batch)
58
- stock_ia_dict = {ia.object_id: ia for ia in stock_integration_actions}
59
- for stock in stocks:
60
- stock_ia = stock_ia_dict[stock.pk]
61
- stock.remote_id = stock_ia.remote_id
62
- return stocks
63
-
64
-
65
- class GetUpdatedProductStocksFromExtraStockList(OmnitronCommandInterface):
66
- """
67
- Fetches updated and not sent stock objects from Omnitron
68
-
69
- Batch request state transition to fail or done
70
- :return: List[ProductStock] as output of do_action
71
- """
72
- endpoint = ChannelExtraProductStockEndpoint
73
- path = "updates"
74
- BATCH_SIZE = 100
75
- content_type = ContentType.product_stock.value
76
-
77
- def get_data(self) -> List[ProductStock]:
78
- self.stock_list_id = self.objects
79
- stocks = self.get_product_stocks()
80
- stocks = self.get_integration_actions(stocks)
81
- return stocks
82
-
83
- def get_product_stocks(self) -> List[ProductStock]:
84
- endpoint = self.endpoint(path=self.path,
85
- channel_id=self.integration.channel_id)
86
- stocks = endpoint.list(
87
- params={"stock_list": self.stock_list_id}
88
- )
89
- for stock_batch in endpoint.iterator:
90
- stocks.extend(stock_batch)
91
- if len(stocks) >= self.BATCH_SIZE:
92
- break
93
- stocks = stocks[:self.BATCH_SIZE]
94
- objects_data = self.create_batch_objects(data=stocks,
95
- content_type=self.content_type)
96
- self.update_batch_request(objects_data=objects_data)
97
- return stocks
98
-
99
- def get_integration_actions(self, stocks: List[ProductStock]):
100
- if not stocks:
101
- return []
102
- endpoint = ChannelIntegrationActionEndpoint(
103
- channel_id=self.integration.channel_id)
104
- stock_integration_actions = endpoint.list(
105
- params={
106
- "local_batch_id": self.integration.batch_request.local_batch_id,
107
- "status": IntegrationActionStatus.processing
108
- })
109
- for stock_batch in endpoint.iterator:
110
- stock_integration_actions.extend(stock_batch)
111
- stock_ia_dict = {ia.object_id: ia for ia in stock_integration_actions}
112
- for stock in stocks:
113
- stock_ia = stock_ia_dict[stock.pk]
114
- stock.remote_id = stock_ia.remote_id
115
- return stocks
116
-
117
-
118
- class GetInsertedProductStocksFromExtraStockList(
119
- GetUpdatedProductStocksFromExtraStockList):
120
- """
121
- Fetches updated and not sent stock objects from Omnitron
122
-
123
- Batch request state transition to fail or done
124
- :return: List[ProductStock] as output of do_action
125
- """
126
- path = "inserts"
127
-
128
-
129
- class GetInsertedProductStocks(GetUpdatedProductStocks):
130
- """
131
- Fetches inserted stock data from Omnitron.
132
-
133
- Batch request state transition to fail or done
134
-
135
- :return: List[ProductStock] as output of do_action
136
- """
137
- path = "inserts"
138
-
139
- def get_stocks_with_available(self, stocks: List[ProductStock]):
140
- endpoint = ChannelIntegrationActionEndpoint(
141
- channel_id=self.integration.channel_id)
142
- product_ids = [str(stock.product) for stock in stocks]
143
- product_ias = endpoint.list(
144
- params={"object_id__in": ",".join(product_ids),
145
- "content_type_name": ContentType.product.value,
146
- "status": IntegrationActionStatus.success,
147
- "channel_id": self.integration.channel_id,
148
- })
149
- for product_batch in endpoint.iterator:
150
- product_ias.extend(product_batch)
151
- product_integrations_by_id = {ia.object_id: ia for ia in product_ias}
152
-
153
- for stock in stocks:
154
- if stock.product in product_integrations_by_id:
155
- product_ia = product_integrations_by_id[stock.product]
156
- stock.remote_id = product_ia.remote_id
157
- else:
158
- stock.failed_reason_type = FailedReasonType.channel_app.value
159
- self.failed_object_list.append(
160
- (stock, ContentType.product_stock.value,
161
- "Product has not been sent"))
162
- return stocks
163
-
164
-
165
- class ProcessStockBatchRequests(OmnitronCommandInterface, ProcessBatchRequests):
166
- """
167
- Processes response of the channel for the stock update/insert task.
168
- It updates the stock and related model integration action data according to the
169
- channel response.
170
-
171
- As input;
172
-
173
- objects : List[BatchRequestResponseDto]. Represents channel response for the
174
- stock items that are in the BatchRequest.
175
-
176
- batch_request: If related batch request is not supplied, Omnitron will not
177
- be notified of the results.
178
- omnitron_integration.batch_request = batch_request
179
-
180
- Batch Request state transition to fail or done
181
-
182
- :return: None
183
- """
184
- endpoint = ChannelBatchRequestEndpoint
185
- content_type = ContentType.product_stock.value
186
- CHUNK_SIZE = 50
187
- BATCH_SIZE = 100
188
-
189
- def get_data(self):
190
- return self.objects
191
-
192
- def validated_data(self, data: List[BatchRequestResponseDto]):
193
- for item in data:
194
- assert isinstance(item, BatchRequestResponseDto)
195
- return data
196
-
197
- def send(self, validated_data):
198
- self.process_item(validated_data)
199
-
200
- @property
201
- def update_state(self, *args, **kwargs) -> BatchRequestStatus:
202
- return BatchRequestStatus.done
203
-
204
- def check_run(self, is_ok, formatted_data):
205
- if not is_ok and self.is_batch_request:
206
- self.integration.batch_request.objects = None
207
- self.batch_service(self.integration.channel_id).to_fail(
208
- self.integration.batch_request)
209
- return False
210
-
211
- def get_channel_items_by_reference_object_ids(self, channel_response,
212
- model_items_by_content,
213
- integration_actions):
214
- product_ids = [str(item) for item in
215
- model_items_by_content["productstock"]]
216
-
217
- model_items_by_content_product = self.get_products(product_ids)
218
-
219
- channel_items_by_product_id = {}
220
- for product_id, product in model_items_by_content_product.items():
221
- for channel_item in channel_response:
222
- # TODO: comment
223
- sku = self.get_barcode(obj=product)
224
- if channel_item.sku != sku:
225
- continue
226
- remote_item = channel_item
227
- channel_items_by_product_id[product_id] = remote_item
228
- break
229
- return channel_items_by_product_id