solidus_bactracs 3.0.0 → 3.1.2
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.
- checksums.yaml +4 -4
- data/.gem_release.yml +2 -2
- data/.github/CODEOWNERS +54 -0
- data/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +3 -0
- data/.github/workflows/release.yml +50 -0
- data/.gitignore +0 -2
- data/.rubocop_todo.yml +3 -3
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +10 -1
- data/PULL_REQUEST_TEMPLATE.md +3 -0
- data/README.md +7 -6
- data/Rakefile +1 -0
- data/app/assets/javascripts/spree/backend/{solidus_backtracs.js → solidus_bactracs.js} +0 -0
- data/app/assets/javascripts/spree/frontend/{solidus_backtracs.js → solidus_bactracs.js} +0 -0
- data/app/assets/stylesheets/spree/backend/{solidus_backtracs.css → solidus_bactracs.css} +0 -0
- data/app/assets/stylesheets/spree/frontend/{solidus_backtracs.css → solidus_bactracs.css} +0 -0
- data/app/controllers/spree/{backtracs_controller.rb → bactracs_controller.rb} +9 -9
- data/app/decorators/models/solidus_bactracs/spree/shipment_decorator.rb +46 -0
- data/app/helpers/{solidus_backtracs → solidus_bactracs}/export_helper.rb +2 -2
- data/app/jobs/{solidus_backtracs → solidus_bactracs}/api/schedule_shipment_syncs_job.rb +7 -7
- data/app/jobs/{solidus_backtracs → solidus_bactracs}/api/sync_shipment_job.rb +1 -1
- data/app/jobs/{solidus_backtracs → solidus_bactracs}/api/sync_shipments_job.rb +7 -3
- data/app/queries/{solidus_backtracs → solidus_bactracs}/shipment/between_query.rb +1 -1
- data/app/queries/{solidus_backtracs → solidus_bactracs}/shipment/exportable_query.rb +3 -3
- data/app/queries/{solidus_backtracs → solidus_bactracs}/shipment/pending_api_sync_query.rb +6 -6
- data/app/views/spree/{backtracs → bactracs}/export.xml.builder +5 -5
- data/app/workers/verify_bactracs_sync_worker.rb +14 -0
- data/bin/console +1 -1
- data/bin/rails-engine +1 -1
- data/bin/sandbox +1 -1
- data/config/routes.rb +2 -2
- data/db/migrate/20210220093010_add_bactracs_api_sync_fields.rb +11 -0
- data/db/migrate/20220701000001_bactracs_typo_correction.rb +10 -0
- data/db/migrate/20220704144504_rename_bactracs_columns_in_spree_shipment.rb +10 -0
- data/lib/bactracs_service.rb +66 -0
- data/lib/generators/{solidus_backtracs → solidus_bactracs}/install/install_generator.rb +3 -3
- data/lib/generators/{solidus_backtracs → solidus_bactracs}/install/templates/initializer.rb +42 -12
- data/lib/solidus_backtracs/version.rb +1 -1
- data/lib/{solidus_backtracs → solidus_bactracs}/api/batch_syncer.rb +5 -5
- data/lib/{solidus_backtracs → solidus_bactracs}/api/client.rb +4 -4
- data/lib/{solidus_backtracs → solidus_bactracs}/api/rate_limited_error.rb +1 -1
- data/lib/{solidus_backtracs → solidus_bactracs}/api/request_error.rb +1 -1
- data/lib/solidus_bactracs/api/request_runner.rb +135 -0
- data/lib/{solidus_backtracs → solidus_bactracs}/api/shipment_serializer.rb +28 -27
- data/lib/{solidus_backtracs → solidus_bactracs}/api/threshold_verifier.rb +6 -6
- data/lib/{solidus_backtracs → solidus_bactracs}/configuration.rb +4 -4
- data/lib/{solidus_backtracs → solidus_bactracs}/engine.rb +2 -2
- data/lib/{solidus_backtracs → solidus_bactracs}/errors.rb +1 -1
- data/lib/{solidus_backtracs → solidus_bactracs}/shipment_notice.rb +2 -2
- data/lib/{solidus_backtracs → solidus_bactracs}/testing_support/factories.rb +0 -0
- data/lib/solidus_bactracs/version.rb +5 -0
- data/lib/solidus_bactracs.rb +16 -0
- data/lib/tasks/solidus_bactracs.rake +16 -0
- data/solidus_bactracs.gemspec +3 -2
- data/spec/controllers/spree/{backtracs_controller_spec.rb → bactracs_controller_spec.rb} +9 -9
- data/spec/fixtures/{backtracs_xml_schema.xsd → bactracs_xml_schema.xsd} +0 -0
- data/spec/jobs/{solidus_backtracs → solidus_bactracs}/api/schedule_shipment_syncs_job_spec.rb +5 -5
- data/spec/jobs/{solidus_backtracs → solidus_bactracs}/api/sync_shipments_job_spec.rb +10 -10
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/batch_syncer_spec.rb +28 -28
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/client_spec.rb +10 -10
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/rate_limited_error_spec.rb +1 -1
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/request_error_spec.rb +1 -1
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/request_runner_spec.rb +3 -3
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/shipment_serializer_spec.rb +1 -1
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/api/threshold_verifier_spec.rb +9 -9
- data/spec/lib/{solidus_backtracs → solidus_bactracs}/shipment_notice_spec.rb +4 -4
- data/spec/lib/solidus_bactracs_spec.rb +9 -0
- data/spec/models/spree/shipment_spec.rb +2 -2
- data/spec/queries/{solidus_backtracs → solidus_bactracs}/shipment/between_query_spec.rb +1 -1
- data/spec/queries/{solidus_backtracs → solidus_bactracs}/shipment/exportable_query_spec.rb +1 -1
- data/spec/queries/{solidus_backtracs → solidus_bactracs}/shipment/pending_api_sync_query_spec.rb +4 -4
- data/spec/spec_helper.rb +2 -2
- data/spec/support/configuration_helper.rb +1 -1
- metadata +81 -68
- data/app/decorators/models/solidus_backtracs/spree/shipment_decorator.rb +0 -33
- data/db/migrate/20210220093010_add_backtracs_api_sync_fields.rb +0 -8
- data/lib/solidus_backtracs/api/request_runner.rb +0 -109
- data/lib/solidus_backtracs.rb +0 -16
- data/spec/lib/solidus_backtracs_spec.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57358a842b15f8f01b4ef06b6e665d3da2d1e71c2cb9d0c963a53cf790329431
|
4
|
+
data.tar.gz: 50ec2b26961894f93f194047564ffc09df92337fcbcc2ef924d241dda879bb84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61b6d5945b5bea4a67e85b44bb2cd719740466d0737599d1e77bb4aad035ce488e7cbb0df89ddedf1307d958dff901f01d0c9f66bb2006d4df06deb62836473e
|
7
|
+
data.tar.gz: 9db512ac8470045e746d5afada89e2634845d175c4bbb45aca29cb6196d8199c5e65aeef0123cd0e5b75e1cfb6b483cbc0e186143e26fedfc5ceadb81b19089d
|
data/.gem_release.yml
CHANGED
data/.github/CODEOWNERS
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# This is a comment.
|
2
|
+
# Each line is a file pattern followed by one or more owners.
|
3
|
+
|
4
|
+
# These owners will be the default owners for everything in
|
5
|
+
# the repo. Unless a later match takes precedence,
|
6
|
+
# @global-owner1 and @global-owner2 will be requested for
|
7
|
+
# review when someone opens a pull request.
|
8
|
+
* @suvie-eng/software-admin
|
9
|
+
|
10
|
+
# Order is important; the last matching pattern takes the most
|
11
|
+
# precedence. When someone opens a pull request that only
|
12
|
+
# modifies JS files, only @js-owner and not the global
|
13
|
+
# owner(s) will be requested for a review.
|
14
|
+
# *.js @js-owner
|
15
|
+
|
16
|
+
# You can also use email addresses if you prefer. They'll be
|
17
|
+
# used to look up users just like we do for commit author
|
18
|
+
# emails.
|
19
|
+
# *.go docs@example.com
|
20
|
+
|
21
|
+
# Teams can be specified as code owners as well. Teams should
|
22
|
+
# be identified in the format @org/team-name. Teams must have
|
23
|
+
# explicit write access to the repository. In this example,
|
24
|
+
# the octocats team in the octo-org organization owns all .txt files.
|
25
|
+
.github/ @suvie-eng/software-admin
|
26
|
+
|
27
|
+
# In this example, @doctocat owns any files in the build/logs
|
28
|
+
# directory at the root of the repository and any of its
|
29
|
+
# subdirectories.
|
30
|
+
# /build/logs/ @doctocat
|
31
|
+
|
32
|
+
# The `docs/*` pattern will match files like
|
33
|
+
# `docs/getting-started.md` but not further nested files like
|
34
|
+
# `docs/build-app/troubleshooting.md`.
|
35
|
+
# docs/* docs@example.com
|
36
|
+
|
37
|
+
# In this example, @octocat owns any file in an apps directory
|
38
|
+
# anywhere in your repository.
|
39
|
+
# apps/ @octocat
|
40
|
+
|
41
|
+
# In this example, @doctocat owns any file in the `/docs`
|
42
|
+
# directory in the root of your repository and any of its
|
43
|
+
# subdirectories.
|
44
|
+
# /docs/ @doctocat
|
45
|
+
|
46
|
+
# In this example, any change inside the `/scripts` directory
|
47
|
+
# will require approval from @doctocat or @octocat.
|
48
|
+
# /scripts/ @doctocat @octocat
|
49
|
+
|
50
|
+
# In this example, @octocat owns any file in the `/apps`
|
51
|
+
# directory in the root of your repository except for the `/apps/github`
|
52
|
+
# subdirectory, as its owners are left empty.
|
53
|
+
# /apps/ @octocat
|
54
|
+
# /apps/github
|
@@ -0,0 +1,50 @@
|
|
1
|
+
name: CI
|
2
|
+
# actions ref: https://github.com/fac/ruby-gem-push-action
|
3
|
+
# https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
pull_request:
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
# build:
|
13
|
+
# runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
# steps: # (your tests go here)
|
16
|
+
|
17
|
+
release:
|
18
|
+
name: Gem / Release
|
19
|
+
# needs: test # Only release IF the tests pass
|
20
|
+
runs-on: ubuntu-latest
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- uses: ruby/setup-ruby@v1.111.0
|
25
|
+
with:
|
26
|
+
ruby-version: '2.7.2' # Not needed with a .ruby-version file
|
27
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
28
|
+
- uses: fac/ruby-gem-setup-credentials-action@v2
|
29
|
+
with:
|
30
|
+
token: ${{ secrets.GH_TOKEN }}
|
31
|
+
|
32
|
+
- name: Build Gem
|
33
|
+
# run: bundle exec rake build
|
34
|
+
run: gem build
|
35
|
+
|
36
|
+
# Release production gem version from default branch
|
37
|
+
- name: Release Gem
|
38
|
+
if: github.ref == 'refs/heads/main'
|
39
|
+
uses: fac/ruby-gem-push-action@v2
|
40
|
+
with:
|
41
|
+
gem-glob: '*.gem'
|
42
|
+
key: github
|
43
|
+
|
44
|
+
# PR branch builds will release pre-release gems
|
45
|
+
# - name: Pre-Release Gem
|
46
|
+
# if: github.ref != 'refs/heads/main'
|
47
|
+
# uses: fac/ruby-gem-push-action@v2
|
48
|
+
# with:
|
49
|
+
# key: github
|
50
|
+
# pre-release: true
|
data/.gitignore
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -9,12 +9,12 @@
|
|
9
9
|
# Offense count: 1
|
10
10
|
Lint/UselessAssignment:
|
11
11
|
Exclude:
|
12
|
-
- 'app/controllers/spree/
|
12
|
+
- 'app/controllers/spree/bactracs_controller.rb'
|
13
13
|
|
14
14
|
# Offense count: 1
|
15
15
|
RSpec/AnyInstance:
|
16
16
|
Exclude:
|
17
|
-
- 'spec/lib/
|
17
|
+
- 'spec/lib/solidus_bactracs/shipment_notice_spec.rb'
|
18
18
|
|
19
19
|
# Offense count: 5
|
20
20
|
RSpec/MultipleExpectations:
|
@@ -29,7 +29,7 @@ RSpec/NestedGroups:
|
|
29
29
|
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
|
30
30
|
Rails/SkipsModelValidations:
|
31
31
|
Exclude:
|
32
|
-
- 'spec/lib/
|
32
|
+
- 'spec/lib/solidus_bactracs/shipment_notice_spec.rb'
|
33
33
|
- 'spec/models/spree/shipment_spec.rb'
|
34
34
|
- 'spec/support/shipment_helper.rb'
|
35
35
|
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.2
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.7.2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 3.1.2
|
4
|
+
Fully include retry support tables and methods within the gem. Earlier in 3.1.x some migrations, etc, were expected to be handled by the host rails app.
|
5
|
+
|
6
|
+
## 3.1.0
|
7
|
+
Different retry support for CreateRMA, as well as more logging
|
8
|
+
|
9
|
+
## 3.0.x
|
10
|
+
Re-release the gem under a new non-forked repo, since this gem is a non-mergeable divergence from the solidus_shipstation gem
|
11
|
+
|
3
12
|
## 2.2.0
|
4
13
|
|
5
14
|
Support the Solidus Assembly gem, consider allowed SKUs within assemblies/bundles
|
@@ -7,7 +16,7 @@ Retry logic for the authenticated request
|
|
7
16
|
|
8
17
|
## 2.1.0
|
9
18
|
|
10
|
-
New auth and API patterns for
|
19
|
+
New auth and API patterns for Bactracs
|
11
20
|
Support specific SKUs to be mapped
|
12
21
|
|
13
22
|
## 2.0.0
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Solidus Bactracs
|
2
2
|
|
3
3
|
|
4
|
-
This gem integrates [Bactracs](http://www.
|
4
|
+
This gem integrates [Bactracs](http://www.bactracs.com) with [Solidus](http://solidus.io). It
|
5
5
|
enables your Solidus system to push shipment RMAs to the system.
|
6
6
|
|
7
7
|
> This integration was cloned from [spree_shipstation](https://github.com/DynamoMTL/spree_shipstation) to provide some consistency with other Solidus<-->Shipping related patterns.
|
@@ -28,11 +28,12 @@ used by the extension.
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
This extension can integrate with
|
31
|
+
This extension can integrate with Bactracs via SOAP-based XML API integration. The gem currently makes SOAP 1.1 format calls, though the API support SOAP 1.2
|
32
|
+
|
32
33
|
|
33
34
|
### XML integration
|
34
35
|
|
35
|
-
The [XML integration](https://help.
|
36
|
+
The [XML integration](https://help.bactracs.com/hc/en-us/articles/360025856192-Custom-Store-Development-Guide)
|
36
37
|
works by exposing a route in your Solidus application that generates an XML feed of all recently
|
37
38
|
created and updated shipments in your Solidus store.
|
38
39
|
|
@@ -45,7 +46,7 @@ configuration initializer, and configure your ShipStation store accordingly:
|
|
45
46
|
|
46
47
|
- **Username**: the username defined in your configuration.
|
47
48
|
- **Password**: the password defined in your configuration.
|
48
|
-
- **URL to custom page**: `https://yourdomain.com/
|
49
|
+
- **URL to custom page**: `https://yourdomain.com/bactracs.xml`.
|
49
50
|
|
50
51
|
You can also configure your ShipStation store to pull the XML feed automatically on a recurring
|
51
52
|
basis, or manually by clicking the "Refresh stores" button.
|
@@ -80,7 +81,7 @@ There are a few gotchas you need to be aware of:
|
|
80
81
|
|
81
82
|
### API integration
|
82
83
|
|
83
|
-
The [API integration](https://www.
|
84
|
+
The [API integration](https://www.bactracs.com/docs/api/) works by calling the ShipStation API
|
84
85
|
to sync all of your shipments continuously.
|
85
86
|
|
86
87
|
Because ShipStation has very low rate limits (i.e., 40 reqs/minute at the time of writing), the
|
@@ -89,7 +90,7 @@ from a traditional API integration.
|
|
89
90
|
|
90
91
|
Instead, a background job runs on a recurring basis and batches together all the shipments that need
|
91
92
|
to be created or updated in ShipStation. These shipments are then sent in groups of 100 (by default)
|
92
|
-
to ShipStation's [bulk order upsert endpoint](https://www.
|
93
|
+
to ShipStation's [bulk order upsert endpoint](https://www.bactracs.com/docs/api/orders/create-update-multiple-orders/).
|
93
94
|
|
94
95
|
This allows us to work around Bactracs's rate limit and sync up to 4000 shipments/minute.
|
95
96
|
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
class
|
4
|
+
class BactracsController < Spree::BaseController
|
5
5
|
protect_from_forgery with: :null_session, only: :shipnotify
|
6
6
|
|
7
|
-
before_action :
|
7
|
+
before_action :authenticate_bactracs
|
8
8
|
|
9
9
|
def export
|
10
|
-
@shipments =
|
11
|
-
@shipments =
|
10
|
+
@shipments = SolidusBactracs::Shipment::ExportableQuery.apply(Spree::Shipment.all)
|
11
|
+
@shipments = SolidusBactracs::Shipment::BetweenQuery.apply(
|
12
12
|
@shipments,
|
13
13
|
from: date_param(:start_date),
|
14
14
|
to: date_param(:end_date),
|
@@ -21,10 +21,10 @@ module Spree
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def shipnotify
|
24
|
-
shipment_notice_class =
|
24
|
+
shipment_notice_class = SolidusBactracs.configuration.shipment_notice_class.constantize
|
25
25
|
shipment_notice_class.from_payload(params.to_unsafe_h).apply
|
26
26
|
head :ok
|
27
|
-
rescue
|
27
|
+
rescue SolidusBactracs::Error => e
|
28
28
|
head :bad_request
|
29
29
|
end
|
30
30
|
|
@@ -36,10 +36,10 @@ module Spree
|
|
36
36
|
Time.strptime("#{params[name]} UTC", '%m/%d/%Y %H:%M %Z')
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def authenticate_bactracs
|
40
40
|
authenticate_or_request_with_http_basic do |username, password|
|
41
|
-
username ==
|
42
|
-
password ==
|
41
|
+
username == SolidusBactracs.configuration.username &&
|
42
|
+
password == SolidusBactracs.configuration.password
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBactracs
|
4
|
+
module Spree
|
5
|
+
module ShipmentDecorator
|
6
|
+
def self.prepended(base)
|
7
|
+
base.singleton_class.prepend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
def verify_bactracs_sync!
|
11
|
+
if bactracs_sync_verified_at.nil?
|
12
|
+
# API call to verify RMAs of shipments
|
13
|
+
if BactracsService.new.rma_was_synced?(self)
|
14
|
+
self.update_column(:bactracs_sync_verified_at, Time.now)
|
15
|
+
else
|
16
|
+
self.update_column(:bactracs_synced_at, nil)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
rescue => e
|
20
|
+
Rails.logger.error({ message: "#{e.message}, file: shipment_decorator.rb", shipment_number: number })
|
21
|
+
end
|
22
|
+
|
23
|
+
module ClassMethods
|
24
|
+
def exportable
|
25
|
+
::Spree::Deprecation.warn <<~DEPRECATION
|
26
|
+
`Spree::Shipment.exportable` is deprecated and will be removed in a future version
|
27
|
+
of solidus_bactracs. Please use `SolidusBactracs::Shipment::ExportableQuery.apply`.
|
28
|
+
DEPRECATION
|
29
|
+
|
30
|
+
SolidusBactracs::Shipment::ExportableQuery.apply(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def between(from, to)
|
34
|
+
::Spree::Deprecation.warn <<~DEPRECATION
|
35
|
+
`Spree::Shipment.between` is deprecated and will be removed in a future version
|
36
|
+
of solidus_bactracs. Please use `SolidusBactracs::Shipment::BetweenQuery.apply`.
|
37
|
+
DEPRECATION
|
38
|
+
|
39
|
+
SolidusBactracs::Shipment::BetweenQuery.apply(self, from: from, to: to)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
::Spree::Shipment.prepend self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'builder'
|
4
4
|
|
5
|
-
module
|
5
|
+
module SolidusBactracs
|
6
6
|
module ExportHelper
|
7
7
|
DATE_FORMAT = '%m/%d/%Y %H:%M'
|
8
8
|
BACTRACS_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S'
|
@@ -29,7 +29,7 @@ module SolidusBacktracs
|
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.
|
32
|
+
def self.bactracs_address(xml, order, type)
|
33
33
|
address = order.send("#{type}_address")
|
34
34
|
if address.present?
|
35
35
|
name = "#{type.to_s.titleize}To"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SolidusBactracs
|
4
4
|
module Api
|
5
5
|
class ScheduleShipmentSyncsJob < ApplicationJob
|
6
6
|
queue_as :default
|
@@ -9,24 +9,24 @@ module SolidusBacktracs
|
|
9
9
|
shipments = query_shipments
|
10
10
|
Rails.logger.info("#{self.class.name} - #{shipments.count} shipments to sync to Bactracs")
|
11
11
|
|
12
|
-
shipments.find_in_batches(batch_size:
|
12
|
+
shipments.find_in_batches(batch_size: SolidusBactracs.config.api_batch_size) do |batch|
|
13
13
|
SyncShipmentsJob.perform_later(batch.to_a)
|
14
14
|
end
|
15
15
|
rescue StandardError => e
|
16
|
-
|
16
|
+
SolidusBactracs.config.error_handler.call(e, {})
|
17
17
|
end
|
18
18
|
|
19
19
|
def shippable_skus
|
20
|
-
|
20
|
+
SolidusBactracs.config.shippable_skus.present? ? SolidusBactracs.config.shippable_skus : Spree::Variant.pluck(:sku)
|
21
21
|
end
|
22
22
|
|
23
23
|
def query_shipments
|
24
|
-
shipments =
|
24
|
+
shipments = SolidusBactracs::Shipment::PendingApiSyncQuery.apply(
|
25
25
|
::Spree::Shipment
|
26
26
|
.joins(inventory_units: [:variant])
|
27
|
-
.where("spree_variants.sku" =>
|
27
|
+
.where("spree_variants.sku" => SolidusBactracs.config.shippable_skus)
|
28
28
|
.where("spree_shipments.state" => :ready)
|
29
|
-
.where(
|
29
|
+
.where(bactracs_synced_at: nil)
|
30
30
|
.distinct
|
31
31
|
)
|
32
32
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SolidusBactracs
|
4
4
|
module Api
|
5
5
|
class SyncShipmentsJob < ApplicationJob
|
6
6
|
queue_as :default
|
@@ -10,10 +10,14 @@ module SolidusBacktracs
|
|
10
10
|
return if shipments.empty?
|
11
11
|
|
12
12
|
sync_shipments(shipments)
|
13
|
+
|
14
|
+
# Verify bactracs sync
|
15
|
+
shipments.each { |shipment| VerifyBactracsSyncWorker.perform_async(shipment.id) }
|
16
|
+
|
13
17
|
rescue RateLimitedError => e
|
14
18
|
self.class.set(wait: e.retry_in).perform_later
|
15
19
|
rescue StandardError => e
|
16
|
-
|
20
|
+
SolidusBactracs.config.error_handler.call(e, {})
|
17
21
|
end
|
18
22
|
|
19
23
|
private
|
@@ -24,7 +28,7 @@ module SolidusBacktracs
|
|
24
28
|
true
|
25
29
|
else
|
26
30
|
::Spree::Event.fire(
|
27
|
-
'
|
31
|
+
'solidus_bactracs.api.sync_skipped',
|
28
32
|
shipment: shipment,
|
29
33
|
)
|
30
34
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SolidusBactracs
|
4
4
|
module Shipment
|
5
5
|
class ExportableQuery
|
6
6
|
def self.apply(scope)
|
@@ -9,11 +9,11 @@ module SolidusBacktracs
|
|
9
9
|
.joins(:order)
|
10
10
|
.merge(::Spree::Order.complete)
|
11
11
|
|
12
|
-
unless
|
12
|
+
unless SolidusBactracs.configuration.capture_at_notification
|
13
13
|
scope = scope.where(spree_shipments: { state: ['ready', 'canceled'] })
|
14
14
|
end
|
15
15
|
|
16
|
-
unless
|
16
|
+
unless SolidusBactracs.configuration.export_canceled_shipments
|
17
17
|
scope = scope.where.not(spree_shipments: { state: 'canceled' })
|
18
18
|
end
|
19
19
|
|
@@ -1,23 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module SolidusBactracs
|
4
4
|
module Shipment
|
5
5
|
class PendingApiSyncQuery
|
6
6
|
SQLITE_CONDITION = <<~SQL.squish
|
7
7
|
(
|
8
|
-
spree_shipments.
|
8
|
+
spree_shipments.bactracs_synced_at IS NULL
|
9
9
|
) AND ((JULIANDAY(CURRENT_TIMESTAMP) - JULIANDAY(spree_orders.updated_at)) * 86400.0) < :threshold
|
10
10
|
SQL
|
11
11
|
|
12
12
|
POSTGRES_CONDITION = <<~SQL.squish
|
13
13
|
(
|
14
|
-
spree_shipments.
|
14
|
+
spree_shipments.bactracs_synced_at IS NULL
|
15
15
|
) AND (EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP - spree_orders.updated_at))) < :threshold
|
16
16
|
SQL
|
17
17
|
|
18
18
|
MYSQL2_CONDITION = <<~SQL.squish
|
19
19
|
(
|
20
|
-
spree_shipments.
|
20
|
+
spree_shipments.bactracs_synced_at IS NULL
|
21
21
|
) AND (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(spree_orders.updated_at)) < :threshold
|
22
22
|
SQL
|
23
23
|
|
@@ -26,7 +26,7 @@ module SolidusBacktracs
|
|
26
26
|
scope
|
27
27
|
.joins(:order)
|
28
28
|
.merge(::Spree::Order.complete)
|
29
|
-
.where(condition_for_adapter, threshold:
|
29
|
+
.where(condition_for_adapter, threshold: SolidusBactracs.config.api_sync_threshold / 1.second)
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
@@ -42,7 +42,7 @@ module SolidusBacktracs
|
|
42
42
|
when /mysql2/
|
43
43
|
MYSQL2_CONDITION
|
44
44
|
else
|
45
|
-
fail "
|
45
|
+
fail "Bactracs API sync not supported for DB adapter #{db_adapter}!"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -9,9 +9,9 @@ xml.Orders(pages: (@shipments.total_count / 50.0).ceil) {
|
|
9
9
|
xml.Order {
|
10
10
|
xml.OrderID shipment.id
|
11
11
|
xml.OrderNumber shipment.number # do not use shipment.order.number as this presents lookup issues
|
12
|
-
xml.OrderDate order.completed_at.strftime(
|
12
|
+
xml.OrderDate order.completed_at.strftime(SolidusBactracs::ExportHelper::DATE_FORMAT)
|
13
13
|
xml.OrderStatus shipment.state
|
14
|
-
xml.LastModified [order.completed_at, shipment.updated_at].max.strftime(
|
14
|
+
xml.LastModified [order.completed_at, shipment.updated_at].max.strftime(SolidusBactracs::ExportHelper::DATE_FORMAT)
|
15
15
|
xml.ShippingMethod shipment.shipping_method.try(:name)
|
16
16
|
xml.OrderTotal order.total
|
17
17
|
xml.TaxAmount order.tax_total
|
@@ -25,8 +25,8 @@ xml.Orders(pages: (@shipments.total_count / 50.0).ceil) {
|
|
25
25
|
|
26
26
|
xml.Customer {
|
27
27
|
xml.CustomerCode order.email.slice(0, 50)
|
28
|
-
|
29
|
-
|
28
|
+
SolidusBactracs::ExportHelper.address(xml, order, :bill)
|
29
|
+
SolidusBactracs::ExportHelper.address(xml, order, :ship)
|
30
30
|
}
|
31
31
|
xml.Items {
|
32
32
|
shipment.line_items.each do |line|
|
@@ -36,7 +36,7 @@ xml.Orders(pages: (@shipments.total_count / 50.0).ceil) {
|
|
36
36
|
xml.Name [variant.product.name, variant.options_text].join(' ')
|
37
37
|
xml.ImageUrl variant.images.first.try(:attachment).try(:url)
|
38
38
|
xml.Weight variant.weight.to_f
|
39
|
-
xml.WeightUnits
|
39
|
+
xml.WeightUnits SolidusBactracs.configuration.weight_units
|
40
40
|
xml.Quantity line.quantity
|
41
41
|
xml.UnitPrice line.price
|
42
42
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class VerifyBactracsSyncWorker
|
4
|
+
include Sidekiq::Worker
|
5
|
+
|
6
|
+
sidekiq_options queue: 'default'
|
7
|
+
|
8
|
+
def perform(shipment_id)
|
9
|
+
shipment = Spree::Shipment.find_by(id: shipment_id)
|
10
|
+
if shipment
|
11
|
+
shipment.verify_bactracs_sync!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/bin/console
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# frozen_string_literal: true
|
4
4
|
|
5
5
|
require "bundler/setup"
|
6
|
-
require "
|
6
|
+
require "solidus_bactracs"
|
7
7
|
|
8
8
|
# You can add fixtures and/or initialization code here to make experimenting
|
9
9
|
# with your gem easier. You can also use a different console, if you like.
|
data/bin/rails-engine
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# installed from the root of your application.
|
4
4
|
|
5
5
|
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
-
ENGINE_PATH = File.expand_path('../lib/
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_bactracs/engine', __dir__)
|
7
7
|
|
8
8
|
# Set up gems listed in the Gemfile.
|
9
9
|
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
data/bin/sandbox
CHANGED
data/config/routes.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# NOTE: This migration is only required if you use the API integration strategy.
|
3
|
+
# If you're using the XML file instead, you can safely skip these columns.
|
4
|
+
|
5
|
+
class AddBactracsApiSyncFields < ActiveRecord::Migration[5.2]
|
6
|
+
def change
|
7
|
+
if !ActiveRecord::Base.connection.column_exists?(:spree_shipments, :bactracs_synced_at)
|
8
|
+
add_column :spree_shipments, :bactracs_synced_at, :datetime
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class BactracsTypoCorrection < ActiveRecord::Migration[5.2]
|
4
|
+
def change
|
5
|
+
if ( ActiveRecord::Base.connection.column_exists?(:spree_shipments, :backtracs_synced_at) &&
|
6
|
+
!ActiveRecord::Base.connection.column_exists?(:spree_shipments, :bactracs_synced_at))
|
7
|
+
rename_column :spree_shipments, :backtracs_synced_at, :bactracs_synced_at
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|