erp_integration 0.7.0 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b7edee1b77a371325210af94802cbd0d6c1df5d730bcfd8d9d326bc8a5eb2c3
4
- data.tar.gz: d59ecb758fde883746da4fec059e99c53b71f7a526f81d7fa272eb139f567ff4
3
+ metadata.gz: 10feefb3de410db28d960dcab694fd3ac8cbc08e9d2ea06627e8cd5f514b2a57
4
+ data.tar.gz: a7d6540c305bf8519789aa11073dc38141cdb60226a1296a99c5ea2e2d412838
5
5
  SHA512:
6
- metadata.gz: 0c34649c0ab233be00b9e9b35897faa934eb85824318528f7df4261b8f093319902d82636bd6e4cbba22d82afec604e6d4136b6f64ad7398ee2227aa5b17dca9
7
- data.tar.gz: 70cac86409b77043c0d0ec4f62946d01b48bd96b4abfaaf88c3b57f9600ada205c505b072ac91836ca693621c37302e2223b65b2769e8157ff2fe0b4c734eb10
6
+ metadata.gz: e64d55ee5b4ab827fb78ebd864ea278bfaaa50506de7e73737cfd88cc9e9f83485b34c7c96d840f3b3a5e26b3a8df730d69f8822d1c513f31b7f4d11bf8dd2e4
7
+ data.tar.gz: dacaceb6e96523354e470e70056f574933cd8dd4e9bf30757a5ab9742545d7b460c73b3b32ff9e41a6284a99c25cb62d4eed9f312b7e4c443242f0d18d3dc894
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  Gemfile.lock
14
14
  .byebug_history
15
15
  *.gem
16
+ /.idea/
data/README.md CHANGED
@@ -104,7 +104,7 @@ It's important to note that you'll need the right privileges to publish the gem.
104
104
 
105
105
  2. Create Pull Request
106
106
 
107
- 3. Merge it to main
107
+ 3. Merge it to develop
108
108
 
109
109
  4. Run Release script
