effective_qb_online 0.9.3 → 0.9.4
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/app/models/effective/qb_api.rb +45 -25
- data/lib/effective_qb_online/version.rb +1 -1
- data/lib/effective_qb_online.rb +5 -2
- metadata +32 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75e9d79cb2a17b67a7c5d6add16160822d572e40122a89ba4b64541850a2457d
|
|
4
|
+
data.tar.gz: 2cf7ab4cd08e0ae4ad9cc4bdfc090eba23b86c93d6e3d554452689377fb8e798
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ca7e1412b2d19086a5e55acf282e6b023970323ba255e342e5f1a8582f5179a166debde4447ab9d7d7050fdd14e358c591fae04bb5d4ffe2cf8a520e2a0ebeb9
|
|
7
|
+
data.tar.gz: 38a668cff06a99766b813d045939b2b06048b30c775a599b46746f25d05aed34a456e7a61737cb6b47a54223d792e00304346aae7fc13cb502423825844b2c4e
|
|
@@ -51,11 +51,11 @@ module Effective
|
|
|
51
51
|
|
|
52
52
|
# Singular
|
|
53
53
|
def company_info
|
|
54
|
-
with_service('CompanyInfo') { |service| service.fetch_by_id(realm.realm_id) }
|
|
54
|
+
@company_info ||= with_service('CompanyInfo') { |service| service.fetch_by_id(realm.realm_id) }
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def accounts
|
|
58
|
-
with_service('Account') { |service| service.all }
|
|
58
|
+
@accounts ||= with_service('Account') { |service| service.all }
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
# Only accounts we can use for the Deposit to Account setting
|
|
@@ -68,7 +68,7 @@ module Effective
|
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def items
|
|
71
|
-
with_service('Item') { |service| service.all }
|
|
71
|
+
@items ||= with_service('Item') { |service| service.all }
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def items_collection
|
|
@@ -90,7 +90,7 @@ module Effective
|
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
def payment_methods
|
|
93
|
-
with_service('PaymentMethod') { |service| service.all }
|
|
93
|
+
@payment_methods ||= with_service('PaymentMethod') { |service| service.all }
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
def payment_methods_collection
|
|
@@ -154,38 +154,40 @@ module Effective
|
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
def tax_codes
|
|
157
|
-
with_service('TaxCode') { |service| service.all }
|
|
157
|
+
@tax_codes ||= with_service('TaxCode') { |service| service.all }
|
|
158
158
|
end
|
|
159
159
|
|
|
160
160
|
def tax_rates
|
|
161
|
-
with_service('TaxRate') { |service| service.all }
|
|
161
|
+
@tax_rates ||= with_service('TaxRate') { |service| service.all }
|
|
162
162
|
end
|
|
163
163
|
|
|
164
164
|
# Returns a Hash of BigDecimal.to_s String Tax Rate => TaxCode Object
|
|
165
165
|
# { '0.0' => 'Quickbooks::Model::TaxCode(Exempt)', '5.0' => 'Quickbooks::Model::TaxCode(GST)' }
|
|
166
166
|
def taxes_collection
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
@taxes_collection ||= begin
|
|
168
|
+
rates = tax_rates()
|
|
169
|
+
codes = tax_codes()
|
|
169
170
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
# Find Exempt 0.0
|
|
172
|
+
exempt = codes.find do |code|
|
|
173
|
+
rate_id = code.sales_tax_rate_list.tax_rate_detail.first&.tax_rate_ref&.value
|
|
174
|
+
rate = rates.find { |rate| rate.id == rate_id } if rate_id
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
code.name.downcase.include?('exempt') && rate && rate.rate_value == 0.0
|
|
177
|
+
end
|
|
177
178
|
|
|
178
|
-
|
|
179
|
+
exempt = [['0.0', exempt]] if exempt.present?
|
|
179
180
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
# Find The rest
|
|
182
|
+
tax_codes = codes.select(&:active?).map do |code|
|
|
183
|
+
rate_id = code.sales_tax_rate_list.tax_rate_detail.first&.tax_rate_ref&.value
|
|
184
|
+
rate = rates.find { |rate| rate.id == rate_id } if rate_id
|
|
184
185
|
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
[rate.rate_value.to_s, code] if rate && (exempt.blank? || rate.rate_value.to_f > 0.0)
|
|
187
|
+
end
|
|
187
188
|
|
|
188
|
-
|
|
189
|
+
(Array(exempt) + tax_codes.compact.uniq { |key, _| key }).to_h
|
|
190
|
+
end
|
|
189
191
|
end
|
|
190
192
|
|
|
191
193
|
def with_service(name, &block)
|
|
@@ -193,18 +195,35 @@ module Effective
|
|
|
193
195
|
|
|
194
196
|
with_authenticated_request do |access_token|
|
|
195
197
|
service = klass.new(company_id: realm.realm_id, access_token: access_token)
|
|
198
|
+
|
|
199
|
+
# quickbooks-ruby's rebuild_connection! creates a new Faraday connection
|
|
200
|
+
# on every service call with no timeouts. Reuse a single connection with
|
|
201
|
+
# timeouts so all calls share one TCP connection via HTTP keep-alive.
|
|
202
|
+
service.oauth.client.connection = faraday_connection
|
|
203
|
+
|
|
196
204
|
yield(service)
|
|
197
205
|
end
|
|
198
206
|
end
|
|
199
207
|
|
|
200
208
|
private
|
|
201
209
|
|
|
210
|
+
def faraday_connection
|
|
211
|
+
@faraday_connection ||= Faraday.new do |faraday|
|
|
212
|
+
faraday.request :multipart
|
|
213
|
+
faraday.request :gzip
|
|
214
|
+
faraday.request :url_encoded
|
|
215
|
+
faraday.options.open_timeout = 10
|
|
216
|
+
faraday.options.timeout = 30
|
|
217
|
+
faraday.adapter Quickbooks.http_adapter
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
202
221
|
def with_authenticated_request(max_attempts: 3, &block)
|
|
203
222
|
attempts = 0
|
|
204
223
|
|
|
205
224
|
begin
|
|
206
|
-
|
|
207
|
-
yield(
|
|
225
|
+
@access_token ||= OAuth2::AccessToken.new(EffectiveQbOnline.oauth2_client, realm.access_token, refresh_token: realm.refresh_token)
|
|
226
|
+
yield(@access_token)
|
|
208
227
|
rescue OAuth2::Error, Quickbooks::AuthorizationFailure => e
|
|
209
228
|
puts "QuickBooks OAuth Error: #{e.message}"
|
|
210
229
|
|
|
@@ -212,7 +231,8 @@ module Effective
|
|
|
212
231
|
raise "unable to refresh QuickBooks OAuth2 token" if attempts >= max_attempts
|
|
213
232
|
|
|
214
233
|
# Refresh
|
|
215
|
-
refreshed =
|
|
234
|
+
refreshed = @access_token.refresh!
|
|
235
|
+
@access_token = nil # Clear memoized token so it's rebuilt with new credentials
|
|
216
236
|
|
|
217
237
|
realm.update!(
|
|
218
238
|
access_token: refreshed.token,
|
data/lib/effective_qb_online.rb
CHANGED
|
@@ -21,12 +21,15 @@ module EffectiveQbOnline
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def self.oauth2_client
|
|
24
|
-
OAuth2::Client.new(
|
|
24
|
+
@oauth2_client ||= OAuth2::Client.new(
|
|
25
25
|
oauth_client_id,
|
|
26
26
|
oauth_client_secret,
|
|
27
27
|
site: 'https://appcenter.intuit.com/connect/oauth2',
|
|
28
28
|
authorize_url: 'https://appcenter.intuit.com/connect/oauth2',
|
|
29
|
-
token_url: 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'
|
|
29
|
+
token_url: 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer',
|
|
30
|
+
connection_opts: {
|
|
31
|
+
request: { open_timeout: 10, timeout: 30 }
|
|
32
|
+
}
|
|
30
33
|
)
|
|
31
34
|
end
|
|
32
35
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: effective_qb_online
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Code and Effect
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-03-
|
|
11
|
+
date: 2026-03-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -137,7 +137,7 @@ dependencies:
|
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
138
|
version: '0'
|
|
139
139
|
- !ruby/object:Gem::Dependency
|
|
140
|
-
name: haml
|
|
140
|
+
name: haml-rails
|
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
|
142
142
|
requirements:
|
|
143
143
|
- - ">="
|
|
@@ -164,6 +164,34 @@ dependencies:
|
|
|
164
164
|
- - ">="
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
166
|
version: '0'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: psych
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0'
|
|
181
|
+
- !ruby/object:Gem::Dependency
|
|
182
|
+
name: wicked
|
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
|
184
|
+
requirements:
|
|
185
|
+
- - ">="
|
|
186
|
+
- !ruby/object:Gem::Version
|
|
187
|
+
version: '0'
|
|
188
|
+
type: :development
|
|
189
|
+
prerelease: false
|
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
191
|
+
requirements:
|
|
192
|
+
- - ">="
|
|
193
|
+
- !ruby/object:Gem::Version
|
|
194
|
+
version: '0'
|
|
167
195
|
- !ruby/object:Gem::Dependency
|
|
168
196
|
name: effective_test_bot
|
|
169
197
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -260,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
260
288
|
- !ruby/object:Gem::Version
|
|
261
289
|
version: '0'
|
|
262
290
|
requirements: []
|
|
263
|
-
rubygems_version: 3.
|
|
291
|
+
rubygems_version: 3.5.9
|
|
264
292
|
signing_key:
|
|
265
293
|
specification_version: 4
|
|
266
294
|
summary: Create QuickBooks Online SalesReceipts for purchased effective orders
|