erp_integration 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5657cdcc644e079869eeb3189a451e97b558cb0c64f93b123280301acd0886b1
4
- data.tar.gz: 5a279cf9b1c38ebba6939861e6f15bd5d4ad66acc03364068d5c5ffe46dfa3be
3
+ metadata.gz: 99b2b058b12b3b5d0b1212c9d077b9aaa224a9a20bc96f624dd7b5de3016bcaa
4
+ data.tar.gz: de266b8b0bb2c412866bf64ba0a28b75500faf79173e8d9bb1d56fd84c0a45b0
5
5
  SHA512:
6
- metadata.gz: 2a3203a5b4277d6656f955aa015b01ab9c180cf628510eceeff4f6b6cab878a349a403c495342a0d050cd5c23c25fb0bda5bbe945b658e64fe53261c7fd78e38
7
- data.tar.gz: f9014829733dd877118093fc7375517ba73982a87c1ad84f1497c183e514900372297c127551de9591801e1404f65ef21439bf0ef8aa3778fb3c27fb650eca6c
6
+ metadata.gz: '09c9117df5560187b9c5010b56ec0cc9ce30b3313a801e687795a0d97bc1c8dd2acae6ebc1cba7b186e777c2198def26e4071b7dfc52f28a04be0265657c68e6'
7
+ data.tar.gz: 3da4be6f4775e272d118ccb93ecec41c9744702a73f328245f472032d66c69796cbec23bb70286bd034e7b2593734f6c169bcd8d6e32d13e089b60ddab3784bc
data/README.md CHANGED
@@ -37,15 +37,15 @@ end
37
37
  After configuring the gem, one can easily query all the available ERP resources from the connected third-parties.
38
38
 
39
39
  ```ruby
40
- $ ErpIntegration::Order.where(reference: 'MT1000SKX')
41
- => #<ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::Order @id=100 />] />
40
+ $ ErpIntegration::SalesOrder.where(reference: 'MT1000SKX')
41
+ => #<ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::SalesOrder @id=100 />] />
42
42
  ```
43
43
 
44
44
  By default, only the `id` will be added to the found ERP resources. However, one can use the `select` method to include more fields.
45
45
 
46
46
  ```ruby
47
- $ ErpIntegration::Order.select(:id, :reference).where(reference: 'MT1000SKX')
48
- => #<ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::Order @id=100 @reference=MT1000SKX />] />
47
+ $ ErpIntegration::SalesOrder.select(:id, :reference).where(reference: 'MT1000SKX')
48
+ => #<ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::SalesOrder @id=100 @reference=MT1000SKX />] />
49
49
  ```
50
50
 
51
51
  There are also other type of `where` queries available:
data/bin/prerelease CHANGED
@@ -17,4 +17,4 @@ git push origin "release_v.$VERSION"
17
17
 
18
18
  # Tag the new gem version.
19
19
  git tag v$VERSION
20
- git push --tags
20
+ git push origin v$VERSION
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  # Faraday is a HTTP/REST API client library to interact with third-party API vendors
35
35
  spec.add_dependency 'faraday', '>= 0.17.3', '< 1.9.0'
36
- spec.add_dependency 'faraday_middleware', '~> 0.14.0'
36
+ spec.add_dependency 'faraday_middleware', '>= 0.14', '< 1.3'
37
37
 
38
38
  # Development dependencies
39
39
  spec.add_development_dependency 'byebug', '~> 11.0'
@@ -22,10 +22,20 @@ module ErpIntegration
22
22
  # @return [String] The merchant ID for Fulfil.
23
23
  attr_accessor :fulfil_merchant_id
24
24
 
25
- # Allows configuring an adapter for the `Order` resource. When none is
25
+ # Allows configuring an adapter for the `SalesOrder` resource. When none is
26
26
  # configured, it will default to Fulfil.
27
- # @return [Symbol] The configured adapter for the orders
28
- attr_writer :order_adapter
27
+ # @return [Symbol] The configured adapter for the sales orders
28
+ attr_writer :sales_order_adapter
29
+
30
+ # Allows configuring an adapter for the `SalesOrderLine` resource. When none is
31
+ # configured, it will default to Fulfil.
32
+ # @return [Symbol] The configured adapter for the order lines.
33
+ attr_writer :sales_order_line_adapter
34
+
35
+ # Allows configuring an adapter for the `Product` resource. When none is
36
+ # configured, it will default to Fulfil.
37
+ # @return [Symbol] The configured adapter for the products.
38
+ attr_writer :product_adapter
29
39
 
