erp_integration 0.5.4 → 0.8.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/README.md +61 -37
- data/lib/erp_integration/bill_of_material_input.rb +12 -0
- data/lib/erp_integration/configuration.rb +9 -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/bill_of_material_input.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 +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2636d8881ff93450aabba350ae21870e98ebf72dbe104b952567a37f49685fde
|
4
|
+
data.tar.gz: 84d2fc64b31a928e93d10c9090f7f1ebbbe187b933889437c62f914b6dacc72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc1fe8cf4bd8739773092308b849f78fa40e740d347850b887f5e33f1d5df873d07635b9b66249ed5c9297e1405f0058f03d99eb433e9d32fdf330686c4cd129
|
7
|
+
data.tar.gz: 43e155e350b9e3cf3be08a3c08770213b5cf06f81c24d579971a75d62d173f21a3a6d49cd316ff9508df9d3548a0df444621870416f951663eacfd63d26265b9
|
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).
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
# The `ErpIntegration::BillOfMaterialInput` exposes an uniformed API for interaction with
|
5
|
+
# third-party ERP vendors.
|
6
|
+
class BillOfMaterialInput < Resource
|
7
|
+
attr_accessor :attachments, :bom, :create_date, :create_uid, :id, :messages,
|
8
|
+
:metadata, :private_notes, :product, :public_notes, :quantity,
|
9
|
+
:rec_blurb, :rec_name, :sequence, :to_location, :unit_digits,
|
10
|
+
:uom, :uom_category, :warehouse, :write_date, :write_uid
|
11
|
+
end
|
12
|
+
end
|
@@ -27,6 +27,11 @@ module ErpIntegration
|
|
27
27
|
# @return [Symbol] The configured adapter for the bill_of_material.
|
28
28
|
attr_writer :bill_of_material_adapter
|
29
29
|
|
30
|
+
# Allows configuring an adapter for the `BillOfMaterialInput` resource. When
|
31
|
+
# none is configured, it will default to Fulfil.
|
32
|
+
# @return [Symbol] The configured adapter for the Bill of Material's input.
|
33
|
+
attr_writer :bill_of_material_input_adapter
|
34
|
+
|
30
35
|
# Allows configuring an adapter for the `BillOfMaterialOutput` resource. When
|
31
36
|
# none is configured, it will default to Fulfil.
|
32
37
|
# @return [Symbol] The configured adapter for the bill_of_material.
|
@@ -87,6 +92,10 @@ module ErpIntegration
|
|
87
92
|
@bill_of_material_adapter || :fulfil
|
88
93
|
end
|
89
94
|
|
95
|
+
def bill_of_material_input_adapter
|
96
|
+
@bill_of_material_input_adapter || :fulfil
|
97
|
+
end
|
98
|
+
|
90
99
|
def bill_of_material_output_adapter
|
91
100
|
@bill_of_material_output_adapter || :fulfil
|
92
101
|
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
@@ -21,6 +21,7 @@ require_relative 'erp_integration/fulfil/client'
|
|
21
21
|
module ErpIntegration
|
22
22
|
# Resources
|
23
23
|
autoload :BillOfMaterial, 'erp_integration/bill_of_material'
|
24
|
+
autoload :BillOfMaterialInput, 'erp_integration/bill_of_material_input'
|
24
25
|
autoload :BillOfMaterialOutput, 'erp_integration/bill_of_material_output'
|
25
26
|
autoload :Product, 'erp_integration/product'
|
26
27
|
autoload :ProductionOrder, 'erp_integration/production_order'
|
@@ -32,4 +33,10 @@ module ErpIntegration
|
|
32
33
|
autoload :SalesOrderLine, 'erp_integration/sales_order_line'
|
33
34
|
autoload :StockMove, 'erp_integration/stock_move'
|
34
35
|
autoload :SupplierShipment, 'erp_integration/supplier_shipment'
|
36
|
+
|
37
|
+
module Resources
|
38
|
+
autoload :Errors, 'erp_integration/resources/errors'
|
39
|
+
autoload :Persistence, 'erp_integration/resources/persistence'
|
40
|
+
autoload :Validations, 'erp_integration/resources/validations'
|
41
|
+
end
|
35
42
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -260,14 +260,18 @@ files:
|
|
260
260
|
- erp_integration.gemspec
|
261
261
|
- lib/erp_integration.rb
|
262
262
|
- lib/erp_integration/bill_of_material.rb
|
263
|
+
- lib/erp_integration/bill_of_material_input.rb
|
263
264
|
- lib/erp_integration/bill_of_material_output.rb
|
264
265
|
- lib/erp_integration/configuration.rb
|
265
266
|
- lib/erp_integration/errors.rb
|
266
267
|
- lib/erp_integration/fulfil/api_resource.rb
|
267
268
|
- lib/erp_integration/fulfil/client.rb
|
269
|
+
- lib/erp_integration/fulfil/finder_methods.rb
|
270
|
+
- lib/erp_integration/fulfil/persistence.rb
|
268
271
|
- lib/erp_integration/fulfil/query.rb
|
269
272
|
- lib/erp_integration/fulfil/query_methods.rb
|
270
273
|
- lib/erp_integration/fulfil/resources/bill_of_material.rb
|
274
|
+
- lib/erp_integration/fulfil/resources/bill_of_material_input.rb
|
271
275
|
- lib/erp_integration/fulfil/resources/bill_of_material_output.rb
|
272
276
|
- lib/erp_integration/fulfil/resources/product.rb
|
273
277
|
- lib/erp_integration/fulfil/resources/production_order.rb
|
@@ -286,6 +290,9 @@ files:
|
|
286
290
|
- lib/erp_integration/purchase_order_line.rb
|
287
291
|
- lib/erp_integration/purchase_request.rb
|
288
292
|
- lib/erp_integration/resource.rb
|
293
|
+
- lib/erp_integration/resources/errors.rb
|
294
|
+
- lib/erp_integration/resources/persistence.rb
|
295
|
+
- lib/erp_integration/resources/validations.rb
|
289
296
|
- lib/erp_integration/sales_order.rb
|
290
297
|
- lib/erp_integration/sales_order_line.rb
|
291
298
|
- lib/erp_integration/stock_move.rb
|