erp_integration 0.26.0 → 0.27.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af2d7c35bd0582dd14abd43703dfe8eaff596501a17e19d6b600ab7b77771437
|
4
|
+
data.tar.gz: d42c0df0a66e21e1b51e64da1761cd774d30bde60a273e5eda2fe907871405cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9c61186614433de65b90c79eabed2980d44447c7b7f1dc7416960ad7d40f6ce92768fb7f81d9024cea3707dac48b0007f63d17c74b104fd112f2ce0dcf3c161
|
7
|
+
data.tar.gz: bec060c2f626b39e375561e4c19453e359243158877a10f12baf570aab10ae218ef9d30e9422178a704c54f9e2015ad7bcfb9f9cd0c13516af178cb1dcaa6259
|
@@ -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.27.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-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|