30
40
  # Allows configuring an adapter for the `PurchaseOrder` resource. When none is
31
41
  # configured, it will default to Fulfil.
@@ -37,14 +47,27 @@ module ErpIntegration
37
47
  # @return [Symbol] The configured adapter for the purchase order lines.
38
48
  attr_writer :purchase_order_line_adapter
39
49
 
50
+ # Allows configuring an adapter for the `PurchaseRequest` resource. When
51
+ # none is configured, it will default to Fulfil.
52
+ # @return [Symbol] The configured adapter for the purchase request.
53
+ attr_writer :purchase_request_adapter
54
+
40
55
  def initialize(**options)
41
56
  options.each_pair do |key, value|
42
57
  public_send("#{key}=", value) if respond_to?("#{key}=")
43
58
  end
44
59
  end
45
60
 
46
- def order_adapter
47
- @order_adapter || :fulfil
61
+ def sales_order_adapter
62
+ @sales_order_adapter || :fulfil
63
+ end
64
+
65
+ def sales_order_line_adapter
66
+ @sales_order_line_adapter || :fulfil
67
+ end
68
+
69
+ def product_adapter
70
+ @product_adapter || :fulfil
48
71
  end
49
72
 
50
73
  def purchase_order_adapter
@@ -54,6 +77,10 @@ module ErpIntegration
54
77
  def purchase_order_line_adapter
55
78
  @purchase_order_line_adapter || :fulfil
56
79
  end
80
+
81
+ def purchase_request_adapter
82
+ @purchase_request_adapter || :fulfil
83
+ end
57
84
  end
58
85
 
59
86
  # Returns ERP Integration's configuration.
@@ -1,17 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'collection'
4
3
  require_relative 'query_methods'
5
4
 
6
5
  module ErpIntegration
7
6
  module Fulfil
8
7
  class ApiResource
8
+ include Enumerable
9
9
  include QueryMethods
10
10
 
11
11
  cattr_accessor :resource_klass, instance_accessor: false
12
-
13
12
  delegate :client, :model_name, :resource_klass, to: 'self.class'
14
- delegate_missing_to :all
15
13
 
16
14
  def initialize(resource_klass)
17
15
  self.class.resource_klass = resource_klass
@@ -20,17 +18,21 @@ module ErpIntegration
20
18
  # The `where` and `includes` methods lazyly build a search/read query
21
19
  # for Fulfil. By calling `all`, the prepared search/read query will actually
22
20
  # be executed and the results will be fetched.
23
- # @return [ErpIntegration::Fulfil::Collection] An enumerable collection object with all API results.
21
+ # @return [Array] An enumerable collection object with all API results.
24
22
  def all
25
23
  return @results if defined?(@results)
26
24
 
27
- @results = Collection.new(
25
+ @results =
28
26
  client.put(
29
27
  "model/#{model_name}/search_read",
30
28
  Query.new(selected_fields, where_clauses)
31
- ),
32
- resource_klass: resource_klass
33
- )
29
+ ).map { |item| resource_klass.new(item) }
30
+ end
31
+
32
+ # The `each` method turns the `ApiResource` instance into an enumerable object.
33
+ # For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
34
+ def each(&block)
35
+ all.each(&block)
34
36
  end
35
37
 
36
38
  # The `client` exposes the `ErpIntegration::Fulfil::Client` to the class.
@@ -13,14 +13,14 @@ module ErpIntegration
13
13
  # selecting multiple fields at once.
14
14
  #
15
15
  # @example
16
- # $ ErpIntegration::Order.select(:id, :name, 'product.name')
16
+ # $ ErpIntegration::SalesOrder.select(:id, :name, 'product.name')
17
17
  # # => <ErpIntegration::Fulfil::Resources::Order @selected_fields=[:id, :name, "product.name"] />
18
18
  #
19
19
  # When one calls the `all` method, it will fetch all the resources from Fulfil
20
20
  # and it will return all the given fields (if available).
21
21
  #
22
22
  # @example
