solidus_bactracs 3.1.2 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/jobs/solidus_bactracs/api/schedule_shipment_syncs_job.rb +7 -6
- data/lib/solidus_bactracs/api/request_runner.rb +7 -6
- data/lib/solidus_bactracs/console_harness.rb +53 -0
- data/lib/solidus_bactracs/version.rb +1 -1
- metadata +3 -3
- data/lib/solidus_backtracs/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e67ac9974b0c0fb6e097172f14667e73c99c5d4ccd948423e48dcdd5820becde
|
4
|
+
data.tar.gz: a7fb4b01e858278ab263373d087aa5a4c63222f9389d2f2a8087566e50f42270
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6232847569c2a6166959fcfdd3791597d8e32aaa71f68def3d4eff77b8b8269857c0973143f5c8af3b33cf47ffcd326b209a43f8c36d6ae07c0542db3255205
|
7
|
+
data.tar.gz: d61675ac31273aa2751b300350d3b3b20ce8d4c23c62c39192a9a90c489762c4d6ff5179abefbcb53ce17031c4f9a68c976663599b49194078a3857d49cf6116
|
@@ -21,16 +21,17 @@ module SolidusBactracs
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def query_shipments
|
24
|
-
shipments = SolidusBactracs::Shipment::PendingApiSyncQuery.apply(
|
25
|
-
|
24
|
+
shipments = SolidusBactracs::Shipment::PendingApiSyncQuery.apply(all_elegible_shipments)
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_elegible_shipments(skus: SolidusBactracs.config.shippable_skus, state: :ready)
|
28
|
+
::Spree::Shipment
|
26
29
|
.joins(inventory_units: [:variant])
|
27
|
-
.where("spree_variants.sku" =>
|
28
|
-
.where("spree_shipments.state" =>
|
30
|
+
.where("spree_variants.sku" => skus)
|
31
|
+
.where("spree_shipments.state" => state)
|
29
32
|
.where(bactracs_synced_at: nil)
|
30
33
|
.distinct
|
31
|
-
)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
36
|
-
|
@@ -13,18 +13,18 @@ module SolidusBactracs
|
|
13
13
|
@retries = SolidusBactracs.configuration.api_retries
|
14
14
|
end
|
15
15
|
|
16
|
-
def authenticated_call(
|
16
|
+
def authenticated_call(serializer: nil, shipment: nil, method: :post, path: '/webservices/rma/rmaservice.asmx', count: 0)
|
17
17
|
if count <= @retries
|
18
18
|
sguid = authenticate! rescue nil
|
19
19
|
|
20
20
|
if !sguid.presence
|
21
21
|
clear_cache
|
22
22
|
count += 1
|
23
|
-
self.authenticated_call(method:
|
23
|
+
self.authenticated_call(method: method, path: path, serializer: serializer, shipment: shipment, count: count)
|
24
24
|
else
|
25
25
|
params = serializer.call(shipment, sguid)
|
26
26
|
|
27
|
-
rma_response = call(method:
|
27
|
+
rma_response = call(method: method, path: path, params: params)
|
28
28
|
if create_rma_success?(rma_response)
|
29
29
|
Rails.logger.info({ event: 'success CreateRMA', rma: shipment.number, response: parse_rma_creation_response(rma_response, "Message")})
|
30
30
|
shipment_synced(shipment)
|
@@ -35,11 +35,12 @@ module SolidusBactracs
|
|
35
35
|
clear_cache
|
36
36
|
count += 1
|
37
37
|
Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(rma_response, "Message")})
|
38
|
-
self.authenticated_call(method:
|
38
|
+
self.authenticated_call(method: method, path: path, serializer: serializer, shipment: shipment, count: count)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
else
|
42
42
|
shipment_sync_failed(shipment)
|
43
|
+
return false
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -77,7 +78,7 @@ module SolidusBactracs
|
|
77
78
|
@response = nil
|
78
79
|
end
|
79
80
|
|
80
|
-
def authenticate!
|
81
|
+
def authenticate!
|
81
82
|
unless @username.present? || @password.present? || @api_base.present?
|
82
83
|
raise "Credentials not defined for Authentication"
|
83
84
|
end
|
@@ -110,7 +111,7 @@ module SolidusBactracs
|
|
110
111
|
|
111
112
|
def rma_exists?(response)
|
112
113
|
if parse_rma_creation_response(response, "Message").match(/rma .* already exists/)
|
113
|
-
Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(
|
114
|
+
Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(response, "Message")})
|
114
115
|
return true
|
115
116
|
end
|
116
117
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module SolidusBactracs
|
2
|
+
class ConsoleHarness
|
3
|
+
attr_reader :runner, :syncer, :sync, :shipments, :shipments_elegible
|
4
|
+
|
5
|
+
attr_accessor :cursor, :batch
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@runner = SolidusBactracs::Api::RequestRunner.new
|
9
|
+
@syncer = SolidusBactracs::Api::BatchSyncer.from_config
|
10
|
+
@sync = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new
|
11
|
+
@shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
|
12
|
+
@shipments_elegible = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.all_elegible_shipments
|
13
|
+
@cursor = 0
|
14
|
+
@batch = 4
|
15
|
+
end
|
16
|
+
|
17
|
+
def refresh
|
18
|
+
@shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
|
19
|
+
end
|
20
|
+
|
21
|
+
def shipment(id)
|
22
|
+
@shipments.find_by(id: id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def shipment_number(ship_number)
|
26
|
+
@shipments.find_by(number: ship_number)
|
27
|
+
end
|
28
|
+
|
29
|
+
def serialize(shipment)
|
30
|
+
# SolidusShipstation::Api::ApplianceShipmentSerializer.new(shipment)
|
31
|
+
@syncer.client.shipment_serializer.call(shipment, @runner.authenticate!)
|
32
|
+
end
|
33
|
+
|
34
|
+
def try_one
|
35
|
+
puts "trying shipment #{(shipment = @shipments[@cursor]).id}"
|
36
|
+
# resp = @runner.call(:post, '/orders/createorders', [serialize(shipment)])
|
37
|
+
resp = @runner.authenticated_call(shipment: shipment, serializer: @syncer.client.shipment_serializer)
|
38
|
+
if resp
|
39
|
+
@cursor += 1
|
40
|
+
return resp
|
41
|
+
end
|
42
|
+
ensure
|
43
|
+
puts resp
|
44
|
+
end
|
45
|
+
|
46
|
+
def try_batch(batch_size=nil)
|
47
|
+
b = [batch_size.to_i, @batch].max
|
48
|
+
b.times do
|
49
|
+
break unless try_one
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_bactracs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeryab Ali
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -171,7 +171,6 @@ files:
|
|
171
171
|
- lib/bactracs_service.rb
|
172
172
|
- lib/generators/solidus_bactracs/install/install_generator.rb
|
173
173
|
- lib/generators/solidus_bactracs/install/templates/initializer.rb
|
174
|
-
- lib/solidus_backtracs/version.rb
|
175
174
|
- lib/solidus_bactracs.rb
|
176
175
|
- lib/solidus_bactracs/api/batch_syncer.rb
|
177
176
|
- lib/solidus_bactracs/api/client.rb
|
@@ -181,6 +180,7 @@ files:
|
|
181
180
|
- lib/solidus_bactracs/api/shipment_serializer.rb
|
182
181
|
- lib/solidus_bactracs/api/threshold_verifier.rb
|
183
182
|
- lib/solidus_bactracs/configuration.rb
|
183
|
+
- lib/solidus_bactracs/console_harness.rb
|
184
184
|
- lib/solidus_bactracs/engine.rb
|
185
185
|
- lib/solidus_bactracs/errors.rb
|
186
186
|
- lib/solidus_bactracs/shipment_notice.rb
|