erp_integration 0.26.0 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/erp_integration/customer_shipment_return.rb +8 -0
- data/lib/erp_integration/fulfil/resources/customer_shipment_return.rb +4 -0
- data/lib/erp_integration/fulfil/resources/sales_order.rb +59 -19
- data/lib/erp_integration/resource.rb +5 -3
- data/lib/erp_integration/version.rb +1 -1
- data/lib/erp_integration.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce9166d556b18b7bc901a79897d91aac2fe7eb55c5aaddf9af9294c4bd998565
|
4
|
+
data.tar.gz: e1691411b7567d04cd7f005be725df6be5934bf5ce6bbf3c827f622ac05f2ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59b3d087c5218481e4482a37f6b48ea3a889fd4e1c63e9a38704a636a45b0c15f2fc622231819ee7f1ebb78687e7313e1044227d3094d9f157f502959bab53fd
|
7
|
+
data.tar.gz: b41b6762a7b5667ea55732c1e2d184c3074223ea3508fb08a1bb917424a76b1b9907434d1c9083c33efd45d4f6c0ec49528b500dec10e0df4e0a0d476faa4fe7
|
@@ -32,5 +32,13 @@ module ErpIntegration
|
|
32
32
|
def create_default_package(id)
|
33
33
|
self.class.adapter.create_default_package(id)
|
34
34
|
end
|
35
|
+
|
36
|
+
# Create a package for a {CustomerShipmentReturn}.
|
37
|
+
#
|
38
|
+
# @param id [Integer] The ID of the {CustomerShipmentReturn}.
|
39
|
+
# @param options [Hash] The attributes needed for the new package.
|
40
|
+
def create_package(id, options)
|
41
|
+
self.class.adapter.create_package(id, options)
|
42
|
+
end
|
35
43
|
end
|
36
44
|
end
|
@@ -8,6 +8,16 @@ module ErpIntegration
|
|
8
8
|
class SalesOrder < ApiResource
|
9
9
|
self.model_name = 'sale.sale'
|
10
10
|
|
11
|
+
class MissingIdempotencyKey < ErpIntegration::Error
|
12
|
+
def initialize
|
13
|
+
super(
|
14
|
+
'[ERP Integration] Missing the required reference attribute. ' \
|
15
|
+
'Setting the reference prevents Fulfil from processing the same sales ' \
|
16
|
+
"order twice. For this reason, it's required to provide it as a safeguard."
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
# Allows cancelling the entire sales order in Fulfil.
|
12
22
|
# @param id [Integer|String] The ID of the to be cancelled order.
|
13
23
|
# @return [boolean] Whether the sales order was cancelled successfully or not.
|
@@ -29,25 +39,6 @@ module ErpIntegration
|
|
29
39
|
true
|
30
40
|
end
|
31
41
|
|
32
|
-
def return!(id, options)
|
33
|
-
client.put("model/sale.sale/#{id}/return_order", options)
|
34
|
-
rescue ErpIntegration::HttpError::BadRequest
|
35
|
-
false
|
36
|
-
end
|
37
|
-
|
38
|
-
# Allows duplicating the entire sales order in Fulfil.
|
39
|
-
# @param id [Integer|String] The ID of the to be duplicated order.
|
40
|
-
# @return [Array|boolean] Whether the sales order was duplicated successfully or not.
|
41
|
-
def duplicate(id)
|
42
|
-
duplicated_order_id = client.put("model/sale.sale/#{id}/copy").first
|
43
|
-
ErpIntegration::SalesOrder.new(id: duplicated_order_id)
|
44
|
-
|
45
|
-
# Fulfil will return an 400 (a.k.a. "Bad Request") status code when a sales order couldn't
|
46
|
-
# be duplicated.
|
47
|
-
rescue ErpIntegration::HttpError::BadRequest
|
48
|
-
false
|
49
|
-
end
|
50
|
-
|
51
42
|
# Confirm the order on Fulfil.
|
52
43
|
# @param id [Integer|String] The ID of the to be confirmed order.
|
53
44
|
# @return [boolean] Whether the sales order was confirmed successfully or not.
|
@@ -66,6 +57,45 @@ module ErpIntegration
|
|
66
57
|
true
|
67
58
|
end
|
68
59
|
|
60
|
+
# Creates the sales order in one API call in Fulfil.
|
61
|
+
#
|
62
|
+
# Fulfil allows two ways of creating a new sales order. Through their
|
63
|
+
# regular/generic API endpoint just like any other resource or through the
|
64
|
+
# sales channel.
|
65
|
+
#
|
66
|
+
# The benefit of using the Sales Channel route is it allows creating the sales
|
67
|
+
#
|
68
|
+
# @see https://developers.fulfil.io/guides/creating-orders/#create-order-api
|
69
|
+
#
|
70
|
+
# The sales order number is used as an idempotency key for Fulfil to prevent
|
71
|
+
# sales orders from being processed twice. Due to that it's a required attribute.
|
72
|
+
#
|
73
|
+
# @see https://developers.fulfil.io/guides/creating-orders/#channel_identifier
|
74
|
+
#
|
75
|
+
# @param sales_channel [String, Integer] The ID of the sales channel in Fulfil.
|
76
|
+
# @param attributes [Hash] The attributes of the sales order
|
77
|
+
# @return [ErpIntegration::SalesOrder]
|
78
|
+
def create_for(sales_channel, attributes:)
|
79
|
+
raise MissingIdempotencyKey if attributes['reference'].blank? && attributes[:reference].blank?
|
80
|
+
|
81
|
+
ErpIntegration::SalesOrder.new(
|
82
|
+
client.put("model/sale.channel/#{sales_channel}/create_order", [attributes])
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Allows duplicating the entire sales order in Fulfil.
|
87
|
+
# @param id [Integer|String] The ID of the to be duplicated order.
|
88
|
+
# @return [Array|boolean] Whether the sales order was duplicated successfully or not.
|
89
|
+
def duplicate(id)
|
90
|
+
duplicated_order_id = client.put("model/sale.sale/#{id}/copy").first
|
91
|
+
ErpIntegration::SalesOrder.new(id: duplicated_order_id)
|
92
|
+
|
93
|
+
# Fulfil will return an 400 (a.k.a. "Bad Request") status code when a sales order couldn't
|
94
|
+
# be duplicated.
|
95
|
+
rescue ErpIntegration::HttpError::BadRequest
|
96
|
+
false
|
97
|
+
end
|
98
|
+
|
69
99
|
# Process the order on Fulfil.
|
70
100
|
# @param id [Integer|String] The ID of the to be processed order.
|
71
101
|
# @return [boolean] Whether the sales order was processed successfully or not.
|
@@ -83,6 +113,16 @@ module ErpIntegration
|
|
83
113
|
rescue Faraday::ParsingError
|
84
114
|
true
|
85
115
|
end
|
116
|
+
|
117
|
+
# Creates a return order in Fulfil.
|
118
|
+
#
|
119
|
+
# @param id [Integer, String] The ID of the sales order
|
120
|
+
# @param options [Hash] The attributes needed for the return.
|
121
|
+
def return!(id, options)
|
122
|
+
client.put("model/sale.sale/#{id}/return_order", options)
|
123
|
+
rescue ErpIntegration::HttpError::BadRequest
|
124
|
+
false
|
125
|
+
end
|
86
126
|
end
|
87
127
|
end
|
88
128
|
end
|
@@ -80,12 +80,14 @@ module ErpIntegration
|
|
80
80
|
# Due to `method_missing` we're able to delegate all the work automatically
|
81
81
|
# to the adapter. However, if the method doesn't exist on the adapter, the
|
82
82
|
# `NoMethodError` is still being raised.
|
83
|
+
#
|
83
84
|
# @param method_name [Symbol] The name of the missing method.
|
84
|
-
# @param args [Array] The list of arguments for the missing method.
|
85
|
+
# @param args [Array] The list of positional arguments for the missing method.
|
86
|
+
# @param kwargs [Hash] The list of arguments for the missing method.
|
85
87
|
# @param block [Proc] Any block given to the missing method.
|
86
|
-
def method_missing(method_name, *args, &block)
|
88
|
+
def method_missing(method_name, *args, **kwargs, &block)
|
87
89
|
if adapter.respond_to?(method_name)
|
88
|
-
adapter.send(method_name, *args, &block)
|
90
|
+
adapter.send(method_name, *args, **kwargs, &block)
|
89
91
|
else
|
90
92
|
super
|
91
93
|
end
|
data/lib/erp_integration.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
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/object/blank'
|
6
7
|
require 'faraday'
|
7
8
|
require 'faraday_middleware'
|
8
9
|
require 'json'
|
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.28.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: 2023-03-
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|