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,230 +0,0 @@
1
- from dataclasses import asdict
2
- from typing import List, Generator, Union
3
-
4
- from omnisdk.omnitron.models import (Customer, Address, CargoCompany, Order,
5
- BatchRequest)
6
-
7
- from channel_app.core import settings
8
- from channel_app.core.data import (OmnitronCreateOrderDto, OmnitronOrderDto,
9
- ChannelCreateOrderDto,
10
- ErrorReportDto,
11
- OrderBatchRequestResponseDto, CancelOrderDto)
12
- from channel_app.core.settings import OmnitronIntegration, ChannelIntegration
13
- from channel_app.omnitron.batch_request import ClientBatchRequest
14
- from channel_app.omnitron.constants import ContentType
15
- from channel_app.omnitron.exceptions import (CityException,
16
- TownshipException,
17
- DistrictException,
18
- CargoCompanyException,
19
- OrderException)
20
-
21
-
22
- class OrderService(object):
23
- batch_service = ClientBatchRequest
24
-
25
- def fetch_and_create_order(self, is_success_log=True):
26
- with OmnitronIntegration(
27
- content_type=ContentType.order.value) as omnitron_integration:
28
- get_orders = ChannelIntegration().do_action(
29
- key='get_orders',
30
- batch_request=omnitron_integration.batch_request
31
- )
32
-
33
- get_orders: Generator
34
- while True:
35
- try:
36
- channel_create_order, report, _ = next(get_orders)
37
- except StopIteration:
38
- break
39
-
40
- # tips
41
- channel_create_order: ChannelCreateOrderDto
42
- report: ErrorReportDto
43
-
44
- if report and (is_success_log or not report.is_ok):
45
- omnitron_integration.do_action(
46
- key='create_error_report',
47
- objects=report)
48
-
49
- self.create_order(omnitron_integration=omnitron_integration,
50
- channel_order=channel_create_order)
51
-
52
- def create_order(self, omnitron_integration: OmnitronIntegration,
53
- channel_order: ChannelCreateOrderDto
54
- ) -> Union[Order, None]:
55
- order = channel_order.order
56
-
57
- try:
58
- customer = omnitron_integration.do_action(
59
- key='get_or_create_customer',
60
- objects=order.customer)
61
- except Exception:
62
- return
63
-
64
- customer: Customer
65
- try:
66
- shipping_address_data = {
67
- "customer": customer,
68
- "address": order.shipping_address
69
- }
70
- shipping_address = omnitron_integration.do_action(
71
- key='get_or_create_address',
72
- objects=shipping_address_data
73
- )[0]
74
-
75
- billing_address_data = {
76
- "customer": customer,
77
- "address": order.billing_address
78
- }
79
- billing_address = omnitron_integration.do_action(
80
- key='get_or_create_address',
81
- objects=billing_address_data
82
- )[0]
83
- except (CityException, TownshipException, DistrictException) as exc:
84
- omnitron_integration.do_action(
85
- key='create_address_error_report',
86
- object=exc)
87
- return
88
-
89
- shipping_address: Address
90
- billing_address: Address
91
- try:
92
- cargo_company = omnitron_integration.do_action(
93
- key='get_cargo_company',
94
- objects=order.cargo_company
95
- )[0]
96
- except CargoCompanyException: # TODO: exception
97
- # log
98
- return
99
- cargo_company: CargoCompany
100
-
101
- order_data = asdict(order)
102
- order_data["customer"] = customer.pk
103
- order_data["shipping_address"] = shipping_address.pk
104
- order_data["billing_address"] = billing_address.pk
105
- order_data["cargo_company"] = cargo_company.pk
106
- omnitron_order = OmnitronOrderDto(**order_data)
107
- create_order_dto = OmnitronCreateOrderDto(
108
- order=omnitron_order,
109
- order_item=channel_order.order_item)
110
- try:
111
- orders: List[Order] = omnitron_integration.do_action(
112
- key='create_order',
113
- objects=create_order_dto
114
- )
115
- order = orders[0] # formatted_data
116
- except OrderException:
117
- return
118
-
119
- omnitron_integration.do_action(
120
- key='create_order_shipping_info',
121
- objects=order
122
- )
123
- return order
124
-
125
- def update_orders(self, is_sync=True, is_success_log=True):
126
- with OmnitronIntegration(
127
- content_type=ContentType.order.value) as omnitron_integration:
128
- orders = omnitron_integration.do_action(key='get_orders')
129
- orders: List[Order]
130
-
131
- if not orders:
132
- return
133
-
134
- response_data, reports, data = ChannelIntegration().do_action(
135
- key='send_updated_orders',
136
- objects=orders,
137
- batch_request=omnitron_integration.batch_request,
138
- is_sync=True)
139
-
140
- # tips
141
- response_data: List[OrderBatchRequestResponseDto]
142
- reports: List[ErrorReportDto]
143
- data: List[Order]
144
-
145
- if not is_sync:
146
- if reports[0].is_ok:
147
- self.batch_service(
148
- settings.OMNITRON_CHANNEL_ID).to_sent_to_remote(
149
- batch_request=omnitron_integration.batch_request)
150
- else:
151
- is_sync = True
152
-
153
- if reports and (is_success_log or not reports[0].is_ok):
154
- for report in reports:
155
- omnitron_integration.do_action(
156
- key='create_error_report',
157
- objects=report)
158
-
159
- if is_sync:
160
- omnitron_integration.do_action(
161
- key='process_order_batch_requests',
162
- objects=response_data)
163
-
164
- def get_order_batch_requests(self, is_success_log=False):
165
- with OmnitronIntegration(create_batch=False) as omnitron_integration:
166
- batch_request_data = omnitron_integration.do_action(
167
- 'get_batch_requests',
168
- params={
169
- "status": ["sent_to_remote", "ongoing"],
170
- "content_type": ContentType.order.value})
171
-
172
- # tips
173
- batch_request_data: List[BatchRequest]
174
-
175
- for batch_request in batch_request_data:
176
- response_data, report, data = ChannelIntegration().do_action(
177
- key='check_orders',
178
- objects=batch_request)
179
-
180
- # tips
181
- response_data: List[OrderBatchRequestResponseDto]
182
- report: ErrorReportDto
183
- data: BatchRequest
184
-
185
- if report and (is_success_log or not report.is_ok):
186
- omnitron_integration.do_action(
187
- key='create_error_report',
188
- objects=report)
189
-
190
- if response_data:
191
- omnitron_integration.batch_request = batch_request_data
192
- omnitron_integration.do_action(
193
- key='process_order_batch_requests',
194
- objects=response_data)
195
-
196
- def fetch_and_create_cancel(self, is_success_log=True):
197
- with OmnitronIntegration(
198
- content_type=ContentType.order.value) as omnitron_integration:
199
- get_cancelled_order = ChannelIntegration().do_action(
200
- key='get_cancelled_orders')
201
- get_cancelled_order: Generator
202
-
203
- while True:
204
- try:
205
- cancel_order_dto, report, _ = next(get_cancelled_order)
206
- except StopIteration:
207
- break
208
-
209
- # tips
210
- cancel_order_dto: CancelOrderDto
211
- report: ErrorReportDto
212
-
213
- if report and (is_success_log or not report.is_ok):
214
- omnitron_integration.do_action(
215
- key='create_error_report',
216
- objects=report)
217
-
218
- self.create_cancel(omnitron_integration=omnitron_integration,
219
- cancel_order_dto=cancel_order_dto)
220
-
221
- def create_cancel(self, omnitron_integration: OmnitronIntegration,
222
- cancel_order_dto: CancelOrderDto):
223
- success_datas: List[Order] = omnitron_integration.do_action(
224
- key="create_order_cancel",
225
- objects=cancel_order_dto)
226
- try:
227
- success_data = success_datas[0]
228
- return success_data
229
- except IndexError:
230
- return
File without changes
@@ -1,237 +0,0 @@
1
- from typing import List
2
-
3
- from omnisdk.omnitron.models import (ProductStock, Product, IntegrationAction,
4
- BatchRequest)
5
-
6
- from channel_app.core import settings
7
- from channel_app.core.data import (ProductBatchRequestResponseDto,
8
- ErrorReportDto)
9
- from channel_app.core.settings import OmnitronIntegration, ChannelIntegration
10
- from channel_app.omnitron.batch_request import ClientBatchRequest
11
- from channel_app.omnitron.constants import ContentType
12
-
13
-
14
- class ProductService(object):
15
- batch_service = ClientBatchRequest
16
-
17
- def insert_products(self, add_mapped=True, add_stock=True, add_price=True,
18
- add_categories=True, is_sync=True,
19
- is_success_log=True):
20
- with OmnitronIntegration(
21
- content_type=ContentType.product.value) as omnitron_integration:
22
- products = omnitron_integration.do_action(
23
- key='get_inserted_products')
24
-
25
- if add_mapped:
26
- products = products and omnitron_integration.do_action(
27
- key='get_mapped_products', objects=products)
28
-
29
- if add_stock:
30
- products = products and omnitron_integration.do_action(
31
- key='get_product_stocks', objects=products)
32
-
33
- if add_price:
34
- products = products and omnitron_integration.do_action(
35
- key='get_product_prices', objects=products)
36
-
37
- if add_categories:
38
- products = products and omnitron_integration.do_action(
39
- key='get_product_categories', objects=products)
40
-
41
- if not products:
42
- return
43
-
44
- products: List[Product]
45
-
46
- response_data, reports, data = ChannelIntegration().do_action(
47
- key='send_inserted_products',
48
- objects=products,
49
- batch_request=omnitron_integration.batch_request,
50
- is_sync=is_sync)
51
-
52
- # tips
53
- response_data: List[ProductBatchRequestResponseDto]
54
- reports: List[ErrorReportDto]
55
- data: List[Product]
56
-
57
- if not is_sync:
58
- if reports[0].is_ok:
59
- self.batch_service(
60
- settings.OMNITRON_CHANNEL_ID).to_sent_to_remote(
61
- batch_request=omnitron_integration.batch_request)
62
- else:
63
- is_sync = True
64
-
65
- if reports and (is_success_log or not reports[0].is_ok):
66
- for report in reports:
67
- omnitron_integration.do_action(
68
- key='create_error_report',
69
- objects=report)
70
-
71
- if is_sync:
72
- omnitron_integration.do_action(
73
- key='process_product_batch_requests',
74
- objects=response_data)
75
-
76
- def update_products(self, add_mapped=True, add_stock=True, add_price=True,
77
- add_categories=True, is_sync=True, is_success_log=True):
78
- with OmnitronIntegration(
79
- content_type=ContentType.product.value) as omnitron_integration:
80
- products = omnitron_integration.do_action(
81
- key='get_updated_products')
82
- if add_mapped:
83
- products = products and omnitron_integration.do_action(
84
- key='get_mapped_products', objects=products)
85
-
86
- if add_stock:
87
- products = products and omnitron_integration.do_action(
88
- key='get_product_stocks', objects=products)
89
-
90
- if add_price:
91
- products = products and omnitron_integration.do_action(
92
- key='get_product_prices', objects=products)
93
-
94
- if add_categories:
95
- products = products and omnitron_integration.do_action(
96
- key='get_product_categories', objects=products)
97
-
98
- if not products:
99
- return
100
-
101
- products: List[Product]
102
-
103
- response_data, reports, data = ChannelIntegration().do_action(
104
- key='send_updated_products',
105
- objects=products,
106
- batch_request=omnitron_integration.batch_request,
107
- is_sync=is_sync)
108
-
109
- # tips
110
- response_data: List[ProductBatchRequestResponseDto]
111
- reports: List[ErrorReportDto]
112
- data: List[Product]
113
-
114
- if not is_sync:
115
- if reports[0].is_ok:
116
- self.batch_service(
117
- settings.OMNITRON_CHANNEL_ID).to_sent_to_remote(
118
- batch_request=omnitron_integration.batch_request)
119
- else:
120
- is_sync = True
121
-
122
- if reports and (is_success_log or not reports[0].is_ok):
123
- for report in reports:
124
- omnitron_integration.do_action(
125
- key='create_error_report',
126
- objects=report)
127
-
128
- if is_sync:
129
- omnitron_integration.do_action(
130
- key='process_product_batch_requests',
131
- objects=response_data)
132
-
133
- def delete_products(self, is_sync=True, is_content_object=True,
134
- is_success_log=True):
135
- with OmnitronIntegration(
136
- content_type=ContentType.integration_action.value) as omnitron_integration:
137
- products_integration_action = omnitron_integration.do_action(
138
- key='get_deleted_products')
139
- if not products_integration_action:
140
- return
141
- products_integration_action = omnitron_integration.do_action(
142
- key="get_content_objects_from_integrations",
143
- objects=products_integration_action
144
- )
145
- products_integration_action: List[IntegrationAction]
146
- response_data, reports, data = ChannelIntegration().do_action(
147
- key='send_deleted_products',
148
- objects=products_integration_action,
149
- batch_request=omnitron_integration.batch_request,
150
- is_sync=is_sync)
151
-
152
- # tips
153
- response_data: List[ProductBatchRequestResponseDto]
154
- reports: List[ErrorReportDto]
155
- data: List[IntegrationAction]
156
-
157
- if not is_sync:
158
- if reports[0].is_ok:
159
- self.batch_service(
160
- settings.OMNITRON_CHANNEL_ID).to_commit(
161
- batch_request=omnitron_integration.batch_request)
162
- self.batch_service(
163
- settings.OMNITRON_CHANNEL_ID).to_sent_to_remote(
164
- batch_request=omnitron_integration.batch_request)
165
- else:
166
- is_sync = True
167
-
168
- if reports and (is_success_log or not reports[0].is_ok):
169
- for report in reports:
170
- omnitron_integration.do_action(
171
- key='create_error_report',
172
- objects=report)
173
-
174
- if is_sync:
175
- omnitron_integration.do_action(
176
- key='process_delete_product_batch_requests',
177
- objects=response_data)
178
-
179
- def get_delete_product_batch_requests(self, is_success_log=True):
180
- with OmnitronIntegration(create_batch=False) as omnitron_integration:
181
- batch_request_data = omnitron_integration.do_action(
182
- 'get_batch_requests',
183
- params={
184
- "status": ["sent_to_remote", "ongoing"],
185
- "content_type": ContentType.integration_action.value})
186
- # tips
187
- batch_request_data: List[BatchRequest]
188
-
189
- for batch_request in batch_request_data:
190
- response_data, report, data = ChannelIntegration().do_action(
191
- key='check_deleted_products',
192
- objects=batch_request)
193
-
194
- # tips
195
- response_data: List[ProductBatchRequestResponseDto]
196
- report: ErrorReportDto
197
- data: BatchRequest
198
-
199
- if report and (is_success_log or not report.is_ok):
200
- omnitron_integration.do_action(
201
- key='create_error_report',
202
- objects=report)
203
- if response_data:
204
- omnitron_integration.batch_request = batch_request
205
- omnitron_integration.do_action(
206
- key='process_delete_product_batch_requests',
207
- objects=batch_request)
208
-
209
- def get_product_batch_requests(self, is_success_log=True):
210
- with OmnitronIntegration(create_batch=False) as omnitron_integration:
211
- batch_request_data = omnitron_integration.do_action(
212
- 'get_batch_requests',
213
- params={
214
- "status": ["sent_to_remote", "ongoing"],
215
- "content_type": ContentType.product.value})
216
- # tips
217
- batch_request_data: List[BatchRequest]
218
-
219
- for batch_request in batch_request_data:
220
- response_data, report, data = ChannelIntegration().do_action(
221
- key='check_products', objects=batch_request)
222
-
223
- # tips
224
- response_data: List[ProductBatchRequestResponseDto]
225
- report: ErrorReportDto
226
- data: BatchRequest
227
-
228
- if report and (is_success_log or not report.is_ok):
229
- omnitron_integration.do_action(
230
- key='create_error_report',
231
- objects=report)
232
-
233
- if response_data:
234
- omnitron_integration.batch_request = batch_request
235
- omnitron_integration.do_action(
236
- key='process_product_batch_requests',
237
- objects=response_data)
File without changes