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
@@ -1,10 +1,11 @@
|
|
1
1
|
from typing import List
|
2
2
|
|
3
|
-
from omnisdk.omnitron.models import ProductPrice,
|
3
|
+
from omnisdk.omnitron.models import ProductPrice, BatchRequest
|
4
4
|
|
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,153 +13,66 @@ from channel_app.omnitron.constants import ContentType
|
|
12
13
|
class PriceService(object):
|
13
14
|
batch_service = ClientBatchRequest
|
14
15
|
|
15
|
-
def update_product_prices(
|
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
|
-
with OmnitronIntegration(
|
76
|
-
content_type=ContentType.product_price.value) as omnitron_integration:
|
77
|
-
product_prices = omnitron_integration.do_action(
|
78
|
-
key='get_inserted_prices')
|
79
|
-
first_product_price_count = len(product_prices)
|
80
|
-
|
81
|
-
if add_product_objects:
|
82
|
-
product_prices = product_prices and omnitron_integration.do_action(
|
83
|
-
key='get_product_objects', objects=product_prices)
|
84
|
-
|
85
|
-
if add_stock:
|
86
|
-
product_prices = product_prices and omnitron_integration.do_action(
|
87
|
-
key='get_stocks_from_product_prices',
|
88
|
-
objects=product_prices,
|
89
|
-
stock_list=omnitron_integration.catalog.stock_list)
|
90
|
-
|
91
|
-
if not product_prices:
|
92
|
-
if first_product_price_count:
|
93
|
-
omnitron_integration.batch_request.objects = None
|
94
|
-
self.batch_service(omnitron_integration.channel_id).to_fail(
|
95
|
-
omnitron_integration.batch_request
|
96
|
-
)
|
97
|
-
return
|
98
|
-
|
99
|
-
product_prices: List[ProductPrice]
|
100
|
-
|
101
|
-
response_data, reports, data = ChannelIntegration().do_action(
|
102
|
-
key='send_inserted_prices',
|
103
|
-
objects=product_prices,
|
104
|
-
batch_request=omnitron_integration.batch_request,
|
105
|
-
is_sync=is_sync)
|
106
|
-
|
107
|
-
# tips
|
108
|
-
response_data: List[BatchRequestResponseDto]
|
109
|
-
reports: List[ErrorReportDto]
|
110
|
-
data: List[ProductPrice]
|
111
|
-
|
112
|
-
if not is_sync:
|
113
|
-
if reports[0].is_ok:
|
114
|
-
self.batch_service(
|
115
|
-
settings.OMNITRON_CHANNEL_ID).to_sent_to_remote(
|
116
|
-
batch_request=omnitron_integration.batch_request)
|
117
|
-
else:
|
118
|
-
is_sync = True
|
119
|
-
|
120
|
-
if reports and (is_success_log or not reports[0].is_ok):
|
121
|
-
for report in reports:
|
122
|
-
omnitron_integration.do_action(
|
123
|
-
key='create_error_report',
|
124
|
-
objects=report)
|
125
|
-
|
126
|
-
if is_sync:
|
127
|
-
omnitron_integration.do_action(
|
128
|
-
key='process_price_batch_requests',
|
129
|
-
objects=response_data)
|
130
|
-
|
131
|
-
def insert_product_prices_from_extra_price_list(self, is_sync=True,
|
132
|
-
is_success_log=True,
|
133
|
-
add_stock=False,
|
134
|
-
add_product_objects=False):
|
135
|
-
currency_mappings = self.get_currency_mappings()
|
136
|
-
for price_list_id, country_code in currency_mappings.items():
|
137
|
-
with OmnitronIntegration(
|
138
|
-
content_type=ContentType.product_price.value) as omnitron_integration:
|
139
|
-
product_prices = omnitron_integration.do_action(
|
140
|
-
key='get_inserted_prices_from_extra_price_list',
|
141
|
-
objects=price_list_id)
|
142
|
-
first_product_price_count = len(product_prices)
|
143
|
-
|
144
|
-
if add_product_objects:
|
145
|
-
product_prices = product_prices and omnitron_integration.do_action(
|
146
|
-
key='get_product_objects', objects=product_prices)
|
147
|
-
|
148
|
-
if add_stock:
|
149
|
-
product_prices = product_prices and omnitron_integration.do_action(
|
150
|
-
key='get_stocks_from_product_prices',
|
151
|
-
objects=product_prices,
|
152
|
-
stock_list=omnitron_integration.catalog.stock_list)
|
153
|
-
|
154
|
-
product_prices: List[ProductPrice]
|
155
|
-
if product_prices:
|
156
|
-
|
157
|
-
response_data, reports, data = ChannelIntegration().do_action(
|
158
|
-
key='send_inserted_prices',
|
159
|
-
objects=(product_prices, country_code),
|
160
|
-
batch_request=omnitron_integration.batch_request,
|
161
|
-
is_sync=is_sync)
|
16
|
+
def update_product_prices(
|
17
|
+
self,
|
18
|
+
is_sync=True,
|
19
|
+
is_success_log=True,
|
20
|
+
add_product_objects=False,
|
21
|
+
add_stock=False,
|
22
|
+
):
|
23
|
+
log_service = LogService()
|
24
|
+
log_service.create_flow(name="Update Product Prices")
|
25
|
+
|
26
|
+
try:
|
27
|
+
with log_service.step("update_product_prices"):
|
28
|
+
with OmnitronIntegration(
|
29
|
+
content_type=ContentType.product_price.value
|
30
|
+
) as omnitron_integration:
|
31
|
+
with log_service.step("get_updated_prices"):
|
32
|
+
product_prices = omnitron_integration.do_action(
|
33
|
+
key="get_updated_prices"
|
34
|
+
)
|
35
|
+
|
36
|
+
first_product_price_count = len(product_prices)
|
37
|
+
|
38
|
+
if add_product_objects:
|
39
|
+
with log_service.step("get_product_objects"):
|
40
|
+
product_prices = (
|
41
|
+
product_prices
|
42
|
+
and omnitron_integration.do_action(
|
43
|
+
key="get_product_objects", objects=product_prices
|
44
|
+
)
|
45
|
+
)
|
46
|
+
|
47
|
+
if add_stock:
|
48
|
+
with log_service.step("get_stocks_from_product_prices"):
|
49
|
+
product_prices = (
|
50
|
+
product_prices
|
51
|
+
and omnitron_integration.do_action(
|
52
|
+
key="get_stocks_from_product_prices",
|
53
|
+
objects=product_prices,
|
54
|
+
stock_list=omnitron_integration.catalog.stock_list,
|
55
|
+
)
|
56
|
+
)
|
57
|
+
|
58
|
+
if not product_prices:
|
59
|
+
if first_product_price_count:
|
60
|
+
omnitron_integration.batch_request.objects = None
|
61
|
+
with log_service.step("batch_to_fail"):
|
62
|
+
self.batch_service(
|
63
|
+
omnitron_integration.channel_id
|
64
|
+
).to_fail(omnitron_integration.batch_request)
|
65
|
+
return
|
66
|
+
|
67
|
+
product_prices: List[ProductPrice]
|
68
|
+
|
69
|
+
with log_service.step("send_updated_prices"):
|
70
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
71
|
+
key="send_updated_prices",
|
72
|
+
objects=product_prices,
|
73
|
+
batch_request=omnitron_integration.batch_request,
|
74
|
+
is_sync=is_sync,
|
75
|
+
)
|
162
76
|
|
163
77
|
# tips
|
164
78
|
response_data: List[BatchRequestResponseDto]
|
@@ -167,59 +81,94 @@ class PriceService(object):
|
|
167
81
|
|
168
82
|
if not is_sync:
|
169
83
|
if reports[0].is_ok:
|
170
|
-
|
171
|
-
|
172
|
-
|
84
|
+
with log_service.step("batch_send_to_remote"):
|
85
|
+
self.batch_service(
|
86
|
+
settings.OMNITRON_CHANNEL_ID
|
87
|
+
).to_sent_to_remote(
|
88
|
+
batch_request=omnitron_integration.batch_request
|
89
|
+
)
|
173
90
|
else:
|
174
91
|
is_sync = True
|
175
92
|
|
176
93
|
if reports and (is_success_log or not reports[0].is_ok):
|
177
94
|
for report in reports:
|
178
|
-
|
179
|
-
|
180
|
-
|
95
|
+
with log_service.step("create_error_report"):
|
96
|
+
omnitron_integration.do_action(
|
97
|
+
key="create_error_report", objects=report
|
98
|
+
)
|
181
99
|
|
182
100
|
if is_sync:
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
101
|
+
with log_service.step("process_price_batch_requests"):
|
102
|
+
omnitron_integration.do_action(
|
103
|
+
key="process_price_batch_requests",
|
104
|
+
objects=response_data,
|
105
|
+
)
|
106
|
+
except Exception as fatal:
|
107
|
+
log_service.add_exception(fatal)
|
108
|
+
raise
|
109
|
+
finally:
|
110
|
+
log_service.save()
|
111
|
+
|
112
|
+
def insert_product_prices(
|
113
|
+
self,
|
114
|
+
is_sync=True,
|
115
|
+
is_success_log=True,
|
116
|
+
add_product_objects=False,
|
117
|
+
add_stock=False,
|
118
|
+
):
|
119
|
+
log_service = LogService()
|
120
|
+
log_service.create_flow(name="Insert Product Prices")
|
121
|
+
|
122
|
+
try:
|
123
|
+
with log_service.step("insert_product_prices"):
|
124
|
+
with OmnitronIntegration(
|
125
|
+
content_type=ContentType.product_price.value
|
126
|
+
) as omnitron_integration:
|
127
|
+
with log_service.step("get_inserted_prices"):
|
128
|
+
product_prices = omnitron_integration.do_action(
|
129
|
+
key="get_inserted_prices"
|
191
130
|
)
|
192
131
|
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
132
|
+
first_product_price_count = len(product_prices)
|
133
|
+
|
134
|
+
if add_product_objects:
|
135
|
+
with log_service.step("get_product_objects"):
|
136
|
+
product_prices = (
|
137
|
+
product_prices
|
138
|
+
and omnitron_integration.do_action(
|
139
|
+
key="get_product_objects", objects=product_prices
|
140
|
+
)
|
141
|
+
)
|
142
|
+
|
143
|
+
if add_stock:
|
144
|
+
with log_service.step("get_stocks_from_product_prices"):
|
145
|
+
product_prices = (
|
146
|
+
product_prices
|
147
|
+
and omnitron_integration.do_action(
|
148
|
+
key="get_stocks_from_product_prices",
|
149
|
+
objects=product_prices,
|
150
|
+
stock_list=omnitron_integration.catalog.stock_list,
|
151
|
+
)
|
152
|
+
)
|
153
|
+
|
154
|
+
if not product_prices:
|
155
|
+
if first_product_price_count:
|
156
|
+
omnitron_integration.batch_request.objects = None
|
157
|
+
with log_service.step("batch_to_fail"):
|
158
|
+
self.batch_service(
|
159
|
+
omnitron_integration.channel_id
|
160
|
+
).to_fail(omnitron_integration.batch_request)
|
161
|
+
return
|
162
|
+
|
163
|
+
product_prices: List[ProductPrice]
|
164
|
+
|
165
|
+
with log_service.step("send_inserted_prices"):
|
166
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
167
|
+
key="send_inserted_prices",
|
168
|
+
objects=product_prices,
|
169
|
+
batch_request=omnitron_integration.batch_request,
|
170
|
+
is_sync=is_sync,
|
171
|
+
)
|
223
172
|
|
224
173
|
# tips
|
225
174
|
response_data: List[BatchRequestResponseDto]
|
@@ -228,61 +177,262 @@ class PriceService(object):
|
|
228
177
|
|
229
178
|
if not is_sync:
|
230
179
|
if reports[0].is_ok:
|
231
|
-
|
232
|
-
|
233
|
-
|
180
|
+
with log_service.step("batch_send_to_remote"):
|
181
|
+
self.batch_service(
|
182
|
+
settings.OMNITRON_CHANNEL_ID
|
183
|
+
).to_sent_to_remote(
|
184
|
+
batch_request=omnitron_integration.batch_request
|
185
|
+
)
|
234
186
|
else:
|
235
187
|
is_sync = True
|
236
188
|
|
237
189
|
if reports and (is_success_log or not reports[0].is_ok):
|
238
190
|
for report in reports:
|
239
|
-
|
240
|
-
|
241
|
-
|
191
|
+
with log_service.step("create_error_report"):
|
192
|
+
omnitron_integration.do_action(
|
193
|
+
key="create_error_report", objects=report
|
194
|
+
)
|
242
195
|
|
243
196
|
if is_sync:
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
197
|
+
with log_service.step("process_price_batch_requests"):
|
198
|
+
omnitron_integration.do_action(
|
199
|
+
key="process_price_batch_requests",
|
200
|
+
objects=response_data,
|
201
|
+
)
|
202
|
+
except Exception as fatal:
|
203
|
+
log_service.add_exception(fatal)
|
204
|
+
raise
|
205
|
+
finally:
|
206
|
+
log_service.save()
|
207
|
+
|
208
|
+
def insert_product_prices_from_extra_price_list(
|
209
|
+
self,
|
210
|
+
is_sync=True,
|
211
|
+
is_success_log=True,
|
212
|
+
add_stock=False,
|
213
|
+
add_product_objects=False,
|
214
|
+
):
|
215
|
+
log_service = LogService()
|
216
|
+
log_service.create_flow(name="Insert Product Prices from Extra Price List")
|
217
|
+
|
218
|
+
try:
|
219
|
+
with log_service.step("insert_product_prices_from_extra_price_list"):
|
220
|
+
with log_service.step("get_currency_mappings"):
|
221
|
+
currency_mappings = self.get_currency_mappings()
|
222
|
+
|
223
|
+
for price_list_id, country_code in currency_mappings.items():
|
224
|
+
with OmnitronIntegration(
|
225
|
+
content_type=ContentType.product_price.value
|
226
|
+
) as omnitron_integration:
|
227
|
+
with log_service.step("get_inserted_prices_from_extra_price_list"):
|
228
|
+
product_prices = omnitron_integration.do_action(
|
229
|
+
key="get_inserted_prices_from_extra_price_list",
|
230
|
+
objects=price_list_id,
|
231
|
+
)
|
232
|
+
first_product_price_count = len(product_prices)
|
233
|
+
|
234
|
+
if add_product_objects:
|
235
|
+
with log_service.step("get_product_objects"):
|
236
|
+
product_prices = product_prices and omnitron_integration.do_action(
|
237
|
+
key="get_product_objects", objects=product_prices
|
238
|
+
)
|
239
|
+
|
240
|
+
if add_stock:
|
241
|
+
with log_service.step("get_stocks_from_product_prices"):
|
242
|
+
product_prices = product_prices and omnitron_integration.do_action(
|
243
|
+
key="get_stocks_from_product_prices",
|
244
|
+
objects=product_prices,
|
245
|
+
stock_list=omnitron_integration.catalog.stock_list,
|
246
|
+
)
|
247
|
+
|
248
|
+
product_prices: List[ProductPrice]
|
249
|
+
if product_prices:
|
250
|
+
with log_service.step("send_inserted_prices"):
|
251
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
252
|
+
key="send_inserted_prices",
|
253
|
+
objects=(product_prices, country_code),
|
254
|
+
batch_request=omnitron_integration.batch_request,
|
255
|
+
is_sync=is_sync,
|
256
|
+
)
|
257
|
+
|
258
|
+
# tips
|
259
|
+
response_data: List[BatchRequestResponseDto]
|
260
|
+
reports: List[ErrorReportDto]
|
261
|
+
data: List[ProductPrice]
|
262
|
+
|
263
|
+
if not is_sync:
|
264
|
+
if reports[0].is_ok:
|
265
|
+
with log_service.step("batch_send_to_remote"):
|
266
|
+
self.batch_service(
|
267
|
+
settings.OMNITRON_CHANNEL_ID
|
268
|
+
).to_sent_to_remote(
|
269
|
+
batch_request=omnitron_integration.batch_request
|
270
|
+
)
|
271
|
+
else:
|
272
|
+
is_sync = True
|
273
|
+
|
274
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
275
|
+
for report in reports:
|
276
|
+
with log_service.step("create_error_report"):
|
277
|
+
omnitron_integration.do_action(
|
278
|
+
key="create_error_report", objects=report
|
279
|
+
)
|
280
|
+
|
281
|
+
if is_sync:
|
282
|
+
with log_service.step("process_price_batch_requests"):
|
283
|
+
omnitron_integration.do_action(
|
284
|
+
key="process_price_batch_requests", objects=response_data
|
285
|
+
)
|
286
|
+
else:
|
287
|
+
if first_product_price_count:
|
288
|
+
omnitron_integration.batch_request.objects = None
|
289
|
+
with log_service.step("batch_to_fail"):
|
290
|
+
self.batch_service(omnitron_integration.channel_id).to_fail(
|
291
|
+
omnitron_integration.batch_request
|
292
|
+
)
|
293
|
+
except Exception as fatal:
|
294
|
+
log_service.add_exception(fatal)
|
295
|
+
raise
|
296
|
+
finally:
|
297
|
+
log_service.save()
|
298
|
+
|
299
|
+
def update_product_prices_from_extra_price_list(
|
300
|
+
self,
|
301
|
+
is_sync=True,
|
302
|
+
is_success_log=True,
|
303
|
+
add_stock=False,
|
304
|
+
add_product_objects=False,
|
305
|
+
):
|
306
|
+
log_service = LogService()
|
307
|
+
log_service.create_flow(name="Update Product Prices from Extra Price List")
|
308
|
+
|
309
|
+
try:
|
310
|
+
with log_service.step("get_currency_mappings"):
|
311
|
+
currency_mappings = self.get_currency_mappings()
|
312
|
+
|
313
|
+
for price_list_id, country_code in currency_mappings.items():
|
314
|
+
with OmnitronIntegration(
|
315
|
+
content_type=ContentType.product_price.value
|
316
|
+
) as omnitron_integration:
|
317
|
+
with log_service.step("get_updated_prices_from_extra_price_list"):
|
318
|
+
product_prices = omnitron_integration.do_action(
|
319
|
+
key="get_updated_prices_from_extra_price_list",
|
320
|
+
objects=price_list_id,
|
252
321
|
)
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
322
|
+
first_product_price_count = len(product_prices)
|
323
|
+
if add_product_objects:
|
324
|
+
with log_service.step("get_product_objects"):
|
325
|
+
product_prices = product_prices and omnitron_integration.do_action(
|
326
|
+
key="get_product_objects", objects=product_prices
|
327
|
+
)
|
328
|
+
|
329
|
+
if add_stock:
|
330
|
+
with log_service.step("get_stocks_from_product_prices"):
|
331
|
+
product_prices = product_prices and omnitron_integration.do_action(
|
332
|
+
key="get_stocks_from_product_prices",
|
333
|
+
objects=product_prices,
|
334
|
+
stock_list=omnitron_integration.catalog.stock_list,
|
335
|
+
)
|
336
|
+
|
337
|
+
product_prices: List[ProductPrice]
|
338
|
+
if product_prices:
|
339
|
+
with log_service.step("send_updated_prices"):
|
340
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
341
|
+
key="send_updated_prices",
|
342
|
+
objects=(product_prices, country_code),
|
343
|
+
batch_request=omnitron_integration.batch_request,
|
344
|
+
is_sync=is_sync,
|
345
|
+
)
|
346
|
+
|
347
|
+
# tips
|
348
|
+
response_data: List[BatchRequestResponseDto]
|
349
|
+
reports: List[ErrorReportDto]
|
350
|
+
data: List[ProductPrice]
|
351
|
+
|
352
|
+
if not is_sync:
|
353
|
+
if reports[0].is_ok:
|
354
|
+
with log_service.step("batch_send_to_remote"):
|
355
|
+
self.batch_service(
|
356
|
+
settings.OMNITRON_CHANNEL_ID
|
357
|
+
).to_sent_to_remote(
|
358
|
+
batch_request=omnitron_integration.batch_request
|
359
|
+
)
|
360
|
+
else:
|
361
|
+
is_sync = True
|
362
|
+
|
363
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
364
|
+
for report in reports:
|
365
|
+
with log_service.step("create_error_report"):
|
366
|
+
omnitron_integration.do_action(
|
367
|
+
key="create_error_report", objects=report
|
368
|
+
)
|
369
|
+
|
370
|
+
if is_sync:
|
371
|
+
with log_service.step("process_price_batch_requests"):
|
372
|
+
omnitron_integration.do_action(
|
373
|
+
key="process_price_batch_requests", objects=response_data
|
374
|
+
)
|
375
|
+
else:
|
376
|
+
if first_product_price_count:
|
377
|
+
omnitron_integration.batch_request.objects = None
|
378
|
+
with log_service.step("batch_to_fail"):
|
379
|
+
self.batch_service(omnitron_integration.channel_id).to_fail(
|
380
|
+
omnitron_integration.batch_request
|
381
|
+
)
|
382
|
+
except Exception as fatal:
|
383
|
+
log_service.add_exception(fatal)
|
384
|
+
raise
|
385
|
+
finally:
|
386
|
+
log_service.save()
|
269
387
|
|
388
|
+
def get_price_batch_requests(self, is_success_log=True):
|
389
|
+
log_service = LogService()
|
390
|
+
log_service.create_flow(name="Get Price Batch Requests")
|
391
|
+
|
392
|
+
try:
|
393
|
+
with OmnitronIntegration(create_batch=False) as omnitron_integration:
|
394
|
+
with log_service.step("get_batch_requests"):
|
395
|
+
batch_request_data = omnitron_integration.do_action(
|
396
|
+
"get_batch_requests",
|
397
|
+
params={
|
398
|
+
"status": ["sent_to_remote", "ongoing"],
|
399
|
+
"content_type": ContentType.product_price.value,
|
400
|
+
},
|
401
|
+
)
|
270
402
|
# tips
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
403
|
+
batch_request_data: List[BatchRequest]
|
404
|
+
|
405
|
+
for batch_request in batch_request_data:
|
406
|
+
with log_service.step("check_prices"):
|
407
|
+
response_data, reports, data = ChannelIntegration().do_action(
|
408
|
+
key="check_prices",
|
409
|
+
objects=batch_request,
|
410
|
+
batch_request=batch_request,
|
411
|
+
)
|
412
|
+
|
413
|
+
# tips
|
414
|
+
response_data: List[BatchRequestResponseDto]
|
415
|
+
reports: List[ErrorReportDto]
|
416
|
+
data: BatchRequest
|
417
|
+
|
418
|
+
if reports and (is_success_log or not reports[0].is_ok):
|
419
|
+
for report in reports:
|
420
|
+
with log_service.step("create_error_report"):
|
421
|
+
omnitron_integration.do_action(
|
422
|
+
key="create_error_report", objects=report
|
423
|
+
)
|
424
|
+
|
425
|
+
if response_data:
|
426
|
+
omnitron_integration.batch_request = batch_request
|
427
|
+
with log_service.step("process_price_batch_requests"):
|
428
|
+
omnitron_integration.do_action(
|
429
|
+
key="process_price_batch_requests", objects=response_data
|
430
|
+
)
|
431
|
+
except Exception as fatal:
|
432
|
+
log_service.add_exception(fatal)
|
433
|
+
raise
|
434
|
+
finally:
|
435
|
+
log_service.save()
|
286
436
|
|
287
437
|
def get_currency_mappings(self):
|
288
438
|
"""
|
@@ -296,13 +446,13 @@ class PriceService(object):
|
|
296
446
|
:return:
|
297
447
|
"""
|
298
448
|
with OmnitronIntegration(create_batch=False) as integration:
|
299
|
-
currency_mappings = integration.channel.conf.get(
|
300
|
-
"CURRENCY_MAPPINGS", {})
|
449
|
+
currency_mappings = integration.channel.conf.get("CURRENCY_MAPPINGS", {})
|
301
450
|
price_lists = integration.catalog.extra_price_lists
|
302
451
|
if integration.catalog.price_list:
|
303
452
|
price_lists.append(integration.catalog.price_list)
|
304
453
|
filtered_currency_mappings = {
|
305
454
|
price_list: currency_mappings[price_list]
|
306
455
|
for price_list in map(str, price_lists)
|
307
|
-
if price_list in currency_mappings
|
456
|
+
if price_list in currency_mappings
|
457
|
+
}
|
308
458
|
return filtered_currency_mappings
|