23
- # $ ErpIntegration::Order.select(:id, :name, 'product.name').all
23
+ # $ ErpIntegration::SalesOrder.select(:id, :name, 'product.name').all
24
24
  # # => <ErpIntegration::Fulfil::Collection @items=[...] />
25
25
  #
26
26
  # Both a list of Strings, Symbols or a combination of these can be passed
@@ -41,8 +41,8 @@ module ErpIntegration
41
41
  # to query resources in Fulfil.
42
42
  #
43
43
  # @example
44
- # $ ErpIntegration::Order.where(id: 100).all
45
- # # => <ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::Order @id=100 />] />
44
+ # $ ErpIntegration::SalesOrder.where(id: 100).all
45
+ # # => <ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::SalesOrder @id=100 />] />
46
46
  #
47
47
  # If one adds the `comparison_operator` key to the arguments, it will use
48
48
  # that comparison operator to build the query to Fulfil.
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../api_resource'
4
+
5
+ module ErpIntegration
6
+ module Fulfil
7
+ module Resources
8
+ class Product < ApiResource
9
+ self.model_name = 'product.product'
10
+
11
+ # Checks whether a certain product is a BOM.
12
+ # @param sku [String] The product's SKU.
13
+ # @return [Boolean] Whether it's a BOM or not.
14
+ def bom?(sku)
15
+ select(:boms).where(code: sku).first.boms.any?
16
+ end
17
+ alias billing_of_materials? bom?
18
+ end
19
+ end
20
+ end
21
+ 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 PurchaseRequest < ApiResource
9
+ self.model_name = 'purchase.request'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,7 +5,7 @@ require_relative '../api_resource'
5
5
  module ErpIntegration
6
6
  module Fulfil
7
7
  module Resources
8
- class Order < ApiResource
8
+ class SalesOrder < ApiResource
9
9
  self.model_name = 'sale.sale'
10
10
 
11
11
  # Allows cancelling the entire sales order in Fulfil.
@@ -22,6 +22,11 @@ module ErpIntegration
22
22
  # https://developers.fulfil.io/rest_api/model/sale.sale/#cancel-a-sales-order
23
23
  rescue ErpIntegration::HttpError::BadRequest
24
24
  false
25
+ # Workaround: Fulfil api does not return a json when status code is 200 (a.k.a. "Ok")
26
+ # and faraday is having an error when trying to parse it. Let's skip the parse error
27
+ # and move on.
28
+ rescue Faraday::ParsingError
29
+ true
25
30
  end
26
31
  end
27
32
  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 SalesOrderLine < ApiResource
9
+ self.model_name = 'sale.line'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -26,7 +26,7 @@ module ErpIntegration
26
26
  def initialize(key:, value:, comparison_operator: DEFAULT_COMPARISON_OPERATOR)
27
27
  @comparison_operator = verify_comparison_operator(comparison_operator)
28
28
  @key = key.to_s
29
- @value = value.to_s
29
+ @value = value
30
30
  end
31
31
 
