channel-app 0.0.157a10__py3-none-any.whl → 0.0.157a12__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.
- channel_app/app/order/service.py +598 -364
- channel_app/app/product/service.py +392 -238
- channel_app/app/product_image/service.py +214 -134
- channel_app/app/product_price/service.py +390 -240
- channel_app/app/product_stock/service.py +285 -203
- channel_app/app/setup/service.py +133 -79
- channel_app/logs/services.py +1 -1
- {channel_app-0.0.157a10.dist-info → channel_app-0.0.157a12.dist-info}/METADATA +1 -1
- {channel_app-0.0.157a10.dist-info → channel_app-0.0.157a12.dist-info}/RECORD +11 -11
- {channel_app-0.0.157a10.dist-info → channel_app-0.0.157a12.dist-info}/WHEEL +0 -0
- {channel_app-0.0.157a10.dist-info → channel_app-0.0.157a12.dist-info}/top_level.txt +0 -0
@@ -1,12 +1,15 @@
|
|
1
1
|
from typing import List
|
2
2
|
|
3
|
-
from omnisdk.omnitron.models import (
|
4
|
-
|
3
|
+
from omnisdk.omnitron.models import (
|
4
|
+
Product,
|
5
|
+
IntegrationAction,
|
6
|
+
BatchRequest,
|
7
|
+
)
|
5
8
|
|
6
9
|
from channel_app.core import settings
|
7
|
-
from channel_app.core.data import
|
8
|
-
ErrorReportDto)
|
10
|
+
from channel_app.core.data import ProductBatchRequestResponseDto, ErrorReportDto
|
9
11
|
from channel_app.core.settings import OmnitronIntegration, ChannelIntegration
|
12
|
+
from channel_app.logs.services import LogService
|
10
13
|
from channel_app.omnitron.batch_request import ClientBatchRequest
|
11
14
|
from channel_app.omnitron.constants import ContentType
|
12
15
|
|
@@ -14,241 +17,392 @@ from channel_app.omnitron.constants import ContentType
|
|
14
17
|
class ProductService(object):
|
15
18
|
batch_service = ClientBatchRequest
|
16
19
|
|
17
|
-
def insert_products(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
20
|
+
def insert_products(
|
21
|
+
self,
|
22
|
+
add_mapped=True,
|
23
|
+
add_stock=True,
|
24
|
+
add_price=True,
|
25
|
+
add_categories=True,
|
26
|
+
is_sync=True,
|
27
|
+
is_success_log=True,
|
28
|
+
):
|
29
|
+
log_service = LogService()
|
30
|
+
log_service.create_flow(name="Insert Products")
|
31
|
+
|
32
|
+
try:
|
33
|
+
with log_service.step("insert_products"):
|
34
|
+
with OmnitronIntegration(
|
35
|
+
content_type=ContentType.product.value
|
36
|
+
) as omnitron_integration:
|
37
|
+
with log_service.step("get_inserted_products"):
|
38
|
+
products = omnitron_integration.do_action(
|
39
|
+
key="get_inserted_products"
|
40
|
+
)
|
41
|
+
|
42
|
+
first_product_count = len(products)
|
43
|
+
|
44
|
+
if add_mapped:
|
45
|
+
with log_service.step("get_mapped_products"):
|
46
|
+
products = products and omnitron_integration.do_action(
|
47
|
+
key="get_mapped_products", objects=products
|
48
|
+
)
|
49
|
+
|
50
|
+
if add_stock:
|
51
|
+
with log_service.step("get_product_stocks"):
|
52
|
+
products = products and omnitron_integration.do_action(
|
53
|
+
key="get_product_stocks", objects=products
|
54
|
+
)
|
55
|
+
|
56
|
+
if add_price:
|
57
|
+
with log_service.step("get_product_prices"):
|
58
|
+
products = products and omnitron_integration.do_action(
|
59
|
+
key="get_product_prices", objects=products
|
60
|
+
)
|
61
|
+
|
62
|
+
if add_categories:
|
63
|
+
with log_service.step("get_product_categories"):
|
64
|
+
products = products and omnitron_integration.do_action(
|
65
|
+
key="get_product_categories", objects=products
|
66
|
+
)
|
67
|
+
|
68
|
+
if not products:
|
69
|
+
if first_product_count:
|
70
|
+
omnitron_integration.batch_request.objects = None
|
71
|
+
|
72
|
+
with log_service.step("batch_to_fail"):
|
73
|
+
self.batch_service(
|
74
|
+
omnitron_integration.channel_id
|
75
|
+
).to_fail(omnitron_integration.batch_request)
|
76
|
+
|
77
|
+
return
|
78
|
+
|
79
|
+
products: List[Product]
|
80
|
+
|
81
|
+
with log_service.step("send_inserted_products"):
|
82
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
83
|
+
key="send_inserted_products",
|
84
|
+
objects=products,
|
85
|
+
batch_request=omnitron_integration.batch_request,
|
86
|
+
is_sync=is_sync,
|
87
|
+
)
|
88
|
+
|
89
|
+
# tips
|
90
|
+
response_data: List[ProductBatchRequestResponseDto]
|
91
|
+
reports: List[ErrorReportDto]
|
92
|
+
data: List[Product]
|
93
|
+
|
94
|
+
if not is_sync:
|
95
|
+
if reports[0].is_ok:
|
96
|
+
|
97
|
+
with log_service.step("batch_send_to_remote"):
|
98
|
+
self.batch_service(
|
99
|
+
settings.OMNITRON_CHANNEL_ID
|
100
|
+
).to_sent_to_remote(
|
101
|
+
batch_request=omnitron_integration.batch_request
|
102
|
+
)
|
103
|
+
else:
|
104
|
+
is_sync = True
|
105
|
+
|
106
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
107
|
+
for report in reports:
|
108
|
+
with log_service.step("create_error_report"):
|
109
|
+
omnitron_integration.do_action(
|
110
|
+
key="create_error_report", objects=report
|
111
|
+
)
|
112
|
+
|
113
|
+
if is_sync:
|
114
|
+
with log_service.step("process_product_batch_requests"):
|
115
|
+
omnitron_integration.do_action(
|
116
|
+
key="process_product_batch_requests",
|
117
|
+
objects=response_data,
|
118
|
+
)
|
119
|
+
except Exception as fatal:
|
120
|
+
log_service.add_exception(fatal)
|
121
|
+
raise
|
122
|
+
finally:
|
123
|
+
log_service.save()
|
124
|
+
|
125
|
+
def update_products(
|
126
|
+
self,
|
127
|
+
add_mapped=True,
|
128
|
+
add_stock=True,
|
129
|
+
add_price=True,
|
130
|
+
add_categories=True,
|
131
|
+
is_sync=True,
|
132
|
+
is_success_log=True,
|
133
|
+
):
|
134
|
+
log_service = LogService()
|
135
|
+
log_service.create_flow(name="Update Products")
|
136
|
+
|
137
|
+
try:
|
138
|
+
with log_service.step("update_products"):
|
139
|
+
with OmnitronIntegration(
|
140
|
+
content_type=ContentType.product.value
|
141
|
+
) as omnitron_integration:
|
142
|
+
with log_service.step("get_updated_products"):
|
143
|
+
products = omnitron_integration.do_action(
|
144
|
+
key="get_updated_products"
|
145
|
+
)
|
146
|
+
|
147
|
+
first_product_count = len(products)
|
148
|
+
|
149
|
+
if add_mapped:
|
150
|
+
with log_service.step("get_mapped_products"):
|
151
|
+
products = products and omnitron_integration.do_action(
|
152
|
+
key="get_mapped_products", objects=products
|
153
|
+
)
|
154
|
+
|
155
|
+
if add_stock:
|
156
|
+
with log_service.step("get_product_stocks"):
|
157
|
+
products = products and omnitron_integration.do_action(
|
158
|
+
key="get_product_stocks", objects=products
|
159
|
+
)
|
160
|
+
|
161
|
+
if add_price:
|
162
|
+
with log_service.step("get_product_prices"):
|
163
|
+
products = products and omnitron_integration.do_action(
|
164
|
+
key="get_product_prices", objects=products
|
165
|
+
)
|
166
|
+
|
167
|
+
if add_categories:
|
168
|
+
with log_service.step("get_product_categories"):
|
169
|
+
products = products and omnitron_integration.do_action(
|
170
|
+
key="get_product_categories", objects=products
|
171
|
+
)
|
172
|
+
|
173
|
+
if not products:
|
174
|
+
if first_product_count:
|
175
|
+
omnitron_integration.batch_request.objects = None
|
176
|
+
with log_service.step("batch_to_fail"):
|
177
|
+
self.batch_service(
|
178
|
+
omnitron_integration.channel_id
|
179
|
+
).to_fail(omnitron_integration.batch_request)
|
180
|
+
|
181
|
+
return
|
182
|
+
|
183
|
+
products: List[Product]
|
184
|
+
|
185
|
+
with log_service.step("send_updated_products"):
|
186
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
187
|
+
key="send_updated_products",
|
188
|
+
objects=products,
|
189
|
+
batch_request=omnitron_integration.batch_request,
|
190
|
+
is_sync=is_sync,
|
191
|
+
)
|
192
|
+
|
193
|
+
# tips
|
194
|
+
response_data: List[ProductBatchRequestResponseDto]
|
195
|
+
reports: List[ErrorReportDto]
|
196
|
+
data: List[Product]
|
197
|
+
|
198
|
+
if not is_sync:
|
199
|
+
if reports[0].is_ok:
|
200
|
+
with log_service.step("batch_send_to_remote"):
|
201
|
+
self.batch_service(
|
202
|
+
settings.OMNITRON_CHANNEL_ID
|
203
|
+
).to_sent_to_remote(
|
204
|
+
batch_request=omnitron_integration.batch_request
|
205
|
+
)
|
206
|
+
else:
|
207
|
+
is_sync = True
|
208
|
+
|
209
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
210
|
+
for report in reports:
|
211
|
+
with log_service.step("create_error_report"):
|
212
|
+
omnitron_integration.do_action(
|
213
|
+
key="create_error_report", objects=report
|
214
|
+
)
|
215
|
+
|
216
|
+
if is_sync:
|
217
|
+
with log_service.step("process_product_batch_requests"):
|
218
|
+
omnitron_integration.do_action(
|
219
|
+
key="process_product_batch_requests",
|
220
|
+
objects=response_data,
|
221
|
+
)
|
222
|
+
except Exception as fatal:
|
223
|
+
log_service.add_exception(fatal)
|
224
|
+
raise
|
225
|
+
finally:
|
226
|
+
log_service.save()
|
227
|
+
|
228
|
+
def delete_products(
|
229
|
+
self, is_sync=True, is_content_object=True, is_success_log=True
|
230
|
+
):
|
231
|
+
log_service = LogService()
|
232
|
+
log_service.create_flow("Delete Products")
|
233
|
+
|
234
|
+
try:
|
235
|
+
with log_service.step("delete_products"):
|
236
|
+
with OmnitronIntegration(
|
237
|
+
content_type=ContentType.integration_action.value
|
238
|
+
) as omnitron_integration:
|
239
|
+
with log_service.step("get_deleted_products"):
|
240
|
+
products_integration_action = omnitron_integration.do_action(
|
241
|
+
key="get_deleted_products"
|
242
|
+
)
|
243
|
+
if not products_integration_action:
|
244
|
+
return
|
245
|
+
|
246
|
+
with log_service.step("get_content_objects_from_integrations"):
|
247
|
+
products_integration_action = omnitron_integration.do_action(
|
248
|
+
key="get_content_objects_from_integrations",
|
249
|
+
objects=products_integration_action,
|
250
|
+
)
|
251
|
+
products_integration_action: List[IntegrationAction]
|
252
|
+
|
253
|
+
with log_service.step("send_deleted_products"):
|
254
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
255
|
+
key="send_deleted_products",
|
256
|
+
objects=products_integration_action,
|
257
|
+
batch_request=omnitron_integration.batch_request,
|
258
|
+
is_sync=is_sync,
|
259
|
+
)
|
260
|
+
|
261
|
+
# tips
|
262
|
+
response_data: List[ProductBatchRequestResponseDto]
|
263
|
+
reports: List[ErrorReportDto]
|
264
|
+
data: List[IntegrationAction]
|
265
|
+
|
266
|
+
if not is_sync:
|
267
|
+
if reports[0].is_ok:
|
268
|
+
with log_service.step("batch_to_commit"):
|
269
|
+
self.batch_service(
|
270
|
+
settings.OMNITRON_CHANNEL_ID
|
271
|
+
).to_commit(
|
272
|
+
batch_request=omnitron_integration.batch_request
|
273
|
+
)
|
274
|
+
with log_service.step("batch_send_to_remote"):
|
275
|
+
self.batch_service(
|
276
|
+
settings.OMNITRON_CHANNEL_ID
|
277
|
+
).to_sent_to_remote(
|
278
|
+
batch_request=omnitron_integration.batch_request
|
279
|
+
)
|
280
|
+
else:
|
281
|
+
is_sync = True
|
282
|
+
|
283
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
284
|
+
for report in reports:
|
285
|
+
with log_service.step("create_error_report"):
|
286
|
+
omnitron_integration.do_action(
|
287
|
+
key="create_error_report", objects=report
|
288
|
+
)
|
289
|
+
|
290
|
+
if is_sync:
|
291
|
+
with log_service.step("process_delete_product_batch_requests"):
|
292
|
+
omnitron_integration.do_action(
|
293
|
+
key="process_delete_product_batch_requests",
|
294
|
+
objects=response_data,
|
295
|
+
)
|
296
|
+
except Exception as fatal:
|
297
|
+
log_service.add_exception(fatal)
|
298
|
+
raise
|
299
|
+
finally:
|
300
|
+
log_service.save()
|
194
301
|
|
195
302
|
def get_delete_product_batch_requests(self, is_success_log=True):
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
303
|
+
log_service = LogService()
|
304
|
+
log_service.create_flow(name="Get Delete Product Batch Requests")
|
305
|
+
|
306
|
+
try:
|
307
|
+
with log_service.step("get_delete_product_batch_requests"):
|
308
|
+
with OmnitronIntegration(create_batch=False) as omnitron_integration:
|
309
|
+
with log_service.step("get_batch_requests"):
|
310
|
+
batch_request_data = omnitron_integration.do_action(
|
311
|
+
"get_batch_requests",
|
312
|
+
params={
|
313
|
+
"status": ["sent_to_remote", "ongoing"],
|
314
|
+
"content_type": ContentType.integration_action.value,
|
315
|
+
},
|
316
|
+
)
|
317
|
+
# tips
|
318
|
+
batch_request_data: List[BatchRequest]
|
319
|
+
|
320
|
+
for batch_request in batch_request_data:
|
321
|
+
with log_service.step("check_deleted_products"):
|
322
|
+
(
|
323
|
+
response_data,
|
324
|
+
report,
|
325
|
+
data,
|
326
|
+
) = ChannelIntegration().do_action(
|
327
|
+
key="check_deleted_products",
|
328
|
+
objects=batch_request,
|
329
|
+
batch_request=batch_request,
|
330
|
+
)
|
331
|
+
|
332
|
+
# tips
|
333
|
+
response_data: List[ProductBatchRequestResponseDto]
|
334
|
+
report: ErrorReportDto
|
335
|
+
data: BatchRequest
|
336
|
+
|
337
|
+
if report and (is_success_log or not report.is_ok):
|
338
|
+
with log_service.step("create_error_report"):
|
339
|
+
omnitron_integration.do_action(
|
340
|
+
key="create_error_report", objects=report
|
341
|
+
)
|
342
|
+
if response_data:
|
343
|
+
omnitron_integration.batch_request = batch_request
|
344
|
+
with log_service.step(
|
345
|
+
"process_delete_product_batch_requests"
|
346
|
+
):
|
347
|
+
omnitron_integration.do_action(
|
348
|
+
key="process_delete_product_batch_requests",
|
349
|
+
objects=response_data,
|
350
|
+
)
|
351
|
+
except Exception as fatal:
|
352
|
+
log_service.add_exception(fatal)
|
353
|
+
finally:
|
354
|
+
log_service.save()
|
224
355
|
|
225
356
|
def get_product_batch_requests(self, is_success_log=True):
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
357
|
+
log_service = LogService()
|
358
|
+
log_service.create_flow(name="Get Product Batch Requests")
|
359
|
+
|
360
|
+
try:
|
361
|
+
with log_service.step("get_product_batch_requests"):
|
362
|
+
with OmnitronIntegration(create_batch=False) as omnitron_integration:
|
363
|
+
with log_service.step("get_batch_requests"):
|
364
|
+
batch_request_data = omnitron_integration.do_action(
|
365
|
+
"get_batch_requests",
|
366
|
+
params={
|
367
|
+
"status": ["sent_to_remote", "ongoing"],
|
368
|
+
"content_type": ContentType.product.value,
|
369
|
+
},
|
370
|
+
)
|
371
|
+
# tips
|
372
|
+
batch_request_data: List[BatchRequest]
|
373
|
+
|
374
|
+
for batch_request in batch_request_data:
|
375
|
+
with log_service.step("check_products"):
|
376
|
+
(
|
377
|
+
response_data,
|
378
|
+
report,
|
379
|
+
data,
|
380
|
+
) = ChannelIntegration().do_action(
|
381
|
+
key="check_products",
|
382
|
+
objects=batch_request,
|
383
|
+
batch_request=batch_request,
|
384
|
+
)
|
385
|
+
|
386
|
+
# tips
|
387
|
+
response_data: List[ProductBatchRequestResponseDto]
|
388
|
+
report: ErrorReportDto
|
389
|
+
data: BatchRequest
|
390
|
+
|
391
|
+
if report and (is_success_log or not report.is_ok):
|
392
|
+
with log_service.step("create_error_report"):
|
393
|
+
omnitron_integration.do_action(
|
394
|
+
key="create_error_report", objects=report
|
395
|
+
)
|
396
|
+
|
397
|
+
if response_data:
|
398
|
+
omnitron_integration.batch_request = batch_request
|
399
|
+
with log_service.step("process_product_batch_requests"):
|
400
|
+
omnitron_integration.do_action(
|
401
|
+
key="process_product_batch_requests",
|
402
|
+
objects=response_data,
|
403
|
+
)
|
404
|
+
except Exception as fatal:
|
405
|
+
log_service.add_exception(fatal)
|
406
|
+
raise
|
407
|
+
finally:
|
408
|
+
log_service.save()
|