channel-app 0.0.157a10__py3-none-any.whl → 0.0.157a11__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-0.0.157a10.dist-info → channel_app-0.0.157a11.dist-info}/METADATA +1 -1
- {channel_app-0.0.157a10.dist-info → channel_app-0.0.157a11.dist-info}/RECORD +10 -10
- {channel_app-0.0.157a10.dist-info → channel_app-0.0.157a11.dist-info}/WHEEL +0 -0
- {channel_app-0.0.157a10.dist-info → channel_app-0.0.157a11.dist-info}/top_level.txt +0 -0
@@ -5,6 +5,7 @@ from omnisdk.omnitron.models import BatchRequest, ProductImage
|
|
5
5
|
from channel_app.core import settings
|
6
6
|
from channel_app.core.data import BatchRequestResponseDto, ErrorReportDto
|
7
7
|
from channel_app.core.settings import OmnitronIntegration, ChannelIntegration
|
8
|
+
from channel_app.logs.services import LogService
|
8
9
|
from channel_app.omnitron.batch_request import ClientBatchRequest
|
9
10
|
from channel_app.omnitron.constants import ContentType
|
10
11
|
|
@@ -12,139 +13,218 @@ from channel_app.omnitron.constants import ContentType
|
|
12
13
|
class ImageService(object):
|
13
14
|
batch_service = ClientBatchRequest
|
14
15
|
|
15
|
-
def update_product_images(
|
16
|
-
|
17
|
-
|
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
|
-
|
16
|
+
def update_product_images(
|
17
|
+
self, is_sync=True, is_success_log=True, add_product_objects=False
|
18
|
+
):
|
19
|
+
log_service = LogService()
|
20
|
+
log_service.create_flow(name="Update Product Images")
|
21
|
+
|
22
|
+
try:
|
23
|
+
with log_service.step("update_product_images"):
|
24
|
+
with OmnitronIntegration(
|
25
|
+
content_type=ContentType.product_image.value
|
26
|
+
) as omnitron_integration:
|
27
|
+
with log_service.step("get_updated_images"):
|
28
|
+
product_images = omnitron_integration.do_action(
|
29
|
+
key="get_updated_images"
|
30
|
+
)
|
31
|
+
|
32
|
+
first_product_image_count = len(product_images)
|
33
|
+
if add_product_objects:
|
34
|
+
with log_service.step("get_product_objects"):
|
35
|
+
product_images = (
|
36
|
+
product_images
|
37
|
+
and omnitron_integration.do_action(
|
38
|
+
key="get_product_objects", objects=product_images
|
39
|
+
)
|
40
|
+
)
|
41
|
+
|
42
|
+
if not product_images:
|
43
|
+
if first_product_image_count:
|
44
|
+
omnitron_integration.batch_request.objects = None
|
45
|
+
with log_service.step("batch_to_fail"):
|
46
|
+
self.batch_service(
|
47
|
+
omnitron_integration.channel_id
|
48
|
+
).to_fail(omnitron_integration.batch_request)
|
49
|
+
return
|
50
|
+
|
51
|
+
product_images: List[ProductImage]
|
52
|
+
|
53
|
+
with log_service.step("send_updated_images"):
|
54
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
55
|
+
key="send_updated_images",
|
56
|
+
objects=product_images,
|
57
|
+
batch_request=omnitron_integration.batch_request,
|
58
|
+
is_sync=is_sync,
|
59
|
+
)
|
60
|
+
|
61
|
+
# tips
|
62
|
+
response_data: List[BatchRequestResponseDto]
|
63
|
+
reports: List[ErrorReportDto]
|
64
|
+
data: List[ProductImage]
|
65
|
+
|
66
|
+
if not is_sync:
|
67
|
+
if reports[0].is_ok:
|
68
|
+
with log_service.step("batch_send_to_remote"):
|
69
|
+
self.batch_service(
|
70
|
+
settings.OMNITRON_CHANNEL_ID
|
71
|
+
).to_sent_to_remote(
|
72
|
+
batch_request=omnitron_integration.batch_request
|
73
|
+
)
|
74
|
+
else:
|
75
|
+
is_sync = True
|
76
|
+
|
77
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
78
|
+
for report in reports:
|
79
|
+
with log_service.step("create_error_report"):
|
80
|
+
omnitron_integration.do_action(
|
81
|
+
key="create_error_report", objects=report
|
82
|
+
)
|
83
|
+
|
84
|
+
if is_sync:
|
85
|
+
with log_service.step("process_image_batch_requests"):
|
86
|
+
omnitron_integration.do_action(
|
87
|
+
key="process_image_batch_requests",
|
88
|
+
objects=response_data,
|
89
|
+
)
|
90
|
+
except Exception as fatal:
|
91
|
+
log_service.add_exception(fatal)
|
92
|
+
raise
|
93
|
+
finally:
|
94
|
+
log_service.save()
|
95
|
+
|
96
|
+
def insert_product_images(
|
97
|
+
self, is_sync=True, is_success_log=True, add_product_objects=False
|
98
|
+
):
|
99
|
+
log_service = LogService()
|
100
|
+
log_service.create_flow(name="Insert Product Images")
|
101
|
+
|
102
|
+
try:
|
103
|
+
with log_service.step("insert_product_images"):
|
104
|
+
with OmnitronIntegration(
|
105
|
+
content_type=ContentType.product_image.value
|
106
|
+
) as omnitron_integration:
|
107
|
+
with log_service.step("get_inserted_images"):
|
108
|
+
product_images = omnitron_integration.do_action(
|
109
|
+
key="get_inserted_images"
|
110
|
+
)
|
111
|
+
|
112
|
+
first_product_image_count = len(product_images)
|
113
|
+
|
114
|
+
if add_product_objects:
|
115
|
+
with log_service.step("get_product_objects"):
|
116
|
+
product_images = (
|
117
|
+
product_images
|
118
|
+
and omnitron_integration.do_action(
|
119
|
+
key="get_product_objects", objects=product_images
|
120
|
+
)
|
121
|
+
)
|
122
|
+
|
123
|
+
if not product_images:
|
124
|
+
if first_product_image_count:
|
125
|
+
omnitron_integration.batch_request.objects = None
|
126
|
+
with log_service.step("batch_to_fail"):
|
127
|
+
self.batch_service(
|
128
|
+
omnitron_integration.channel_id
|
129
|
+
).to_fail(omnitron_integration.batch_request)
|
130
|
+
return
|
131
|
+
|
132
|
+
product_images: List[ProductImage]
|
133
|
+
|
134
|
+
with log_service.step("send_inserted_images"):
|
135
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
136
|
+
key="send_inserted_images",
|
137
|
+
objects=product_images,
|
138
|
+
batch_request=omnitron_integration.batch_request,
|
139
|
+
is_sync=is_sync,
|
140
|
+
)
|
141
|
+
|
142
|
+
# tips
|
143
|
+
response_data: List[BatchRequestResponseDto]
|
144
|
+
reports: List[ErrorReportDto]
|
145
|
+
data: List[ProductImage]
|
146
|
+
|
147
|
+
if not is_sync:
|
148
|
+
if reports[0].is_ok:
|
149
|
+
with log_service.step("batch_send_to_remote"):
|
150
|
+
self.batch_service(
|
151
|
+
settings.OMNITRON_CHANNEL_ID
|
152
|
+
).to_sent_to_remote(
|
153
|
+
batch_request=omnitron_integration.batch_request
|
154
|
+
)
|
155
|
+
else:
|
156
|
+
is_sync = True
|
157
|
+
|
158
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
159
|
+
for report in reports:
|
160
|
+
with log_service.step("create_error_report"):
|
161
|
+
omnitron_integration.do_action(
|
162
|
+
key="create_error_report", objects=report
|
163
|
+
)
|
164
|
+
|
165
|
+
if is_sync:
|
166
|
+
with log_service.step("process_image_batch_requests"):
|
167
|
+
omnitron_integration.do_action(
|
168
|
+
key="process_image_batch_requests",
|
169
|
+
objects=response_data,
|
170
|
+
)
|
171
|
+
except Exception as fatal:
|
172
|
+
log_service.add_exception(fatal)
|
173
|
+
raise
|
174
|
+
finally:
|
175
|
+
log_service.save()
|
117
176
|
|
118
177
|
def get_image_batch_requests(self, is_success_log=True):
|
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
|
-
|
178
|
+
log_service = LogService()
|
179
|
+
log_service.create_flow(name="Get Image Batch Requests")
|
180
|
+
|
181
|
+
try:
|
182
|
+
with log_service.step("get_image_batch_requests"):
|
183
|
+
with OmnitronIntegration(create_batch=False) as omnitron_integration:
|
184
|
+
with log_service.step("get_batch_requests"):
|
185
|
+
batch_request_data = omnitron_integration.do_action(
|
186
|
+
"get_batch_requests",
|
187
|
+
params={
|
188
|
+
"status": ["sent_to_remote", "ongoing"],
|
189
|
+
"content_type": ContentType.product_image.value,
|
190
|
+
},
|
191
|
+
)
|
192
|
+
# tips
|
193
|
+
batch_request_data: List[BatchRequest]
|
194
|
+
|
195
|
+
for batch_request in batch_request_data:
|
196
|
+
with log_service.step("check_images"):
|
197
|
+
(
|
198
|
+
response_data,
|
199
|
+
reports,
|
200
|
+
data,
|
201
|
+
) = ChannelIntegration().do_action(
|
202
|
+
key="check_images",
|
203
|
+
objects=batch_request,
|
204
|
+
batch_request=batch_request,
|
205
|
+
)
|
206
|
+
|
207
|
+
# tips
|
208
|
+
response_data: List[BatchRequestResponseDto]
|
209
|
+
reports: List[ErrorReportDto]
|
210
|
+
data: BatchRequest
|
211
|
+
|
212
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
213
|
+
for report in reports:
|
214
|
+
with log_service.step("create_error_report"):
|
215
|
+
omnitron_integration.do_action(
|
216
|
+
key="create_error_report", objects=report
|
217
|
+
)
|
218
|
+
|
219
|
+
if response_data:
|
220
|
+
omnitron_integration.batch_request = batch_request
|
221
|
+
with log_service.step("process_image_batch_requests"):
|
222
|
+
omnitron_integration.do_action(
|
223
|
+
key="process_image_batch_requests",
|
224
|
+
objects=response_data,
|
225
|
+
)
|
226
|
+
except Exception as fatal:
|
227
|
+
log_service.add_exception(fatal)
|
228
|
+
raise
|
229
|
+
finally:
|
230
|
+
log_service.save()
|