32
32
  # Transforms the `WhereClause` into a filter object for Fulfil.
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErpIntegration
4
+ # The `ErpIntegration::Product` exposes an uniformed API for interaction with
5
+ # third-party ERP vendors.
6
+ class Product < Resource
7
+ attr_accessor :id, :code, :cost_price, :cost_price_method, :quantity_available,
8
+ :quantity_buildable, :quantity_inbound, :quantity_on_hand, :salable,
9
+ :template, :variant_name, :abc_classification, :account_category,
10
+ :account_cogs_used, :account_expense_used, :account_revenue_used,
11
+ :account_stock_lost_found_used, :account_stock_production_used,
12
+ :account_stock_supplier_used, :account_stock_used, :active,
13
+ :asin, :attachments, :attribute_set, :attributes, :attributes_json,
14
+ :average_daily_consumed, :average_daily_sales, :average_monthly_consumed,
15
+ :average_monthly_sales, :average_price, :boms, :box_type, :brand, :channel_listings,
16
+ :consumable, :country_of_origin, :create_date, :create_uid, :customs_description,
17
+ :customs_value, :days_of_inventory_left, :default_uom, :default_uom_category,
18
+ :description, :dimensions_uom, :ean, :fulfil_strategy, :gc_max, :gc_min,
19
+ :gift_card_delivery_mode, :gift_card_prices, :google_product_category,
20
+ :gross_margin, :gross_profit, :height, :hs_code, :is_gift_card, :landed_cost,
21
+ :lead_time_in_days, :length, :list_price, :long_description, :metadata,
22
+ :next_shipping_date, :product_suppliers, :purchasable, :purchase_uom,
23
+ :quantity_on_confirmed_purchase_orders, :quantity_outbound, :quantity_returned,
24
+ :quantity_sold, :quantity_waiting_consumption, :quantity_wip, :safety_stock_days,
25
+ :sale_uom, :scan_required, :ship_from_stock_if_available, :type,
26
+ :upc, :use_name_as_customs_description, :weight, :weight_uom,
27
+ :width, :write_date, :write_uid
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErpIntegration
4
+ # The `ErpIntegration::PurchaseRequest` exposes an uniformed API for interaction with
5
+ # third-party ERP vendors.
6
+ class PurchaseRequest < Resource
7
+ attr_accessor :id, :party, :product, :quantity, :attachments, :company,
8
+ :create_date, :create_uid, :customer, :delivery_address,
9
+ :metadata, :purchase, :purchase_date, :purchase_line, :state,
10
+ :uom, :warehouse, :write_date, :write_uid
11
+ end
12
+ end
@@ -16,8 +16,8 @@ module ErpIntegration
16
16
  # config.order_adapter = :fulfil
17
17
  # end
18
18
  #
19
- # $ ErpIntegration::Order.adapter
20
- # => #<ErpIntegration::Orders::FulfilOrder />
19
+ # $ ErpIntegration::SalesOrder.adapter
20
+ # => #<ErpIntegration::SalesOrders::FulfilOrder />
21
21
  #
22
22
  # To add a new resource, follow these steps:
23
23
  # 1. Add a new `attr_writer` in the `ErpIntegration::Configuration` class.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErpIntegration
4
+ # The `ErpIntegration::SalesOrder` exposes an uniformed API for interaction with
5
+ # third-party ERP vendors.
6
+ class SalesOrder < Resource
7
+ attr_accessor :id, :channel, :number, :party, :sale_date, :shipment_address,
8
+ :amount_invoiced, :attachments, :carrier, :carrier_service,
9
+ :channel_identifier, :comment, :company, :confirmation_time,
10
+ :create_date, :currency, :description, :gateway_transaction,
11
+ :invoice_address, :invoice_method, :invoice_state, :invoices,
12
+ :lines, :metadata, :payment_term, :payment_total, :price_list,
13
+ :reference, :sales_person, :shipment_amount, :shipment_method,
14
+ :shipment_state, :shipments, :shipping_start_date, :state,
15
+ :tax_amount, :total_amount, :total_quantity, :total_shipment_cost,
16
+ :untaxed_amount, :warehouse, :weight, :weight_uom, :write_date,
17
+ :write_uid
18
+
19
+ def cancel
20
+ self.class.adapter.cancel(id)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErpIntegration
4
+ # The `ErpIntegration::SalesOrderLine` exposes an uniformed API for interaction with
5
+ # third-party ERP vendors.
6
+ class SalesOrderLine < Resource
7
+ attr_accessor :id, :product, :quantity, :unit, :unit_price, :amount, :attachments,
8
+ :channel_identifier, :create_date, :create_uid, :delivery_address,
9
+ :delivery_date, :delivery_mode, :description, :discount, :gift_message,
10
+ :gross_profit_cpny_cc, :is_gift_card, :list_price, :listing_sku,
11
+ :metadata, :note, :options, :purhcase_request, :quantity_canceled,
12
+ :quantity_reserved, :quantity_shipped, :return_reason, :sale,
13
+ :sequence, :shipping_date, :taxes, :type, :warehouse, :write_date,
14
+ :write_uid
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ErpIntegration
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -3,7 +3,6 @@
3
3
  require 'active_support'
4
4
  require 'active_support/core_ext/string/inflections'
5
5
  require 'active_support/core_ext/module/delegation' # Allows using `delegate`
6
- require 'active_support/core_ext/module/attribute_accessors' # Allows using `delegate_missing_to`
7
6
  require 'faraday'
8
7
  require 'faraday_middleware'
9
8
  require 'json'
