erp_integration 0.5.5 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +61 -37
- data/lib/erp_integration/configuration.rb +9 -0
- data/lib/erp_integration/customer_shipment_return.rb +22 -0
- data/lib/erp_integration/errors.rb +6 -0
- data/lib/erp_integration/fulfil/api_resource.rb +4 -0
- data/lib/erp_integration/fulfil/finder_methods.rb +53 -0
- data/lib/erp_integration/fulfil/persistence.rb +55 -0
- data/lib/erp_integration/fulfil/resources/customer_shipment_return.rb +13 -0
- data/lib/erp_integration/fulfil/resources/product.rb +1 -1
- data/lib/erp_integration/fulfil/resources/sales_order_line.rb +39 -0
- data/lib/erp_integration/resource.rb +9 -0
- data/lib/erp_integration/resources/errors.rb +32 -0
- data/lib/erp_integration/resources/persistence.rb +40 -0
- data/lib/erp_integration/resources/validations.rb +35 -0
- data/lib/erp_integration/sales_order_line.rb +8 -0
- data/lib/erp_integration/version.rb +1 -1
- data/lib/erp_integration.rb +7 -0
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aa8a1bdac1da55e10572a0f25ad21f3e608d77e014e6abfb1c8e93667dee23f
|
4
|
+
data.tar.gz: 7bda7954766e6925764a2477acdf7dbd5974d8fb463a44ba8ee6d9ad4b695a26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f72a741e0c219a30b961acea16804e9c47d8941e941518942856c20faef421ed0465b58e202ce0b79c29b6289334e6e3ae09e5a82bcc921aecb0d17fbcd80f2
|
7
|
+
data.tar.gz: 210749ddda85e42fa4cd8a4503580ca0c7e53de84f4c5339dd4a7c2476de8da14eb67023bdfafa47ae748481c09965acd53aac1fdd667f949d475ef5b704abfe
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Mejuri's ERP integration
|
2
2
|
|
3
|
-
|
3
|
+
The ERP integration gem allows connecting to multiple ERP at the same time and query the data from these ERP's. It's currently only supporting [Fulfil](https://www.fulfil.io).
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,8 +16,6 @@ Or run the following command to add `ErpIntegration` to your Gemfile:
|
|
16
16
|
$ bundle add erp_integration
|
17
17
|
```
|
18
18
|
|
19
|
-
TODO: Write installation instructions here for the Github package registry.
|
20
|
-
|
21
19
|
## Usage
|
22
20
|
|
23
21
|
### Configuration
|
@@ -32,20 +30,15 @@ ErpIntegration.configure do |config|
|
|
32
30
|
end
|
33
31
|
```
|
34
32
|
|
35
|
-
###
|
36
|
-
|
37
|
-
After configuring the gem, one can easily query all the available ERP resources from the connected third-parties.
|
33
|
+
### Supported Query Methods
|
38
34
|
|
39
|
-
|
40
|
-
$ ErpIntegration::SalesOrder.where(reference: 'MT1000SKX')
|
41
|
-
=> #<ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::SalesOrder @id=100 />] />
|
42
|
-
```
|
35
|
+
After configuring the gem, one can easily query all the available ERP resources from the connected third-parties. In all cases, the API will return a collection of resources.
|
43
36
|
|
44
|
-
|
37
|
+
> **NOTE**: If you need to lookup an individual resource take a look at the "Supported finder methods" section.
|
45
38
|
|
46
39
|
```ruby
|
47
|
-
$ ErpIntegration::SalesOrder.
|
48
|
-
=>
|
40
|
+
$ ErpIntegration::SalesOrder.where(reference: 'MT1000SKX')
|
41
|
+
=> [<ErpIntegration::SalesOrder @id=100 />]
|
49
42
|
```
|
50
43
|
|
51
44
|
There are also other type of `where` queries available:
|
@@ -55,50 +48,81 @@ There are also other type of `where` queries available:
|
|
55
48
|
- `where_in` for inclusion queries.
|
56
49
|
- `where_not_in` for exclusion queries.
|
57
50
|
|
58
|
-
|
51
|
+
### Supported Finder Methods
|
59
52
|
|
60
|
-
|
53
|
+
The __Query Methods__ allow you to lookup a list of resources. The __Finder Methods__ allow you to lookup **an individual resource** from the API.
|
61
54
|
|
62
|
-
|
55
|
+
- `#find` looks up a resource by id and raises `ErpIntegration::ResourceNotFound` when no result is found.
|
56
|
+
- `#find_by` looks up a resource by a given set of query methods and returns `nil` when no result is found.
|
57
|
+
- `#find_by!` looks up a resource by a given set of query methods and raises `ErpIntegration::ResourceNotFound` when no result is found.
|
63
58
|
|
64
|
-
|
59
|
+
A difference between the query methods and the finder methods is the way it's executed. The finder methods are executed directly after they're called. The query methods will be lazily executed.
|
65
60
|
|
66
|
-
|
61
|
+
```ruby
|
62
|
+
$ ErpIntegration::SalesOrder.find(100)
|
63
|
+
# => #<ErpIntegration::SalesOrder @id=100 />
|
67
64
|
|
68
|
-
|
65
|
+
$ ErpIntegration::SalesOrder.find_by(code: "MT100")
|
66
|
+
# => #<ErpIntegration::SalesOrder @id=100 />
|
69
67
|
|
70
|
-
|
68
|
+
$ ErpIntegration::SalesOrder.find_by!(code: "MT100")
|
69
|
+
# => #<ErpIntegration::SalesOrder @id=100 />
|
70
|
+
```
|
71
71
|
|
72
|
-
|
72
|
+
### Supported Selection Methods
|
73
73
|
|
74
|
-
|
74
|
+
By default, only the `id` will be added to ERP resources. However, one can use the `select` method to include more fields.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
$ ErpIntegration::SalesOrder.select(:id, :reference).find_by(reference: 'MT1000SKX')
|
78
|
+
# => <ErpIntegration::SalesOrder @id=100 @reference=MT1000SKX />
|
79
|
+
```
|
80
|
+
|
81
|
+
## Development
|
75
82
|
|
76
|
-
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
### Releasing
|
77
86
|
|
78
|
-
|
87
|
+
**Prerequisites**
|
79
88
|
|
80
89
|
To be able to publish a new release, you'll need to set up a Rubygems account.
|
81
90
|
|
82
91
|
> To begin, you’ll need to create an account on RubyGems.org. Visit the sign up page and supply an email address that you control, a handle (username) and a password.
|
83
92
|
>
|
84
93
|
> After creating the account, use your email and password when pushing the gem. (RubyGems saves the credentials in ~/.gem/credentials for you so you only need to log in once.)
|
85
|
-
>
|
94
|
+
> [Publishing to RubyGems.org](https://guides.rubygems.org/publishing/)
|
86
95
|
|
87
|
-
It's important to note that you'll need the right privileges to publish the gem. Ask @germansvriz to add you as a gem owner.
|
96
|
+
It's important to note that you'll need the right privileges to publish the gem. Ask [@germansvriz](https://github.com/germansvriz) or [@stefanvermaas](https://github.com/stefanvermaas) to add you as a gem owner.
|
88
97
|
|
89
|
-
|
98
|
+
**Publish a new version**
|
90
99
|
|
91
|
-
1
|
92
|
-
```shell
|
93
|
-
$ bin/prerelease 0.0.1
|
94
|
-
```
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
100
|
+
1. Run the prerelease script
|
101
|
+
```shell
|
102
|
+
$ bin/prerelease 0.0.1
|
103
|
+
```
|
104
|
+
|
105
|
+
2. Create Pull Request
|
106
|
+
|
107
|
+
3. Merge it to main
|
108
|
+
|
109
|
+
4. Run Release script
|
110
|
+
```shell
|
111
|
+
$ bin/release 0.0.1
|
112
|
+
```
|
101
113
|
|
102
114
|
We're following [semver](https://semver.org/) for the release process of this gem. Make sure to apply the correct semver version for a new release.
|
103
115
|
|
104
116
|
> **NOTE**: You don't have to add a `v` to the version you want to release. The release script will handle that for you.
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mejuri-inc/erp_integration. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mejuri-inc/erp_integration/blob/main/CODE_OF_CONDUCT.md).
|
121
|
+
|
122
|
+
## License
|
123
|
+
|
124
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
125
|
+
|
126
|
+
## Code of Conduct
|
127
|
+
|
128
|
+
Everyone interacting in the ErpIntegration project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mejuri-inc/erp_integration/blob/main/CODE_OF_CONDUCT.md).
|
@@ -37,6 +37,11 @@ module ErpIntegration
|
|
37
37
|
# @return [Symbol] The configured adapter for the bill_of_material.
|
38
38
|
attr_writer :bill_of_material_output_adapter
|
39
39
|
|
40
|
+
# Allows configuring an adapter for the `CustomerShipmentReturn` resource. When
|
41
|
+
# none is configured, it will default to Fulfil.
|
42
|
+
# @return [Symbol] The configured adapter for the customer shipment.
|
43
|
+
attr_writer :customer_shipment_return_adapter
|
44
|
+
|
40
45
|
# Allows configuring an adapter for the `Product` resource. When none is
|
41
46
|
# configured, it will default to Fulfil.
|
42
47
|
# @return [Symbol] The configured adapter for the products.
|
@@ -100,6 +105,10 @@ module ErpIntegration
|
|
100
105
|
@bill_of_material_output_adapter || :fulfil
|
101
106
|
end
|
102
107
|
|
108
|
+
def customer_shipment_return_adapter
|
109
|
+
@customer_shipment_return_adapter || :fulfil
|
110
|
+
end
|
111
|
+
|
103
112
|
def product_adapter
|
104
113
|
@product_adapter || :fulfil
|
105
114
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
# The `ErpIntegration::CustomerShipmentReturn` exposes an uniformed API for interaction with
|
5
|
+
# third-party ERP vendors.
|
6
|
+
class CustomerShipmentReturn < Resource
|
7
|
+
attr_accessor :aes_itn, :attachments, :available_carrier_services, :carrier,
|
8
|
+
:carrier_billing_account, :carrier_cost_method, :carrier_duties_account,
|
9
|
+
:carrier_service, :channels, :company, :contents_explanation, :contents_type,
|
10
|
+
:cost, :cost_currency, :cost_currency_digits, :create_date, :create_uid,
|
11
|
+
:customer, :customer_location, :customs_items, :delivery_address, :delivery_mode,
|
12
|
+
:done_by, :duties_tax_id, :duties_tax_id_type, :eel_pfc, :effective_date,
|
13
|
+
:eori_number, :id, :incoming_moves, :inventory_moves, :is_international_shipping,
|
14
|
+
:is_shippo, :last_modification, :license_plates, :messages, :metadata, :moves,
|
15
|
+
:packages, :planned_date, :private_notes, :public_notes, :putaway_by, :rec_blurb,
|
16
|
+
:rec_name, :received_by, :reference, :require_customs, :root_packages, :sales,
|
17
|
+
:sent_to_3pl_at, :shipping_instructions, :shipping_manifest, :sscc_code, :state,
|
18
|
+
:total_customs_value, :tpl_status, :tracking_number, :tsv, :warehouse, :warehouse_input,
|
19
|
+
:warehouse_storage, :warehouse_type, :weight, :weight_digits, :weight_uom,
|
20
|
+
:weight_uom_symbol, :write_date, :write_uid
|
21
|
+
end
|
22
|
+
end
|
@@ -17,6 +17,12 @@ module ErpIntegration
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
class ResourceNotFound < Error
|
21
|
+
def initialize
|
22
|
+
super "[ERP Integration] Couldn't find the requested resource."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
20
26
|
class HttpError < Faraday::Error
|
21
27
|
class BadRequest < HttpError; end
|
22
28
|
class AuthorizationRequired < HttpError; end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'finder_methods'
|
4
|
+
require_relative 'persistence'
|
3
5
|
require_relative 'query_methods'
|
4
6
|
|
5
7
|
module ErpIntegration
|
6
8
|
module Fulfil
|
7
9
|
class ApiResource
|
8
10
|
include Enumerable
|
11
|
+
include FinderMethods
|
12
|
+
include Persistence
|
9
13
|
include QueryMethods
|
10
14
|
|
11
15
|
attr_accessor :resource_klass
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Fulfil
|
5
|
+
# The `FinderMethods` add various, simplistic lookup methods to find API resources.
|
6
|
+
# These methods should be the last method in the chain as it will invoke the HTTP
|
7
|
+
# request to Fulfil immediately.
|
8
|
+
#
|
9
|
+
# If you need more attributes than the default ID attribute for an ApiResource
|
10
|
+
# to be returned, add the `select` method before the finder method is being called
|
11
|
+
# in your application code.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# $ ErpIntegration::SalesOrder.select(:id, :product).find(100)
|
15
|
+
# => <ErpIntegration::SalesOrder @id=100 @product=10 />
|
16
|
+
module FinderMethods
|
17
|
+
# Looks up an individual resource based on resource's ID.
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# $ ErpIntegration::SalesOrder.find(100)
|
21
|
+
# => <ErpIntegration::SalesOrder @id=100 />
|
22
|
+
#
|
23
|
+
# @param id [Integer] The ID of the API resource.
|
24
|
+
# @return [ApiResource] The found resource in Fulfil.
|
25
|
+
def find(id)
|
26
|
+
find_by!(id: id) || raise(ResourceNotFound)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Looks up an individual resource based on the given attributes.
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
# $ ErpIntegration::SalesOrder.find_by(product: 10)
|
33
|
+
# => <ErpIntegration::SalesOrder @id=100 />
|
34
|
+
#
|
35
|
+
# @return [ApiResource|nil] The found resource in Fulfil.
|
36
|
+
def find_by(args)
|
37
|
+
where(args).first
|
38
|
+
end
|
39
|
+
|
40
|
+
# Looks up an individual resource based on the given attributes and raises
|
41
|
+
# an `ErpIntegration::ResourceNotFound` when the resource doesn't exist.
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# $ ErpIntegration::SalesOrder.find_by!(product: 10)
|
45
|
+
# => ErpIntegration::ResourceNotFound
|
46
|
+
#
|
47
|
+
# @return [ApiResource|nil] The found resource in Fulfil.
|
48
|
+
def find_by!(args)
|
49
|
+
find_by(args) || raise(ResourceNotFound)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Fulfil
|
5
|
+
module Persistence
|
6
|
+
# Allows creating new resources in Fulfil.
|
7
|
+
#
|
8
|
+
# @param attributes [Hash] A list of attributes for the new resource.
|
9
|
+
# @return [Array|Hash] The response from the API
|
10
|
+
def create(attributes)
|
11
|
+
client
|
12
|
+
.post("model/#{model_name}", normalize_attributes(attributes))
|
13
|
+
.map { |new_record_id| attributes.merge!(id: new_record_id) }
|
14
|
+
.first
|
15
|
+
rescue ErpIntegration::HttpError::BadRequest => e
|
16
|
+
[attributes, [extract_error_message(e)]]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Updates the resource with the given attributes.
|
20
|
+
#
|
21
|
+
# @param resource_id [Integer] The ID of the resource.
|
22
|
+
# @param attributes [Hash] A list of attributes to update for the resource.
|
23
|
+
# @return [Array|Hash] The response from the API
|
24
|
+
def update(resource_id, attributes)
|
25
|
+
client.put("model/#{model_name}/#{resource_id}", attributes)
|
26
|
+
rescue ErpIntegration::HttpError::BadRequest => e
|
27
|
+
[attributes, [extract_error_message(e)]]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Fulfil returns a 400 status code (e.g. Bad Request) with the error message
|
33
|
+
# in the body. We're using the exception to extract the error message in the
|
34
|
+
# body of the original response from Fulfil.
|
35
|
+
#
|
36
|
+
# @param error [ErpIntegration::HttpError::BadRequest] The exception raised by our middleware.
|
37
|
+
# @return [String] The error message by Fulfil.
|
38
|
+
def extract_error_message(error)
|
39
|
+
JSON.parse(error.response[:body]).fetch('message')
|
40
|
+
end
|
41
|
+
|
42
|
+
# Fulfil always expects an array of attributes. That way, we could also create
|
43
|
+
# a whole bunch of objects all at once. We don't support creating multiple records
|
44
|
+
# yet as it's not needed yet. However, we do need to normalize the attributes we're
|
45
|
+
# passing to the Fulfil API.
|
46
|
+
#
|
47
|
+
# @param attributes [Hash|Array<Hash>] The attributes for the new resource.
|
48
|
+
# @return [Array<Hash>] The normalized attributes.
|
49
|
+
def normalize_attributes(attributes)
|
50
|
+
attrs = attributes.is_a?(Array) ? attributes : [attributes]
|
51
|
+
attrs.compact
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -12,7 +12,7 @@ module ErpIntegration
|
|
12
12
|
# @param sku [String] The product's SKU.
|
13
13
|
# @return [Boolean] Whether it's a BOM or not.
|
14
14
|
def bom?(sku)
|
15
|
-
select(:boms).
|
15
|
+
select(:boms).find_by!(code: sku).boms.any?
|
16
16
|
end
|
17
17
|
alias billing_of_materials? bom?
|
18
18
|
end
|
@@ -7,6 +7,45 @@ module ErpIntegration
|
|
7
7
|
module Resources
|
8
8
|
class SalesOrderLine < ApiResource
|
9
9
|
self.model_name = 'sale.line'
|
10
|
+
# Allows cancelling the entire sales order line in Fulfil.
|
11
|
+
# @param id [Integer|String] The ID of the to be cancelled order line.
|
12
|
+
# @return [boolean] Whether the sales order line was cancelled successfully or not.
|
13
|
+
def cancel(id)
|
14
|
+
client.put("model/sale.line/#{id}/cancel")
|
15
|
+
true
|
16
|
+
rescue ErpIntegration::HttpError::BadRequest
|
17
|
+
false
|
18
|
+
# Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok")
|
19
|
+
# and faraday is having an error when trying to parse it. Let's skip the parse error
|
20
|
+
# and move on.
|
21
|
+
rescue Faraday::ParsingError
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
# Updates the sales order line quantity of canceled and non canceled items
|
26
|
+
# @param sales_channel [Integer] Sales channel id
|
27
|
+
# @param channel_identifier [String]
|
28
|
+
# @param sku [String]
|
29
|
+
# @param quantity [Integer] The total quantity (canceled + not canceled)
|
30
|
+
# Should be more or equal than quantity_canceled but the above criteria is suggested
|
31
|
+
# @param quantity_canceled [Integer] the total quantity of canceled items (including new ones)
|
32
|
+
# @return [boolean] Whether the sales order line was changed successfully or not.
|
33
|
+
def adjust_quantity(sales_channel, channel_identifier,
|
34
|
+
sku, quantity, quantity_canceled)
|
35
|
+
options = [{
|
36
|
+
"channel_identifier": channel_identifier,
|
37
|
+
"sale_lines":
|
38
|
+
[{
|
39
|
+
"sku": sku,
|
40
|
+
"quantity": quantity,
|
41
|
+
"quantity_canceled": quantity_canceled
|
42
|
+
}]
|
43
|
+
}]
|
44
|
+
client.put("model/sale.channel/#{sales_channel}/create_order", options)
|
45
|
+
true
|
46
|
+
rescue ErpIntegration::HttpError::BadRequest
|
47
|
+
false
|
48
|
+
end
|
10
49
|
end
|
11
50
|
end
|
12
51
|
end
|
@@ -29,11 +29,20 @@ module ErpIntegration
|
|
29
29
|
# 5. Create a new adapter class prefixed with the adapter's name
|
30
30
|
# (e.g. `FulfilOrder` for the `Order` resource in the `lib/erp_integration/orders` folder).
|
31
31
|
class Resource
|
32
|
+
include Resources::Validations
|
33
|
+
include Resources::Persistence
|
34
|
+
|
32
35
|
attr_accessor :raw_api_response
|
33
36
|
|
34
37
|
def initialize(attributes = {})
|
35
38
|
@raw_api_response = attributes
|
39
|
+
assign_attributes(attributes)
|
40
|
+
end
|
36
41
|
|
42
|
+
# Allows assigning attributes to an resource instance.
|
43
|
+
# @param attributes [Hash] A list of attributes for the resource.
|
44
|
+
# @return [Hash] The list of assigned attributes.
|
45
|
+
def assign_attributes(attributes = {})
|
37
46
|
attributes.each_pair do |name, value|
|
38
47
|
public_send(:"#{name}=", value) if respond_to?(:"#{name}=")
|
39
48
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Resources
|
5
|
+
# The `ErpIntegration::Resources::Errors` expose a clean, simple API to manage
|
6
|
+
# and display error messages for any `ErpIntegration::Resource` instance.
|
7
|
+
class Errors
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
extend Forwardable
|
11
|
+
def_delegators :@errors, :any?, :blank?, :clear, :count, :empty?, :uniq!, :size
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@errors = []
|
15
|
+
end
|
16
|
+
|
17
|
+
# Allows adding new error messages to the `ErpIntegration::Resource`.
|
18
|
+
# @param message [String] An (internal/external) error message.
|
19
|
+
# @return [String] The given error message.
|
20
|
+
def add(message)
|
21
|
+
raise ErpIntegration::Error, 'Use a simple string as an error message' unless message.is_a?(String)
|
22
|
+
|
23
|
+
@errors << message
|
24
|
+
message
|
25
|
+
end
|
26
|
+
|
27
|
+
def each(&block)
|
28
|
+
@errors.each(&block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Resources
|
5
|
+
module Persistence
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
# Creates a new resource in the ERP.
|
12
|
+
# @param attributes [Hash] A list of attributes for the new resource.
|
13
|
+
# @return [ErpIntegration::Resource] The (to be) created resource.
|
14
|
+
def create(attributes)
|
15
|
+
attrs, error_messages = adapter.create(**attributes)
|
16
|
+
|
17
|
+
new_resource = new(attrs)
|
18
|
+
new_resource.validate_with(error_messages)
|
19
|
+
new_resource
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Determines whether a `ErpIntegration::Resource` is considered to be persisted.
|
24
|
+
# @return [Boolean] Whether it's persisted or not.
|
25
|
+
def persisted?
|
26
|
+
!id.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
# Update an resource in the ERP.
|
30
|
+
# @param attributes [Hash] A list of attributes to update.
|
31
|
+
# @return [Boolean] Whether the update action was succcesful or not.
|
32
|
+
def update(attributes)
|
33
|
+
attrs, error_messages = self.class.adapter.update(id, **attributes)
|
34
|
+
|
35
|
+
assign_attributes(attrs)
|
36
|
+
validate_with(error_messages)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Resources
|
5
|
+
module Validations
|
6
|
+
# Exposes all errors related to an `ErpIntegration::Resource`.
|
7
|
+
#
|
8
|
+
# @return [ErpIntegration::Resources::Errors] Encapsulation of all error messages.
|
9
|
+
def errors
|
10
|
+
@errors ||= Resources::Errors.new
|
11
|
+
end
|
12
|
+
|
13
|
+
# Checks whether an resource is considered valid or not.
|
14
|
+
#
|
15
|
+
# @return [Boolean] Is the resource valid according to the ERP?
|
16
|
+
def valid?
|
17
|
+
errors.none?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Validates the resource by checking the given error messages.
|
21
|
+
#
|
22
|
+
# @param error_messages [Array] A list of error messages.
|
23
|
+
# @return [Boolean] Whether the resource is valid or not.
|
24
|
+
def validate_with(*error_messages)
|
25
|
+
errors.clear
|
26
|
+
|
27
|
+
error_messages.flatten.compact.each do |error_message|
|
28
|
+
errors.add(error_message)
|
29
|
+
end
|
30
|
+
|
31
|
+
valid?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -12,5 +12,13 @@ module ErpIntegration
|
|
12
12
|
:quantity_reserved, :quantity_shipped, :return_reason, :sale,
|
13
13
|
:sequence, :shipping_date, :taxes, :type, :warehouse, :write_date,
|
14
14
|
:write_uid
|
15
|
+
|
16
|
+
def cancel(id)
|
17
|
+
self.class.adapter.cancel(id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def adjust_quantity(sales_channel, channel_identifier, sku, quantity, quantity_canceled)
|
21
|
+
self.class.adapter.adjust_quantity(sales_channel, channel_identifier, sku, quantity, quantity_canceled)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
end
|
data/lib/erp_integration.rb
CHANGED
@@ -23,6 +23,7 @@ module ErpIntegration
|
|
23
23
|
autoload :BillOfMaterial, 'erp_integration/bill_of_material'
|
24
24
|
autoload :BillOfMaterialInput, 'erp_integration/bill_of_material_input'
|
25
25
|
autoload :BillOfMaterialOutput, 'erp_integration/bill_of_material_output'
|
26
|
+
autoload :CustomerShipmentReturn, 'erp_integration/customer_shipment_return'
|
26
27
|
autoload :Product, 'erp_integration/product'
|
27
28
|
autoload :ProductionOrder, 'erp_integration/production_order'
|
28
29
|
autoload :PurchaseOrder, 'erp_integration/purchase_order'
|
@@ -33,4 +34,10 @@ module ErpIntegration
|
|
33
34
|
autoload :SalesOrderLine, 'erp_integration/sales_order_line'
|
34
35
|
autoload :StockMove, 'erp_integration/stock_move'
|
35
36
|
autoload :SupplierShipment, 'erp_integration/supplier_shipment'
|
37
|
+
|
38
|
+
module Resources
|
39
|
+
autoload :Errors, 'erp_integration/resources/errors'
|
40
|
+
autoload :Persistence, 'erp_integration/resources/persistence'
|
41
|
+
autoload :Validations, 'erp_integration/resources/validations'
|
42
|
+
end
|
36
43
|
end
|
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.9.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:
|
11
|
+
date: 2022-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -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: []
|
@@ -263,14 +263,18 @@ files:
|
|
263
263
|
- lib/erp_integration/bill_of_material_input.rb
|
264
264
|
- lib/erp_integration/bill_of_material_output.rb
|
265
265
|
- lib/erp_integration/configuration.rb
|
266
|
+
- lib/erp_integration/customer_shipment_return.rb
|
266
267
|
- lib/erp_integration/errors.rb
|
267
268
|
- lib/erp_integration/fulfil/api_resource.rb
|
268
269
|
- lib/erp_integration/fulfil/client.rb
|
270
|
+
- lib/erp_integration/fulfil/finder_methods.rb
|
271
|
+
- lib/erp_integration/fulfil/persistence.rb
|
269
272
|
- lib/erp_integration/fulfil/query.rb
|
270
273
|
- lib/erp_integration/fulfil/query_methods.rb
|
271
274
|
- lib/erp_integration/fulfil/resources/bill_of_material.rb
|
272
275
|
- lib/erp_integration/fulfil/resources/bill_of_material_input.rb
|
273
276
|
- lib/erp_integration/fulfil/resources/bill_of_material_output.rb
|
277
|
+
- lib/erp_integration/fulfil/resources/customer_shipment_return.rb
|
274
278
|
- lib/erp_integration/fulfil/resources/product.rb
|
275
279
|
- lib/erp_integration/fulfil/resources/production_order.rb
|
276
280
|
- lib/erp_integration/fulfil/resources/purchase_order.rb
|
@@ -288,6 +292,9 @@ files:
|
|
288
292
|
- lib/erp_integration/purchase_order_line.rb
|
289
293
|
- lib/erp_integration/purchase_request.rb
|
290
294
|
- lib/erp_integration/resource.rb
|
295
|
+
- lib/erp_integration/resources/errors.rb
|
296
|
+
- lib/erp_integration/resources/persistence.rb
|
297
|
+
- lib/erp_integration/resources/validations.rb
|
291
298
|
- lib/erp_integration/sales_order.rb
|
292
299
|
- lib/erp_integration/sales_order_line.rb
|
293
300
|
- lib/erp_integration/stock_move.rb
|
@@ -301,7 +308,7 @@ metadata:
|
|
301
308
|
homepage_uri: https://www.github.com/mejuri-inc/erp-integration
|
302
309
|
source_code_uri: https://www.github.com/mejuri-inc/erp-integration
|
303
310
|
changelog_uri: https://www.github.com/mejuri-inc/erp-integration/blob/main/CHANGELOG.md
|
304
|
-
post_install_message:
|
311
|
+
post_install_message:
|
305
312
|
rdoc_options: []
|
306
313
|
require_paths:
|
307
314
|
- lib
|
@@ -316,8 +323,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
316
323
|
- !ruby/object:Gem::Version
|
317
324
|
version: '0'
|
318
325
|
requirements: []
|
319
|
-
rubygems_version: 3.
|
320
|
-
signing_key:
|
326
|
+
rubygems_version: 3.0.3
|
327
|
+
signing_key:
|
321
328
|
specification_version: 4
|
322
329
|
summary: Connects Mejuri with third-party ERP vendors
|
323
330
|
test_files: []
|