erp_integration 0.11.0 → 0.13.0
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/.github/workflows/pull_requests.yml +1 -1
- data/.reek.yml +2 -1
- data/erp_integration.gemspec +1 -1
- data/lib/erp_integration/configuration.rb +18 -0
- data/lib/erp_integration/fulfil/api_resource.rb +34 -20
- data/lib/erp_integration/fulfil/context.rb +47 -0
- data/lib/erp_integration/fulfil/persistence.rb +11 -0
- data/lib/erp_integration/fulfil/resources/sales_order.rb +49 -0
- data/lib/erp_integration/fulfil/resources/sales_return_reason.rb +13 -0
- data/lib/erp_integration/fulfil/resources/tracking_number.rb +13 -0
- data/lib/erp_integration/resources/persistence.rb +9 -0
- data/lib/erp_integration/sales_order.rb +12 -0
- data/lib/erp_integration/sales_return_reason.rb +12 -0
- data/lib/erp_integration/tracking_number.rb +15 -0
- data/lib/erp_integration/version.rb +1 -1
- data/lib/erp_integration.rb +2 -0
- metadata +14 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33c09fbc8ebeff2b8b907e88e8b9bc147aefba15d5f7c1245de69cf66b24a8e6
|
4
|
+
data.tar.gz: c4ffdceea9bd5510bbee71647868e54a1ef36cc58bd7832a9333216811a3dd81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e7a15d4a90a16905aab8c8be40e751c3b16148ad616631e6adad6033fdf444eeaeb9d6f37e30ba4639f17f5a1a7e800281051a2e98e44aa93936e74eed7c0de
|
7
|
+
data.tar.gz: bfba3edd52a0529d5ca11457b12ab255c3aed41fb2ca08df17c2c09333fa7c22c76ce96a0b96436c84327b62442d4129429d5a928863e5185c3724d926ddcef2
|
data/.reek.yml
CHANGED
data/erp_integration.gemspec
CHANGED
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
|
|
45
45
|
spec.add_development_dependency 'rubocop', '< 0.82.0'
|
46
46
|
spec.add_development_dependency 'rubocop-rake', '~> 0.5'
|
47
47
|
spec.add_development_dependency 'rubocop-rspec', '< 1.39.0'
|
48
|
-
spec.add_development_dependency 'webmock', '~> 3.
|
48
|
+
spec.add_development_dependency 'webmock', '~> 3.17.0'
|
49
49
|
|
50
50
|
# The `parallel` gem is a dev dependency for Rubocop. However, the versions
|
51
51
|
# for parallel after 1.19.2 don't work with ruby 2.3.x. As ruby 2.3.x is
|
@@ -82,6 +82,11 @@ module ErpIntegration
|
|
82
82
|
# @return [Symbol] The configured adapter for the order lines.
|
83
83
|
attr_writer :sales_order_line_adapter
|
84
84
|
|
85
|
+
# Allows configuring an adapter for the `SalesReturnReason` resource. When none is
|
86
|
+
# configured, it will default to Fulfil.
|
87
|
+
# @return [Symbol] The configured adapter for the order lines.
|
88
|
+
attr_writer :sales_return_reason_adapter
|
89
|
+
|
85
90
|
# Allows configuring an adapter for the `SupplierShipment` resource. When
|
86
91
|
# none is configured, it will default to Fulfil.
|
87
92
|
# @return [Symbol] The configured adapter for the supplier shipment.
|
@@ -92,6 +97,11 @@ module ErpIntegration
|
|
92
97
|
# @return [Symbol] The configured adapter for the stock move.
|
93
98
|
attr_writer :stock_move_adapter
|
94
99
|
|
100
|
+
# Allows configuring an adapter for the `TrackingNumber` resource. When
|
101
|
+
# none is configured, it will default to Fulfil.
|
102
|
+
# @return [Symbol] The configured adapter for the tracking number.
|
103
|
+
attr_writer :tracking_number_adapter
|
104
|
+
|
95
105
|
# Logger that will be used for HTTP operations on Client
|
96
106
|
# @return [Logger] The configured logger
|
97
107
|
attr_accessor :logger
|
@@ -150,6 +160,10 @@ module ErpIntegration
|
|
150
160
|
@sales_order_adapter || :fulfil
|
151
161
|
end
|
152
162
|
|
163
|
+
def sales_return_reason_adapter
|
164
|
+
@sales_return_reason_adapter || :fulfil
|
165
|
+
end
|
166
|
+
|
153
167
|
def supplier_shipment_adapter
|
154
168
|
@supplier_shipment_adapter || :fulfil
|
155
169
|
end
|
@@ -157,6 +171,10 @@ module ErpIntegration
|
|
157
171
|
def stock_move_adapter
|
158
172
|
@stock_move_adapter || :fulfil
|
159
173
|
end
|
174
|
+
|
175
|
+
def tracking_number_adapter
|
176
|
+
@tracking_number_adapter || :fulfil
|
177
|
+
end
|
160
178
|
end
|
161
179
|
|
162
180
|
# Returns ERP Integration's configuration.
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'context'
|
3
4
|
require_relative 'finder_methods'
|
4
5
|
require_relative 'persistence'
|
5
6
|
require_relative 'query_methods'
|
@@ -7,6 +8,7 @@ require_relative 'query_methods'
|
|
7
8
|
module ErpIntegration
|
8
9
|
module Fulfil
|
9
10
|
class ApiResource
|
11
|
+
include Context
|
10
12
|
include Enumerable
|
11
13
|
include FinderMethods
|
12
14
|
include Persistence
|
@@ -19,26 +21,6 @@ module ErpIntegration
|
|
19
21
|
@resource_klass = resource_klass
|
20
22
|
end
|
21
23
|
|
22
|
-
# The `where` and `includes` methods lazyly build a search/read query
|
23
|
-
# for Fulfil. By calling `all`, the prepared search/read query will actually
|
24
|
-
# be executed and the results will be fetched.
|
25
|
-
# @return [Array] An enumerable collection object with all API results.
|
26
|
-
def all
|
27
|
-
return @results if defined?(@results)
|
28
|
-
|
29
|
-
@results =
|
30
|
-
client.put(
|
31
|
-
"model/#{model_name}/search_read",
|
32
|
-
Query.new(selected_fields, where_clauses)
|
33
|
-
).map { |item| resource_klass.new(item) }
|
34
|
-
end
|
35
|
-
|
36
|
-
# The `each` method turns the `ApiResource` instance into an enumerable object.
|
37
|
-
# For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
|
38
|
-
def each(&block)
|
39
|
-
all.each(&block)
|
40
|
-
end
|
41
|
-
|
42
24
|
# The `client` exposes the `ErpIntegration::Fulfil::Client` to the class.
|
43
25
|
# @return [ErpIntegration::Fulfil::Client] The HTTP client for Fulfil.
|
44
26
|
def self.client
|
@@ -70,6 +52,38 @@ module ErpIntegration
|
|
70
52
|
def self.model_name
|
71
53
|
instance_variable_get(:@model_name)
|
72
54
|
end
|
55
|
+
|
56
|
+
# The `where` and `includes` methods lazyly build a search/read query
|
57
|
+
# for Fulfil. By calling `all`, the prepared search/read query will actually
|
58
|
+
# be executed and the results will be fetched.
|
59
|
+
# @return [Array] An enumerable collection object with all API results.
|
60
|
+
def all
|
61
|
+
return @results if defined?(@results)
|
62
|
+
|
63
|
+
@results =
|
64
|
+
client.put(
|
65
|
+
api_resource_path,
|
66
|
+
Query.new(selected_fields, where_clauses)
|
67
|
+
).map { |item| resource_klass.new(item) }
|
68
|
+
end
|
69
|
+
|
70
|
+
# The `each` method turns the `ApiResource` instance into an enumerable object.
|
71
|
+
# For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
|
72
|
+
def each(&block)
|
73
|
+
all.each(&block)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Builds the relative resource path and adds the context if needed.
|
79
|
+
#
|
80
|
+
# @return [String]
|
81
|
+
def api_resource_path
|
82
|
+
base_path = "model/#{model_name}/search_read"
|
83
|
+
return base_path unless context?
|
84
|
+
|
85
|
+
"#{base_path}?context=#{context.to_json}"
|
86
|
+
end
|
73
87
|
end
|
74
88
|
end
|
75
89
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Fulfil
|
5
|
+
# When making HTTP requests to the Fulfil API endpoints, it's possible to define
|
6
|
+
# the warehouses that should be considered part of the querying context.
|
7
|
+
#
|
8
|
+
# This means that it's possible to fetch the stock levels for a specific "warehouse"
|
9
|
+
# when it's specified in the context of the HTTP request to the API endpoints of
|
10
|
+
# Fulfil.
|
11
|
+
#
|
12
|
+
# @example without any context, the main warehouse will be used as configured
|
13
|
+
# in Fulfil through the application settings.
|
14
|
+
#
|
15
|
+
# $ ErpIntegration::Product.find_by(sku: "PT123").quantity_available
|
16
|
+
# => 25
|
17
|
+
#
|
18
|
+
# @example with context, the given warehouse will be used to find the requested
|
19
|
+
# data in Fulfil.
|
20
|
+
#
|
21
|
+
# $ ErpIntegration::Product.with_context(locations: [25]).find_by(sku: "PT123").quantity_available
|
22
|
+
# => 15
|
23
|
+
module Context
|
24
|
+
extend ActiveSupport::Concern
|
25
|
+
|
26
|
+
included do
|
27
|
+
attr_accessor :context
|
28
|
+
end
|
29
|
+
|
30
|
+
# Verifies whether or not the context is set.
|
31
|
+
#
|
32
|
+
# @return [Boolean]
|
33
|
+
def context?
|
34
|
+
!@context.nil? && !@context.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Allows setting the context for the HTTP request to the Fulfil API endpoints.
|
38
|
+
#
|
39
|
+
# @param context [Hash] The context for the HTTP request.
|
40
|
+
# @return [ErpIntegration::Fulfil::ApiResource]
|
41
|
+
def with_context(context)
|
42
|
+
@context = (@context || {}).merge(context)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -27,6 +27,17 @@ module ErpIntegration
|
|
27
27
|
[attributes, [extract_error_message(e)]]
|
28
28
|
end
|
29
29
|
|
30
|
+
# Destroys the resource.
|
31
|
+
#
|
32
|
+
# @param resource_id [Integer] The ID of the resource.
|
33
|
+
# @return [Boolean] Returns true if the resource was deleted
|
34
|
+
def destroy(resource_id)
|
35
|
+
client.delete("model/#{model_name}/#{resource_id}")
|
36
|
+
{ id: resource_id }
|
37
|
+
rescue ErpIntegration::HttpError::BadRequest => e
|
38
|
+
[{ id: resource_id }, [extract_error_message(e)]]
|
39
|
+
end
|
40
|
+
|
30
41
|
private
|
31
42
|
|
32
43
|
# Fulfil returns a 400 status code (e.g. Bad Request) with the error message
|
@@ -28,6 +28,55 @@ module ErpIntegration
|
|
28
28
|
rescue Faraday::ParsingError
|
29
29
|
true
|
30
30
|
end
|
31
|
+
|
32
|
+
# Allows duplicating the entire sales order in Fulfil.
|
33
|
+
# @param id [Integer|String] The ID of the to be duplicated order.
|
34
|
+
# @return [Array|boolean] Whether the sales order was duplicated successfully or not.
|
35
|
+
def duplicate(id)
|
36
|
+
duplicated_order_id = client.put("model/sale.sale/#{id}/copy").first
|
37
|
+
ErpIntegration::SalesOrder.new(id: duplicated_order_id)
|
38
|
+
|
39
|
+
# Fulfil will return an 400 (a.k.a. "Bad Request") status code when a sales order couldn't
|
40
|
+
# be duplicated.
|
41
|
+
rescue ErpIntegration::HttpError::BadRequest
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
# Confirm the order on Fulfil.
|
46
|
+
# @param id [Integer|String] The ID of the to be confirmed order.
|
47
|
+
# @return [boolean] Whether the sales order was confirmed successfully or not.
|
48
|
+
def confirm(id)
|
49
|
+
client.put("model/sale.sale/#{id}/confirm")
|
50
|
+
true
|
51
|
+
|
52
|
+
# Fulfil will return an 400 (a.k.a. "Bad Request") status code when a sales order couldn't
|
53
|
+
# be confirmed.
|
54
|
+
rescue ErpIntegration::HttpError::BadRequest
|
55
|
+
false
|
56
|
+
# Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok")
|
57
|
+
# and faraday is having an error when trying to parse it. Let's skip the parse error
|
58
|
+
# and move on.
|
59
|
+
rescue Faraday::ParsingError
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
# Process the order on Fulfil.
|
64
|
+
# @param id [Integer|String] The ID of the to be processed order.
|
65
|
+
# @return [boolean] Whether the sales order was processed successfully or not.
|
66
|
+
def process(id)
|
67
|
+
client.put("model/sale.sale/#{id}/process")
|
68
|
+
true
|
69
|
+
|
70
|
+
# Fulfil will return an 400 (a.k.a. "Bad Request") status code when a sales order couldn't
|
71
|
+
# be processed.
|
72
|
+
rescue ErpIntegration::HttpError::BadRequest
|
73
|
+
false
|
74
|
+
# Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok")
|
75
|
+
# and faraday is having an error when trying to parse it. Let's skip the parse error
|
76
|
+
# and move on.
|
77
|
+
rescue Faraday::ParsingError
|
78
|
+
true
|
79
|
+
end
|
31
80
|
end
|
32
81
|
end
|
33
82
|
end
|
@@ -35,6 +35,15 @@ module ErpIntegration
|
|
35
35
|
assign_attributes(attrs)
|
36
36
|
validate_with(error_messages)
|
37
37
|
end
|
38
|
+
|
39
|
+
# Destroy an resource in the ERP.
|
40
|
+
# @return [Boolean] Whether the destroy action was succcesful or not.
|
41
|
+
def destroy(id)
|
42
|
+
attrs, error_messages = self.class.adapter.destroy(id)
|
43
|
+
|
44
|
+
assign_attributes(attrs)
|
45
|
+
validate_with(error_messages)
|
46
|
+
end
|
38
47
|
end
|
39
48
|
end
|
40
49
|
end
|
@@ -19,5 +19,17 @@ module ErpIntegration
|
|
19
19
|
def cancel
|
20
20
|
self.class.adapter.cancel(id)
|
21
21
|
end
|
22
|
+
|
23
|
+
def duplicate
|
24
|
+
self.class.adapter.duplicate(id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def confirm
|
28
|
+
self.class.adapter.confirm(id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def process
|
32
|
+
self.class.adapter.process(id)
|
33
|
+
end
|
22
34
|
end
|
23
35
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
# The `ErpIntegration::SalesReturnReason` exposes an uniformed API for interaction with
|
5
|
+
# third-party ERP vendors.
|
6
|
+
class SalesReturnReason < Resource
|
7
|
+
attr_accessor :attachments, :create_date, :create_uid, :description,
|
8
|
+
:id, :messages, :metadata, :name, :private_notes,
|
9
|
+
:public_notes, :rec_blurb, :rec_name, :write_date,
|
10
|
+
:write_uid
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
# The `ErpIntegration::TrackingNumber` exposes an uniformed API for interaction with
|
5
|
+
# third-party ERP vendors.
|
6
|
+
class TrackingNumber < Resource
|
7
|
+
attr_accessor :attachments, :attempts, :carrier, :carrier_identifier,
|
8
|
+
:carrier_service, :create_date, :create_uid, :delivered_at,
|
9
|
+
:delivered_date, :delivery_date, :delivery_time, :easypost_order_id,
|
10
|
+
:estimated_delivery_date, :id, :is_master, :messages, :metadata,
|
11
|
+
:next_update_at, :origin, :private_notes, :public_notes, :rec_blurb,
|
12
|
+
:rec_name, :reference, :scac, :state, :tracking_number,
|
13
|
+
:tracking_url, :transportation_mode, :write_date, :write_uid
|
14
|
+
end
|
15
|
+
end
|
data/lib/erp_integration.rb
CHANGED
@@ -33,8 +33,10 @@ module ErpIntegration
|
|
33
33
|
autoload :Resource, 'erp_integration/resource'
|
34
34
|
autoload :SalesOrder, 'erp_integration/sales_order'
|
35
35
|
autoload :SalesOrderLine, 'erp_integration/sales_order_line'
|
36
|
+
autoload :SalesReturnReason, 'erp_integration/sales_return_reason'
|
36
37
|
autoload :StockMove, 'erp_integration/stock_move'
|
37
38
|
autoload :SupplierShipment, 'erp_integration/supplier_shipment'
|
39
|
+
autoload :TrackingNumber, 'erp_integration/tracking_number'
|
38
40
|
|
39
41
|
module Resources
|
40
42
|
autoload :Errors, 'erp_integration/resources/errors'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: erp_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -202,14 +202,14 @@ dependencies:
|
|
202
202
|
requirements:
|
203
203
|
- - "~>"
|
204
204
|
- !ruby/object:Gem::Version
|
205
|
-
version: 3.
|
205
|
+
version: 3.17.0
|
206
206
|
type: :development
|
207
207
|
prerelease: false
|
208
208
|
version_requirements: !ruby/object:Gem::Requirement
|
209
209
|
requirements:
|
210
210
|
- - "~>"
|
211
211
|
- !ruby/object:Gem::Version
|
212
|
-
version: 3.
|
212
|
+
version: 3.17.0
|
213
213
|
- !ruby/object:Gem::Dependency
|
214
214
|
name: parallel
|
215
215
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,7 +224,7 @@ dependencies:
|
|
224
224
|
- - '='
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: 1.19.2
|
227
|
-
description:
|
227
|
+
description:
|
228
228
|
email:
|
229
229
|
- stefan@knowndecimal.com
|
230
230
|
executables: []
|
@@ -268,6 +268,7 @@ files:
|
|
268
268
|
- lib/erp_integration/errors.rb
|
269
269
|
- lib/erp_integration/fulfil/api_resource.rb
|
270
270
|
- lib/erp_integration/fulfil/client.rb
|
271
|
+
- lib/erp_integration/fulfil/context.rb
|
271
272
|
- lib/erp_integration/fulfil/finder_methods.rb
|
272
273
|
- lib/erp_integration/fulfil/persistence.rb
|
273
274
|
- lib/erp_integration/fulfil/query.rb
|
@@ -284,8 +285,10 @@ files:
|
|
284
285
|
- lib/erp_integration/fulfil/resources/purchase_request.rb
|
285
286
|
- lib/erp_integration/fulfil/resources/sales_order.rb
|
286
287
|
- lib/erp_integration/fulfil/resources/sales_order_line.rb
|
288
|
+
- lib/erp_integration/fulfil/resources/sales_return_reason.rb
|
287
289
|
- lib/erp_integration/fulfil/resources/stock_move.rb
|
288
290
|
- lib/erp_integration/fulfil/resources/supplier_shipment.rb
|
291
|
+
- lib/erp_integration/fulfil/resources/tracking_number.rb
|
289
292
|
- lib/erp_integration/fulfil/where_clause.rb
|
290
293
|
- lib/erp_integration/middleware/error_handling.rb
|
291
294
|
- lib/erp_integration/product.rb
|
@@ -299,8 +302,10 @@ files:
|
|
299
302
|
- lib/erp_integration/resources/validations.rb
|
300
303
|
- lib/erp_integration/sales_order.rb
|
301
304
|
- lib/erp_integration/sales_order_line.rb
|
305
|
+
- lib/erp_integration/sales_return_reason.rb
|
302
306
|
- lib/erp_integration/stock_move.rb
|
303
307
|
- lib/erp_integration/supplier_shipment.rb
|
308
|
+
- lib/erp_integration/tracking_number.rb
|
304
309
|
- lib/erp_integration/version.rb
|
305
310
|
homepage: https://www.github.com/mejuri-inc/erp-integration
|
306
311
|
licenses:
|
@@ -310,7 +315,7 @@ metadata:
|
|
310
315
|
homepage_uri: https://www.github.com/mejuri-inc/erp-integration
|
311
316
|
source_code_uri: https://www.github.com/mejuri-inc/erp-integration
|
312
317
|
changelog_uri: https://www.github.com/mejuri-inc/erp-integration/blob/main/CHANGELOG.md
|
313
|
-
post_install_message:
|
318
|
+
post_install_message:
|
314
319
|
rdoc_options: []
|
315
320
|
require_paths:
|
316
321
|
- lib
|
@@ -325,8 +330,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
330
|
- !ruby/object:Gem::Version
|
326
331
|
version: '0'
|
327
332
|
requirements: []
|
328
|
-
rubygems_version: 3.
|
329
|
-
signing_key:
|
333
|
+
rubygems_version: 3.2.22
|
334
|
+
signing_key:
|
330
335
|
specification_version: 4
|
331
336
|
summary: Connects Mejuri with third-party ERP vendors
|
332
337
|
test_files: []
|