@@ -21,8 +20,11 @@ require_relative 'erp_integration/fulfil/client'
21
20
  # The `ErpIntegration` integrates Mejuri with third-party ERP vendors.
22
21
  module ErpIntegration
23
22
  # Resources
24
- autoload :Resource, 'erp_integration/resource'
25
- autoload :Order, 'erp_integration/order'
23
+ autoload :Product, 'erp_integration/product'
26
24
  autoload :PurchaseOrder, 'erp_integration/purchase_order'
27
25
  autoload :PurchaseOrderLine, 'erp_integration/purchase_order_line'
26
+ autoload :PurchaseRequest, 'erp_integration/purchase_request'
27
+ autoload :Resource, 'erp_integration/resource'
28
+ autoload :SalesOrder, 'erp_integration/sales_order'
29
+ autoload :SalesOrderLine, 'erp_integration/sales_order_line'
28
30
  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.3.0
4
+ version: 0.4.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: 2021-10-07 00:00:00.000000000 Z
11
+ date: 2021-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -48,16 +48,22 @@ dependencies:
48
48
  name: faraday_middleware
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0.14'
54
+ - - "<"
52
55
  - !ruby/object:Gem::Version
53
- version: 0.14.0
56
+ version: '1.3'
54
57
  type: :runtime
55
58
  prerelease: false
56
59
  version_requirements: !ruby/object:Gem::Requirement
57
60
  requirements:
58
- - - "~>"
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0.14'
64
+ - - "<"
59
65
  - !ruby/object:Gem::Version
60
- version: 0.14.0
66
+ version: '1.3'
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: byebug
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -257,18 +263,23 @@ files:
257
263
  - lib/erp_integration/errors.rb
258
264
  - lib/erp_integration/fulfil/api_resource.rb
259
265
  - lib/erp_integration/fulfil/client.rb
260
- - lib/erp_integration/fulfil/collection.rb
261
266
  - lib/erp_integration/fulfil/query.rb
262
267
  - lib/erp_integration/fulfil/query_methods.rb
263
- - lib/erp_integration/fulfil/resources/order.rb
268
+ - lib/erp_integration/fulfil/resources/product.rb
264
269
  - lib/erp_integration/fulfil/resources/purchase_order.rb
265
270
  - lib/erp_integration/fulfil/resources/purchase_order_line.rb
271
+ - lib/erp_integration/fulfil/resources/purchase_request.rb
272
+ - lib/erp_integration/fulfil/resources/sales_order.rb
273
+ - lib/erp_integration/fulfil/resources/sales_order_line.rb
266
274
  - lib/erp_integration/fulfil/where_clause.rb
267
275
  - lib/erp_integration/middleware/error_handling.rb
268
- - lib/erp_integration/order.rb
276
+ - lib/erp_integration/product.rb
269
277
  - lib/erp_integration/purchase_order.rb
270
278
  - lib/erp_integration/purchase_order_line.rb
279
+ - lib/erp_integration/purchase_request.rb
271
280
  - lib/erp_integration/resource.rb
281
+ - lib/erp_integration/sales_order.rb
282
+ - lib/erp_integration/sales_order_line.rb
272
283
  - lib/erp_integration/version.rb
273
284
  homepage: https://www.github.com/mejuri-inc/erp-integration
274
285
  licenses:
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ErpIntegration
4
- module Fulfil
5
- # The `Collection` class provides an enumerable interface for the `ApiResource`
6
- # to consume. It turns all the given items into the passed resource class.
7
- #
8
- # @example
9
- # $ Collection.new([...], resource_klass: ErpIntegration::Order)
10
- # # => <Collection @items=[<ErpIntegration::Order ... />, <ErpIntegration::Order ... />]
11
- class Collection
12
- include Enumerable
13
- attr_reader :items
14
-
15
- def initialize(items, resource_klass:)
16
- @items = items.map { |item| resource_klass.new(item) }
17
- end
18
-
19
- # The `each` method turns the `Collection` instance into an enumerable object.
20
- # For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
21
- def each(&block)
22
- @items.each(&block)
23
- end
24
- end
25
- end
26
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ErpIntegration
4
- # The `ErpIntegration::Order` exposes an uniformed API for interaction with
5
- # third-party ERP vendors.
6
- class Order < Resource
7
- attr_accessor :id, :number
8
- end
9
- end