110
110
  ```shell
@@ -37,6 +37,16 @@ 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 `CustomerShipment` 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_adapter
44
+
45
+ # Allows configuring an adapter for the `CustomerShipmentReturn` resource. When
46
+ # none is configured, it will default to Fulfil.
47
+ # @return [Symbol] The configured adapter for the customer shipment.
48
+ attr_writer :customer_shipment_return_adapter
49
+
40
50
  # Allows configuring an adapter for the `Product` resource. When none is
41
51
  # configured, it will default to Fulfil.
42
52
  # @return [Symbol] The configured adapter for the products.
@@ -82,6 +92,10 @@ module ErpIntegration
82
92
  # @return [Symbol] The configured adapter for the stock move.
83
93
  attr_writer :stock_move_adapter
84
94
 
95
+ # Logger that will be used for HTTP operations on Client
96
+ # @return [Logger] The configured logger
97
+ attr_accessor :logger
98
+
85
99
  def initialize(**options)
86
100
  options.each_pair do |key, value|
87
101
  public_send("#{key}=", value) if respond_to?("#{key}=")
@@ -100,6 +114,14 @@ module ErpIntegration
100
114
  @bill_of_material_output_adapter || :fulfil
101
115
  end
102
116
 
117
+ def customer_shipment_adapter
118
+ @customer_shipment_adapter || :fulfil
119
+ end
120
+
121
+ def customer_shipment_return_adapter
122
+ @customer_shipment_return_adapter || :fulfil
123
+ end
124
+
103
125
  def product_adapter
104
126
  @product_adapter || :fulfil
105
127
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErpIntegration
4
+ # The `ErpIntegration::CustomerShipment` exposes an uniformed API for interaction with
5
+ # third-party ERP vendors.
6
+ class CustomerShipment < Resource
7
+ attr_accessor :acknowledged_by_3pl_at, :aes_itn, :assigned_by, :assigned_time, :attachments,
8
+ :available_carrier_services, :avg_cycle_time, :avg_cycle_time_cache, :carrier,
9
+ :carrier_billing_account, :carrier_cost_method, :carrier_duties_account,
10
+ :carrier_service, :channel_carrier_service_code, :channel_logo_url, :channels,
11
+ :checklists, :company, :consumable_moves, :consumables_cost, :consumables_cost_cache,
12
+ :contact_categories, :contents_explanation, :contents_type, :cost, :cost_currency,
13
+ :cost_currency_digits, :cost_invoice_line, :create_date, :create_return_label, :create_uid,
14
+ :customer, :customer_location, :customs_items, :default_box_type, :delivery_address,
15
+ :delivery_address_datetime, :delivery_mode, :done_by, :duties_tax_id, :duties_tax_id_type,
16
+ :eel_pfc, :effective_date, :eori_number, :fedex_saturday_delivery, :full_delivery_address,
17
+ :gift_message, :has_gift_message, :hold_reason, :id, :incoterm, :insurance_amount, :inventory_moves,
18
+ :invoices, :is_international_shipping, :is_shippo, :last_modification, :license_plates, :messages,
19
+ :metadata, :moves, :non_delivery_option, :number, :on_hold, :on_hold_until, :order_confirmation_time,
20
+ :order_numbers, :origins, :outgoing_moves, :packages, :packed_at, :packed_by, :packed_date, :packer,
21
+ :payment_status, :payment_transactions, :picked_at, :picked_date, :picker, :picking_started_at,
22
+ :picking_status, :planned_date, :planned_datetime, :planned_time, :priority, :private_notes,
23
+ :productions, :public_notes, :rec_blurb, :rec_name, :reference, :request_confirmation,
24
+ :requested_delivery_date, :requested_shipping_service, :require_customs, :root_packages, :sale_date,
25
+ :sales, :sent_to_3pl_at, :shipped_at, :shipper, :shipping_batch, :shipping_instructions,
26
+ :shipping_label_date, :shipping_label_printed, :shipping_manifest, :sscc_code, :state, :tax_id,
27
+ :total_amount_ccy, :total_cost, :total_customs_value, :total_item_cost_ccy, :total_quantity, :tpl,
28
+ :tpl_status, :tracking_export_status, :tracking_number, :tracking_number_blurb, :tsv,
29
+ :ups_saturday_delivery, :warehouse, :warehouse_output, :warehouse_storage, :weight, :weight_digits,
30
+ :weight_uom, :weight_uom_symbol, :write_date, :write_uid
31
+ end
32
+ 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
+ :origins, :number, :packages, :planned_date, :private_notes, :public_notes, :putaway_by,
16
+ :rec_blurb, :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
@@ -44,7 +44,8 @@ module ErpIntegration
44
44
  def self.client
45
45
  Client.new(
46
46
  api_key: config.fulfil_api_key,
47
- merchant_id: config.fulfil_merchant_id
47
+ merchant_id: config.fulfil_merchant_id,
48
+ logger: config.logger
48
49
  )
49
50
  end
50
51
 
@@ -6,9 +6,10 @@ module ErpIntegration
6
6
  attr_reader :api_key, :merchant_id
7
7
  attr_writer :connection, :faraday_adapter
8
8
 
9
- def initialize(api_key:, merchant_id:)
9
+ def initialize(api_key:, merchant_id:, logger: nil)
10
10
  @api_key = api_key
11
11
  @merchant_id = merchant_id
12
+ @logger = logger
12
13
  end
13
14
 
14
15
  # Generates the url prefix for the Faraday connection client.
@@ -35,6 +36,11 @@ module ErpIntegration
35
36
  faraday.response :follow_redirects
36
37
  faraday.response :json # Decode response bodies as JSON
37
38
 
39
+ # Notice that logging headers will expose sensitive information
40
+ # like api-key. To avoid use filters:
41
+ # https://lostisland.github.io/faraday/middleware/logger
42
+ faraday.response :logger, @logger, { headers: false, bodies: true }
43
+
38
44
  # Custom error handling for the error response
39
45
  faraday.use ErpIntegration::Middleware::ErrorHandling
40
46
 
@@ -5,21 +5,26 @@ module ErpIntegration
5
5
  module Persistence
6
6
  # Allows creating new resources in Fulfil.
7
7
  #
8
- # @example
9
- # $ ErpIntegration::Product.create(code: 'MT100eu', variant: 10)
10
- # => <ErpIntegration::Product @id=2 @code="MT100eu" @variant=10 />
11
- #
12
- # @param attributes [Hash] A list of attributes.
13
- # @return [ErpIntegration::Resource] The newly created resource.
14
- def create(attributes = {})
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)
15
11
  client
16
12
  .post("model/#{model_name}", normalize_attributes(attributes))
17
- .map { |new_record_id| resource_klass.new(attributes.merge(id: new_record_id)) }
13
+ .map { |new_record_id| attributes.merge!(id: new_record_id) }
18
14
  .first
19
15
  rescue ErpIntegration::HttpError::BadRequest => e
20
- record = resource_klass.new(attributes)
21
- record.errors.add(extract_error_message(e))
22
- record
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)]]
23
28
  end
24
29
 
25
30
  private
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../api_resource'
4
+
5
+ module ErpIntegration
6
+ module Fulfil
7
+ module Resources
8
+ class CustomerShipment < ApiResource
9
+ self.model_name = 'stock.shipment.out'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../api_resource'
4
+
5
+ module ErpIntegration
6
+ module Fulfil
7
+ module Resources
8
+ class CustomerShipmentReturn < ApiResource
9
+ self.model_name = 'stock.shipment.out.return'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -29,22 +29,25 @@ 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
40
49
  end
41
50
 
42
- # Exposes all errors related to an `ErpIntegration::Resource`.
43
- # @return [ErpIntegration::Resources::Errors] Encapsulation of all error messages.
44
- def errors
45
- @errors ||= Resources::Errors.new
46
- end
47
-
48
51
  class << self
49
52
  # Dynamically defines and loads the adapter for the class inheriting from
50
53
  # the `ErpIntegration::Resource`.
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ErpIntegration
4
- VERSION = '0.7.0'
4
+ VERSION = '0.11.0'
5
5
  end
@@ -23,6 +23,8 @@ 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 :CustomerShipment, 'erp_integration/customer_shipment'
27
+ autoload :CustomerShipmentReturn, 'erp_integration/customer_shipment_return'
26
28
  autoload :Product, 'erp_integration/product'
27
29
  autoload :ProductionOrder, 'erp_integration/production_order'
28
30
  autoload :PurchaseOrder, 'erp_integration/purchase_order'
@@ -36,5 +38,7 @@ module ErpIntegration
36
38
 
37
39
  module Resources
38
40
  autoload :Errors, 'erp_integration/resources/errors'
41
+ autoload :Persistence, 'erp_integration/resources/persistence'
42
+ autoload :Validations, 'erp_integration/resources/validations'
39
43
  end
40
44
  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.7.0
4
+ version: 0.11.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: 2022-01-11 00:00:00.000000000 Z
11
+ date: 2022-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -263,6 +263,8 @@ 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.rb
267
+ - lib/erp_integration/customer_shipment_return.rb
266
268
  - lib/erp_integration/errors.rb
267
269
  - lib/erp_integration/fulfil/api_resource.rb
268
270
  - lib/erp_integration/fulfil/client.rb
@@ -273,6 +275,8 @@ files:
273
275
  - lib/erp_integration/fulfil/resources/bill_of_material.rb
274
276
  - lib/erp_integration/fulfil/resources/bill_of_material_input.rb
275
277
  - lib/erp_integration/fulfil/resources/bill_of_material_output.rb
278
+ - lib/erp_integration/fulfil/resources/customer_shipment.rb
279
+ - lib/erp_integration/fulfil/resources/customer_shipment_return.rb
276
280
  - lib/erp_integration/fulfil/resources/product.rb
277
281
  - lib/erp_integration/fulfil/resources/production_order.rb
278
282
  - lib/erp_integration/fulfil/resources/purchase_order.rb
@@ -291,6 +295,8 @@ files:
291
295
  - lib/erp_integration/purchase_request.rb
292
296
  - lib/erp_integration/resource.rb
293
297
  - lib/erp_integration/resources/errors.rb
298
+ - lib/erp_integration/resources/persistence.rb
299
+ - lib/erp_integration/resources/validations.rb
294
300
  - lib/erp_integration/sales_order.rb
295
301
  - lib/erp_integration/sales_order_line.rb
296
302
  - lib/erp_integration/stock_move.rb
@@ -319,7 +325,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
319
325
  - !ruby/object:Gem::Version
320
326
  version: '0'
321
327
  requirements: []
322
- rubygems_version: 3.2.22
328
+ rubygems_version: 3.1.4
323
329
  signing_key:
324
330
  specification_version: 4
325
331
  summary: Connects Mejuri with third-party ERP vendors