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.
- channel_app/app/product/service.py +16 -0
- channel_app/core/commands.py +3 -1
- channel_app/core/tests.py +15 -164
- channel_app/omnitron/commands/tests/test_products.py +494 -0
- {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/METADATA +1 -1
- channel_app-0.0.135.dist-info/RECORD +60 -0
- {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/WHEEL +1 -1
- channel_app/channel_app/app/__init__.py +0 -0
- channel_app/channel_app/app/order/__init__.py +0 -0
- channel_app/channel_app/app/order/service.py +0 -230
- channel_app/channel_app/app/product/__init__.py +0 -0
- channel_app/channel_app/app/product/service.py +0 -237
- channel_app/channel_app/app/product_price/__init__.py +0 -0
- channel_app/channel_app/app/product_price/service.py +0 -254
- channel_app/channel_app/app/product_stock/__init__.py +0 -0
- channel_app/channel_app/app/product_stock/service.py +0 -258
- channel_app/channel_app/app/setup/__init__.py +0 -0
- channel_app/channel_app/app/setup/service.py +0 -61
- channel_app/channel_app/channel/__init__.py +0 -0
- channel_app/channel_app/channel/commands/__init__.py +0 -0
- channel_app/channel_app/channel/commands/orders/__init__.py +0 -0
- channel_app/channel_app/channel/commands/orders/orders.py +0 -329
- channel_app/channel_app/channel/commands/product_categories.py +0 -1
- channel_app/channel_app/channel/commands/product_images.py +0 -1
- channel_app/channel_app/channel/commands/product_prices.py +0 -148
- channel_app/channel_app/channel/commands/product_stocks.py +0 -220
- channel_app/channel_app/channel/commands/products.py +0 -161
- channel_app/channel_app/channel/commands/setup.py +0 -948
- channel_app/channel_app/channel/integration.py +0 -84
- channel_app/channel_app/core/__init__.py +0 -0
- channel_app/channel_app/core/clients.py +0 -12
- channel_app/channel_app/core/commands.py +0 -364
- channel_app/channel_app/core/data.py +0 -227
- channel_app/channel_app/core/integration.py +0 -74
- channel_app/channel_app/core/products.py +0 -64
- channel_app/channel_app/core/settings.py +0 -28
- channel_app/channel_app/core/utilities.py +0 -99
- channel_app/channel_app/omnitron/__init__.py +0 -0
- channel_app/channel_app/omnitron/batch_request.py +0 -82
- channel_app/channel_app/omnitron/commands/__init__.py +0 -0
- channel_app/channel_app/omnitron/commands/batch_requests.py +0 -281
- channel_app/channel_app/omnitron/commands/error_reports.py +0 -86
- channel_app/channel_app/omnitron/commands/integration_actions.py +0 -200
- channel_app/channel_app/omnitron/commands/orders/__init__.py +0 -0
- channel_app/channel_app/omnitron/commands/orders/addresses.py +0 -242
- channel_app/channel_app/omnitron/commands/orders/cargo_companies.py +0 -40
- channel_app/channel_app/omnitron/commands/orders/customers.py +0 -72
- channel_app/channel_app/omnitron/commands/orders/orders.py +0 -450
- channel_app/channel_app/omnitron/commands/product_categories.py +0 -1
- channel_app/channel_app/omnitron/commands/product_images.py +0 -1
- channel_app/channel_app/omnitron/commands/product_prices.py +0 -192
- channel_app/channel_app/omnitron/commands/product_stocks.py +0 -229
- channel_app/channel_app/omnitron/commands/products.py +0 -735
- channel_app/channel_app/omnitron/commands/setup.py +0 -839
- channel_app/channel_app/omnitron/constants.py +0 -98
- channel_app/channel_app/omnitron/exceptions.py +0 -42
- channel_app/channel_app/omnitron/integration.py +0 -159
- channel_app/setup.py +0 -21
- channel_app-0.0.131.dist-info/RECORD +0 -110
- /channel_app/{channel_app → omnitron/commands/tests}/__init__.py +0 -0
- {channel_app-0.0.131.dist-info → channel_app-0.0.135.dist-info}/top_level.txt +0 -0
@@ -1,329 +0,0 @@
|
|
1
|
-
import datetime
|
2
|
-
from random import random
|
3
|
-
from typing import Tuple, Any, List
|
4
|
-
|
5
|
-
from omnisdk.omnitron.models import Order, BatchRequest
|
6
|
-
|
7
|
-
from channel_app.core.commands import ChannelCommandInterface
|
8
|
-
from channel_app.core.data import (ErrorReportDto, ChannelCreateOrderDto,
|
9
|
-
AddressDto, CustomerDto, ChannelOrderDto,
|
10
|
-
OrderItemDto, OrderBatchRequestResponseDto,
|
11
|
-
CancelOrderDto)
|
12
|
-
from channel_app.omnitron.constants import ResponseStatus
|
13
|
-
|
14
|
-
|
15
|
-
class GetOrders(ChannelCommandInterface):
|
16
|
-
def get_data(self):
|
17
|
-
|
18
|
-
data = self.objects
|
19
|
-
return data
|
20
|
-
|
21
|
-
def validated_data(self, data) -> object:
|
22
|
-
return data
|
23
|
-
|
24
|
-
def transform_data(self, data) -> object:
|
25
|
-
return data
|
26
|
-
|
27
|
-
def send_request(self, validated_data) -> object:
|
28
|
-
response = self.__mocked_request(data=validated_data)
|
29
|
-
return response
|
30
|
-
|
31
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
32
|
-
response) -> Tuple[ChannelCreateOrderDto,
|
33
|
-
ErrorReportDto, Any]:
|
34
|
-
"""
|
35
|
-
Convert channel order to the format OmnitronIntegration
|
36
|
-
requires
|
37
|
-
"""
|
38
|
-
for response_order_data in response:
|
39
|
-
order_data = response_order_data["order"]
|
40
|
-
customer_data = order_data.pop("customer")
|
41
|
-
shipping_address_data = order_data.pop("shipping_address")
|
42
|
-
billing_address_data = order_data.pop("billing_address")
|
43
|
-
|
44
|
-
order_items_data = response_order_data["order_items"]
|
45
|
-
|
46
|
-
shipping_address = AddressDto(**shipping_address_data)
|
47
|
-
|
48
|
-
billing_address = AddressDto(**billing_address_data)
|
49
|
-
|
50
|
-
customer = CustomerDto(**customer_data)
|
51
|
-
|
52
|
-
channel_order_data = {
|
53
|
-
"billing_address": billing_address,
|
54
|
-
"shipping_address": shipping_address,
|
55
|
-
"customer": customer,
|
56
|
-
"cargo_company": order_data["cargo_company"]
|
57
|
-
}
|
58
|
-
channel_order_data.update(order_data)
|
59
|
-
channel_order_dto = ChannelOrderDto(**channel_order_data)
|
60
|
-
|
61
|
-
order_items_dto = []
|
62
|
-
for order_item_data in order_items_data:
|
63
|
-
order_item = OrderItemDto(**order_item_data)
|
64
|
-
order_items_dto.append(order_item)
|
65
|
-
|
66
|
-
order_items_dto: List[OrderItemDto]
|
67
|
-
channel_create_order = ChannelCreateOrderDto(
|
68
|
-
order=channel_order_dto,
|
69
|
-
order_item=order_items_dto)
|
70
|
-
|
71
|
-
report = self.create_report(response_order_data)
|
72
|
-
yield channel_create_order, report, None
|
73
|
-
|
74
|
-
def __mocked_request(self, data):
|
75
|
-
return [{
|
76
|
-
"order": {
|
77
|
-
"remote_id": "123131",
|
78
|
-
"number": "12331",
|
79
|
-
"channel": "1",
|
80
|
-
"currency": "try",
|
81
|
-
"amount": "17",
|
82
|
-
"shipping_amount": "0.0",
|
83
|
-
"shipping_tax_rate": "18",
|
84
|
-
"extra_field": {},
|
85
|
-
"created_at": datetime.datetime.now(),
|
86
|
-
"customer": {
|
87
|
-
"email": "dummy@dummy.com",
|
88
|
-
"phone_number": None,
|
89
|
-
"first_name": "Dummy",
|
90
|
-
"last_name": "Dummy",
|
91
|
-
"channel_code": "1212",
|
92
|
-
"extra_field": None,
|
93
|
-
"is_active": True
|
94
|
-
},
|
95
|
-
"shipping_address": {
|
96
|
-
"email": "dummy@dummy.com",
|
97
|
-
"phone_number": "05540000000",
|
98
|
-
"first_name": "dummy",
|
99
|
-
"last_name": "dummy",
|
100
|
-
"country": "Türkiye",
|
101
|
-
"city": "İstanbul",
|
102
|
-
"line": "dummy 3 dummy cd"
|
103
|
-
},
|
104
|
-
"billing_address": {
|
105
|
-
"email": "dummy@dummy.com",
|
106
|
-
"phone_number": "05540000000",
|
107
|
-
"first_name": "dummy",
|
108
|
-
"last_name": "dummy",
|
109
|
-
"country": "Türkiye",
|
110
|
-
"city": "İstanbul",
|
111
|
-
"line": "dummy 3 dummy cd"
|
112
|
-
},
|
113
|
-
"cargo_company": "aras kargo"
|
114
|
-
},
|
115
|
-
"order_items": [
|
116
|
-
{
|
117
|
-
"remote_id": "1234",
|
118
|
-
"product": "1234",
|
119
|
-
"price_currency": "try",
|
120
|
-
"price": "17.0",
|
121
|
-
"tax_rate": "18",
|
122
|
-
"retail_price": "20.0",
|
123
|
-
"extra_field": {"tracking_number": "1231"},
|
124
|
-
"status": "400"
|
125
|
-
}
|
126
|
-
]
|
127
|
-
}]
|
128
|
-
|
129
|
-
|
130
|
-
class SendUpdatedOrders(ChannelCommandInterface):
|
131
|
-
param_sync = True
|
132
|
-
|
133
|
-
def get_data(self) -> List[Order]:
|
134
|
-
data = self.objects
|
135
|
-
return data
|
136
|
-
|
137
|
-
def validated_data(self, data) -> object:
|
138
|
-
return data
|
139
|
-
|
140
|
-
def transform_data(self, data) -> object:
|
141
|
-
return data
|
142
|
-
|
143
|
-
def send_request(self, transformed_data) -> object:
|
144
|
-
response = self.__mocked_request(data=transformed_data)
|
145
|
-
return response
|
146
|
-
|
147
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
148
|
-
response) -> Tuple[
|
149
|
-
List[OrderBatchRequestResponseDto], List[ErrorReportDto], Any]:
|
150
|
-
response_data = []
|
151
|
-
for row in response:
|
152
|
-
obj = OrderBatchRequestResponseDto(
|
153
|
-
status=row["status"],
|
154
|
-
remote_id=row["remote_id"],
|
155
|
-
number=row["number"],
|
156
|
-
message=row["message"])
|
157
|
-
response_data.append(obj)
|
158
|
-
|
159
|
-
report = self.create_report(response)
|
160
|
-
return response_data, report, data
|
161
|
-
|
162
|
-
def __mocked_request(self, data):
|
163
|
-
"""
|
164
|
-
Mock a request and response for the send operation to mimic actual
|
165
|
-
channel data
|
166
|
-
|
167
|
-
:return:
|
168
|
-
|
169
|
-
[{
|
170
|
-
"status": "SUCCESS",
|
171
|
-
"remote_id": "123a1",
|
172
|
-
"number": "1234567",
|
173
|
-
"message": ""
|
174
|
-
},]
|
175
|
-
"""
|
176
|
-
response_data = []
|
177
|
-
for index, item in enumerate(data):
|
178
|
-
if random() < 0.8:
|
179
|
-
response_item = {
|
180
|
-
'number': item.number,
|
181
|
-
'message': "",
|
182
|
-
'remote_id': "{}_{}".format(prefix, index),
|
183
|
-
'status': ResponseStatus.success
|
184
|
-
}
|
185
|
-
else:
|
186
|
-
response_item = {
|
187
|
-
"status": ResponseStatus.fail,
|
188
|
-
"remote_id": None,
|
189
|
-
"number": item.number,
|
190
|
-
"message": "exception message"
|
191
|
-
}
|
192
|
-
response_data.append(response_item)
|
193
|
-
return response_data
|
194
|
-
|
195
|
-
|
196
|
-
class CheckOrders(ChannelCommandInterface):
|
197
|
-
def get_data(self) -> BatchRequest:
|
198
|
-
batch_request = self.objects
|
199
|
-
return batch_request
|
200
|
-
|
201
|
-
def validated_data(self, data) -> object:
|
202
|
-
return data
|
203
|
-
|
204
|
-
def transform_data(self, data) -> object:
|
205
|
-
return data
|
206
|
-
|
207
|
-
def send_request(self, transformed_data: BatchRequest) -> object:
|
208
|
-
"""
|
209
|
-
Sends a post request to the channel client to insert the products
|
210
|
-
:param transformed_data:
|
211
|
-
:return:
|
212
|
-
[{ remote_data},]
|
213
|
-
"""
|
214
|
-
|
215
|
-
response = self.__mocked_request(
|
216
|
-
data=self.integration._sent_data[transformed_data.remote_batch_id],
|
217
|
-
remote_batch_id=transformed_data.remote_batch_id)
|
218
|
-
return response
|
219
|
-
|
220
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
221
|
-
response) -> Tuple[
|
222
|
-
List[OrderBatchRequestResponseDto], List[ErrorReportDto], Any]:
|
223
|
-
response_data = []
|
224
|
-
for row in response:
|
225
|
-
obj = OrderBatchRequestResponseDto(
|
226
|
-
status=row["status"],
|
227
|
-
remote_id=row["remote_id"],
|
228
|
-
number=row["number"],
|
229
|
-
message=row["message"])
|
230
|
-
response_data.append(obj)
|
231
|
-
|
232
|
-
report = self.create_report(response)
|
233
|
-
return response_data, report, data
|
234
|
-
|
235
|
-
def __mocked_request(self, data, remote_batch_id):
|
236
|
-
"""
|
237
|
-
Mock a request and response for the send operation to mimic actual
|
238
|
-
channel data
|
239
|
-
|
240
|
-
:return:
|
241
|
-
|
242
|
-
[{
|
243
|
-
"status": "SUCCESS",
|
244
|
-
"remote_id": "123a1",
|
245
|
-
"number": "1234567",
|
246
|
-
"message": ""
|
247
|
-
},]
|
248
|
-
"""
|
249
|
-
response_data = []
|
250
|
-
prefix = remote_batch_id[-8:]
|
251
|
-
for index, item in enumerate(data):
|
252
|
-
if random() < 0.8:
|
253
|
-
response_item = {
|
254
|
-
'number': item.number,
|
255
|
-
'message': "",
|
256
|
-
'remote_id': "{}_{}".format(prefix, index),
|
257
|
-
'status': ResponseStatus.success
|
258
|
-
}
|
259
|
-
else:
|
260
|
-
response_item = {
|
261
|
-
"status": ResponseStatus.fail,
|
262
|
-
"remote_id": None,
|
263
|
-
"number": item.number,
|
264
|
-
"message": "exception message"
|
265
|
-
}
|
266
|
-
response_data.append(response_item)
|
267
|
-
return response_data
|
268
|
-
|
269
|
-
|
270
|
-
class GetCancelledOrders(ChannelCommandInterface):
|
271
|
-
def get_data(self) -> None:
|
272
|
-
return self.objects
|
273
|
-
|
274
|
-
def validated_data(self, data) -> object:
|
275
|
-
return data
|
276
|
-
|
277
|
-
def transform_data(self, data) -> object:
|
278
|
-
return data
|
279
|
-
|
280
|
-
def send_request(self, transformed_data: BatchRequest) -> object:
|
281
|
-
"""
|
282
|
-
Sends a post request to the channel client to insert the products
|
283
|
-
:param transformed_data:
|
284
|
-
:return:
|
285
|
-
[{ remote_data},]
|
286
|
-
"""
|
287
|
-
|
288
|
-
response = self.__mocked_request(
|
289
|
-
data=self.integration._sent_data[transformed_data],
|
290
|
-
remote_batch_id=transformed_data)
|
291
|
-
return response
|
292
|
-
|
293
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
294
|
-
response) -> Tuple[List[CancelOrderDto],
|
295
|
-
ErrorReportDto, Any]:
|
296
|
-
report = self.create_report(response)
|
297
|
-
|
298
|
-
for row in response:
|
299
|
-
obj = CancelOrderDto(
|
300
|
-
order=row["order"],
|
301
|
-
cancel_items=row["cancel_items"],
|
302
|
-
reasons=row["reasons"]
|
303
|
-
)
|
304
|
-
|
305
|
-
yield obj, report, data
|
306
|
-
|
307
|
-
def __mocked_request(self, data, remote_batch_id):
|
308
|
-
"""
|
309
|
-
Mock a request and response for the send operation to mimic actual
|
310
|
-
channel data
|
311
|
-
|
312
|
-
:return:
|
313
|
-
|
314
|
-
[{
|
315
|
-
"order": "orderNumber123",
|
316
|
-
"cancel_items": ["remote_item_1", "remote_item_2"],
|
317
|
-
"reasons": {"remote_item_1": "remote_reason_code",
|
318
|
-
"remote_item_2": "remote_reason_code"}
|
319
|
-
},]
|
320
|
-
"""
|
321
|
-
response_data = []
|
322
|
-
for index, item in enumerate(data):
|
323
|
-
response_item = {
|
324
|
-
'order': item.number,
|
325
|
-
'cancel_items': item.cancel_items,
|
326
|
-
'reasons': item.reasons,
|
327
|
-
}
|
328
|
-
response_data.append(response_item)
|
329
|
-
return response_data
|
@@ -1 +0,0 @@
|
|
1
|
-
#TODO implement channel product category integration
|
@@ -1 +0,0 @@
|
|
1
|
-
#TODO implement channel image integration
|
@@ -1,148 +0,0 @@
|
|
1
|
-
import random
|
2
|
-
import uuid
|
3
|
-
from typing import Tuple, List, Any
|
4
|
-
|
5
|
-
from omnisdk.omnitron.models import ProductPrice, BatchRequest
|
6
|
-
|
7
|
-
from channel_app.core.commands import ChannelCommandInterface
|
8
|
-
from channel_app.core.data import BatchRequestResponseDto, ErrorReportDto
|
9
|
-
from channel_app.omnitron.constants import ResponseStatus
|
10
|
-
|
11
|
-
|
12
|
-
class SendUpdatedPrices(ChannelCommandInterface):
|
13
|
-
param_sync = True
|
14
|
-
|
15
|
-
def get_data(self) -> List[ProductPrice]:
|
16
|
-
product_prices = self.objects
|
17
|
-
return product_prices
|
18
|
-
|
19
|
-
def validated_data(self, data) -> object:
|
20
|
-
return data
|
21
|
-
|
22
|
-
def transform_data(self, data) -> object:
|
23
|
-
return data
|
24
|
-
|
25
|
-
def send_request(self, transformed_data) -> object:
|
26
|
-
if not self.param_sync:
|
27
|
-
response = self.__mocked_request(data=transformed_data)
|
28
|
-
else:
|
29
|
-
response = self.__mock_request_sync(data=transformed_data)
|
30
|
-
|
31
|
-
return response
|
32
|
-
|
33
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
34
|
-
response) -> Tuple[List[BatchRequestResponseDto],
|
35
|
-
ErrorReportDto, Any]:
|
36
|
-
report = self.create_report(response)
|
37
|
-
if not self.param_sync:
|
38
|
-
remote_batch_id = response.get("remote_batch_request_id")
|
39
|
-
self.batch_request.remote_batch_id = remote_batch_id
|
40
|
-
return "", report, data
|
41
|
-
else:
|
42
|
-
response_data = []
|
43
|
-
for row in response:
|
44
|
-
response_data.append(BatchRequestResponseDto(
|
45
|
-
sku=row["sku"],
|
46
|
-
message=row["message"],
|
47
|
-
remote_id=row["remote_id"],
|
48
|
-
status=row["status"]
|
49
|
-
))
|
50
|
-
|
51
|
-
response_data: List[BatchRequestResponseDto]
|
52
|
-
return response_data, report, data
|
53
|
-
|
54
|
-
def __mock_request_sync(self, data):
|
55
|
-
result = []
|
56
|
-
for row in data:
|
57
|
-
obj = dict(
|
58
|
-
sku=row["sku"],
|
59
|
-
message=row["message"],
|
60
|
-
remote_id=row["remote_id"],
|
61
|
-
status=row["status"])
|
62
|
-
result.append(obj)
|
63
|
-
return result
|
64
|
-
|
65
|
-
def __mocked_request(self, data):
|
66
|
-
"""
|
67
|
-
Mock a request and response for the send operation to mimic actual channel data
|
68
|
-
:param data:
|
69
|
-
:return:
|
70
|
-
"""
|
71
|
-
batch_id = str(uuid.uuid4())
|
72
|
-
self.integration._sent_data[batch_id] = data
|
73
|
-
return {"remote_batch_request_id": batch_id}
|
74
|
-
|
75
|
-
|
76
|
-
class SendInsertedPrices(SendUpdatedPrices):
|
77
|
-
pass
|
78
|
-
|
79
|
-
|
80
|
-
class CheckPrices(ChannelCommandInterface):
|
81
|
-
def get_data(self) -> BatchRequest:
|
82
|
-
batch_request = self.objects
|
83
|
-
return batch_request
|
84
|
-
|
85
|
-
def validated_data(self, data):
|
86
|
-
return data
|
87
|
-
|
88
|
-
def transform_data(self, data) -> object:
|
89
|
-
return data
|
90
|
-
|
91
|
-
def send_request(self, transformed_data) -> object:
|
92
|
-
"""
|
93
|
-
Sends a post request to the channel client to check the prices
|
94
|
-
param validated_data:
|
95
|
-
"""
|
96
|
-
|
97
|
-
response = self.__mocked_request(
|
98
|
-
data=self.integration._sent_data[transformed_data.remote_batch_id],
|
99
|
-
remote_batch_id=transformed_data.remote_batch_id)
|
100
|
-
return response
|
101
|
-
|
102
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
103
|
-
response) -> Tuple[List[BatchRequestResponseDto],
|
104
|
-
ErrorReportDto, Any]:
|
105
|
-
response_data = []
|
106
|
-
for row in response:
|
107
|
-
obj = BatchRequestResponseDto(
|
108
|
-
sku=row["sku"],
|
109
|
-
message=row["message"],
|
110
|
-
remote_id=row["remote_id"],
|
111
|
-
status=row["status"])
|
112
|
-
response_data.append(obj)
|
113
|
-
report = self.create_report(response)
|
114
|
-
return response_data, report, data
|
115
|
-
|
116
|
-
def __mocked_request(self, data, remote_batch_id):
|
117
|
-
"""
|
118
|
-
Mock a request and response for the send operation to mimic actual channel data
|
119
|
-
:param data:
|
120
|
-
:return:
|
121
|
-
|
122
|
-
[{
|
123
|
-
"status": "SUCCESS",
|
124
|
-
"remote_id": "123a1",
|
125
|
-
"sku": "1KBATC0197",
|
126
|
-
"message": ""
|
127
|
-
},]
|
128
|
-
"""
|
129
|
-
|
130
|
-
response_data = []
|
131
|
-
prefix = remote_batch_id[-8:]
|
132
|
-
for index, item in enumerate(data):
|
133
|
-
if random.random() < 0.8:
|
134
|
-
response_item = {
|
135
|
-
'sku': item.sku,
|
136
|
-
'message': "",
|
137
|
-
'remote_id': "{}_{}".format(prefix, index),
|
138
|
-
'status': ResponseStatus.success
|
139
|
-
}
|
140
|
-
else:
|
141
|
-
response_item = {
|
142
|
-
"status": ResponseStatus.fail,
|
143
|
-
"remote_id": None,
|
144
|
-
"sku": item.sku,
|
145
|
-
"message": "exception message"
|
146
|
-
}
|
147
|
-
response_data.append(response_item)
|
148
|
-
return response_data
|
@@ -1,220 +0,0 @@
|
|
1
|
-
import random
|
2
|
-
import uuid
|
3
|
-
from typing import Tuple, List, Any
|
4
|
-
|
5
|
-
from omnisdk.omnitron.models import ProductStock, BatchRequest
|
6
|
-
|
7
|
-
from channel_app.core.commands import ChannelCommandInterface
|
8
|
-
from channel_app.core.data import BatchRequestResponseDto, ErrorReportDto
|
9
|
-
from channel_app.omnitron.constants import ResponseStatus
|
10
|
-
|
11
|
-
|
12
|
-
class SendUpdatedStocks(ChannelCommandInterface):
|
13
|
-
"""
|
14
|
-
Daha once bildirilmiş stokların yeni güncellemelerini ilgili satış kanalına
|
15
|
-
gönderebilmek için kullanılır.
|
16
|
-
|
17
|
-
input olarak do_action'da
|
18
|
-
objects -> List[ProductStock] tipinde kayıtları alır.
|
19
|
-
batch_request -> BatchRequest tipinde kayıt alır. Ana işleme ait
|
20
|
-
BatchRequest kaydı. Rapor üretmek için kullanılır.
|
21
|
-
is_sync -> bool tipinde olan bu işlemin sonucunun hemen mi alınabileceği
|
22
|
-
yoksa bu işlemin sonucunun asenkron mu öğrenilebileceğinin bilgisi
|
23
|
-
|
24
|
-
List[BatchRequestResponseDto] -> Stok bildirimi yapildiginda sonucu hemen
|
25
|
-
donuyorsa hazirlanir. Eğer bildirimin sonucu daha sonra kontrol edilecekse
|
26
|
-
bu tip veri yerine None tipinde dönüş yapılır
|
27
|
-
|
28
|
-
ErrorReportDto -> Rapor için üretilmiş veri tipi. Hata olmasada uretilebilir.
|
29
|
-
|
30
|
-
List[ProductStock] -> objects içerisinde geçilmiş veridir. Belki Monkey Patch
|
31
|
-
yapılmış objeleri barındırıyor olabilir.
|
32
|
-
|
33
|
-
:return: do_action çıktısı olarak
|
34
|
-
(List[BatchRequestResponseDto], ErrorReportDto, List[ProductStock])
|
35
|
-
listesi döner
|
36
|
-
"""
|
37
|
-
param_sync = True
|
38
|
-
|
39
|
-
def get_data(self) -> List[ProductStock]:
|
40
|
-
product_stocks = self.objects
|
41
|
-
return product_stocks
|
42
|
-
|
43
|
-
def validated_data(self, data) -> object:
|
44
|
-
return data
|
45
|
-
|
46
|
-
def transform_data(self, data) -> object:
|
47
|
-
return data
|
48
|
-
|
49
|
-
def send_request(self, transformed_data) -> object:
|
50
|
-
if not self.param_sync:
|
51
|
-
response = self.__mocked_request(data=transformed_data)
|
52
|
-
else:
|
53
|
-
response = self.__mock_request_sync(data=transformed_data)
|
54
|
-
|
55
|
-
return response
|
56
|
-
|
57
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
58
|
-
response) -> Tuple[List[BatchRequestResponseDto],
|
59
|
-
ErrorReportDto, Any]:
|
60
|
-
report = self.create_report(response)
|
61
|
-
if not self.param_sync:
|
62
|
-
remote_batch_id = response.get("remote_batch_request_id")
|
63
|
-
self.batch_request.remote_batch_id = remote_batch_id
|
64
|
-
return None, report, data
|
65
|
-
else:
|
66
|
-
response_data = []
|
67
|
-
for row in response:
|
68
|
-
response_data.append(BatchRequestResponseDto(
|
69
|
-
sku=row["sku"],
|
70
|
-
message=row["message"],
|
71
|
-
remote_id=row["remote_id"],
|
72
|
-
status=row["status"]
|
73
|
-
))
|
74
|
-
|
75
|
-
response_data: List[BatchRequestResponseDto]
|
76
|
-
return response_data, report, data
|
77
|
-
|
78
|
-
def __mock_request_sync(self, data):
|
79
|
-
result = []
|
80
|
-
for row in data:
|
81
|
-
obj = dict(
|
82
|
-
sku=row["sku"],
|
83
|
-
message=row["message"],
|
84
|
-
remote_id=row["remote_id"],
|
85
|
-
status=row["status"])
|
86
|
-
result.append(obj)
|
87
|
-
return result
|
88
|
-
|
89
|
-
def __mocked_request(self, data):
|
90
|
-
"""
|
91
|
-
Mock a request and response for the send operation to mimic actual channel data
|
92
|
-
:param data:
|
93
|
-
:return:
|
94
|
-
"""
|
95
|
-
batch_id = str(uuid.uuid4())
|
96
|
-
self.integration._sent_data[batch_id] = data
|
97
|
-
return {"remote_batch_request_id": batch_id}
|
98
|
-
|
99
|
-
|
100
|
-
class SendInsertedStocks(SendUpdatedStocks):
|
101
|
-
"""
|
102
|
-
Daha once bildirilmemiş stokları ilk defa bildirmesi için kullanılır.
|
103
|
-
|
104
|
-
input olarak do_action'da
|
105
|
-
objects -> List[ProductStock] tipinde kayıtları alır.
|
106
|
-
batch_request -> BatchRequest tipinde kayıt alır. Ana işleme ait
|
107
|
-
BatchRequest kaydı. Rapor üretmek için kullanılır.
|
108
|
-
is_sync -> bool tipinde olan bu işlemin sonucunun hemen mi alınabileceği
|
109
|
-
yoksa bu işlemin sonucunun asenkron mu öğrenilebileceğinin bilgisi
|
110
|
-
|
111
|
-
List[BatchRequestResponseDto] -> Stok bildirimi yapildiginda sonucu hemen
|
112
|
-
donuyorsa hazirlanir. Eğer bildirimin sonucu daha sonra kontrol edilecekse
|
113
|
-
bu tip veri yerine None tipinde dönüş yapılır
|
114
|
-
|
115
|
-
ErrorReportDto -> Rapor için üretilmiş veri tipi. Hata olmasada uretilebilir.
|
116
|
-
|
117
|
-
List[ProductStock] -> objects içerisinde geçilmiş veridir. Belki Monkey Patch
|
118
|
-
yapılmış objeleri barındırıyor olabilir.
|
119
|
-
|
120
|
-
:return: do_action çıktısı olarak
|
121
|
-
(List[BatchRequestResponseDto], ErrorReportDto, List[ProductStock])
|
122
|
-
listesi döner
|
123
|
-
"""
|
124
|
-
pass
|
125
|
-
|
126
|
-
|
127
|
-
class CheckStocks(ChannelCommandInterface):
|
128
|
-
"""
|
129
|
-
Bildirilmiş stokların durumlarını satış kanılana sorularak öğrenilmesi
|
130
|
-
için kullanılır.
|
131
|
-
|
132
|
-
input olarak do_action'da
|
133
|
-
objects -> batch_request tipinde veri alır. Bu veri durumunu kontrol
|
134
|
-
edilecek olan daha önce bildirim işleminde bulunmuş batch_request
|
135
|
-
kaydıdır.
|
136
|
-
batch_request -> BatchRequest tipinde kayıt alır. Ana işleme ait
|
137
|
-
BatchRequest kaydı. Rapor üretmek için kullanılır.
|
138
|
-
|
139
|
-
List[BatchRequestResponseDto] -> Stok bildirimi yapildiginda sonucu hemen
|
140
|
-
donuyorsa hazirlanir. Eğer bildirimin sonucu daha sonra kontrol edilecekse
|
141
|
-
bu tip veri yerine None tipinde dönüş yapılır
|
142
|
-
|
143
|
-
ErrorReportDto -> Rapor için üretilmiş veri tipi. Hata olmasada uretilebilir.
|
144
|
-
|
145
|
-
BatchRequest -> objects içerisinde geçilmiş veridir. Belki Monkey Patch
|
146
|
-
yapılmış objeleri barındırıyor olabilir.
|
147
|
-
|
148
|
-
:return: do_action çıktısı olarak
|
149
|
-
(List[BatchRequestResponseDto], ErrorReportDto, BatchRequest)
|
150
|
-
listesi döner
|
151
|
-
"""
|
152
|
-
|
153
|
-
def get_data(self) -> BatchRequest:
|
154
|
-
batch_request = self.objects
|
155
|
-
return batch_request
|
156
|
-
|
157
|
-
def validated_data(self, data):
|
158
|
-
return data
|
159
|
-
|
160
|
-
def transform_data(self, data) -> object:
|
161
|
-
return data
|
162
|
-
|
163
|
-
def send_request(self, transformed_data) -> object:
|
164
|
-
"""
|
165
|
-
Sends a post request to the channel client to check the stocks
|
166
|
-
param validated_data:
|
167
|
-
"""
|
168
|
-
|
169
|
-
response = self.__mocked_request(
|
170
|
-
data=self.integration._sent_data[transformed_data.remote_batch_id],
|
171
|
-
remote_batch_id=transformed_data.remote_batch_id)
|
172
|
-
return response
|
173
|
-
|
174
|
-
def normalize_response(self, data, validated_data, transformed_data,
|
175
|
-
response) -> Tuple[List[BatchRequestResponseDto],
|
176
|
-
ErrorReportDto, Any]:
|
177
|
-
response_data = []
|
178
|
-
for row in response:
|
179
|
-
obj = BatchRequestResponseDto(
|
180
|
-
sku=row["sku"],
|
181
|
-
message=row["message"],
|
182
|
-
remote_id=row["remote_id"],
|
183
|
-
status=row["status"])
|
184
|
-
response_data.append(obj)
|
185
|
-
report = self.create_report(response)
|
186
|
-
return response_data, report, data
|
187
|
-
|
188
|
-
def __mocked_request(self, data, remote_batch_id):
|
189
|
-
"""
|
190
|
-
Mock a request and response for the send operation to mimic actual channel data
|
191
|
-
:param data:
|
192
|
-
:return:
|
193
|
-
|
194
|
-
[{
|
195
|
-
"status": "SUCCESS",
|
196
|
-
"remote_id": "123a1",
|
197
|
-
"sku": "1KBATC0197",
|
198
|
-
"message": ""
|
199
|
-
},]
|
200
|
-
"""
|
201
|
-
|
202
|
-
response_data = []
|
203
|
-
prefix = remote_batch_id[-8:]
|
204
|
-
for index, item in enumerate(data):
|
205
|
-
if random.random() < 0.8:
|
206
|
-
response_item = {
|
207
|
-
'sku': item.sku,
|
208
|
-
'message': "",
|
209
|
-
'remote_id': "{}_{}".format(prefix, index),
|
210
|
-
'status': ResponseStatus.success
|
211
|
-
}
|
212
|
-
else:
|
213
|
-
response_item = {
|
214
|
-
"status": ResponseStatus.fail,
|
215
|
-
"remote_id": None,
|
216
|
-
"sku": item.sku,
|
217
|
-
"message": "exception message"
|
218
|
-
}
|
219
|
-
response_data.append(response_item)
|
220
|
-
return response_data
|