effective_qb_online 0.1.5 → 0.2.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: b576a3949ed29e03fff73780968b77c380cd4454c8117b39aba87690f96a0ae9
4
- data.tar.gz: c16c7f2ad020a416e0fae62fa98016cff913f1bd372e4e06feb8cd042954ebae
3
+ metadata.gz: 20091c462c42fe7c361cc24f430c7ac8050b5fd101db4d18b0dd96730b1d7e8f
4
+ data.tar.gz: 86db22b8febd131c30659676ad3a39edb1d6ee8c3cf84fda9055d12c1fab6658
5
5
  SHA512:
6
- metadata.gz: 07c548ac7ea522e377897dca08cb17f77b3db74b3633bd61135584297857c04100a7adc1942f410b141dbbb2c7e3968e748c2769f4e32c98fbd627977924c8fc
7
- data.tar.gz: d4986d17edbe98241942c5888537f2593fcbab09a0ddf81c6194989a0daf7db7124025c992c0d39ac1157077314cd8b6dd3dcdbdecd6dabd05e4a00e428e6c99
6
+ metadata.gz: fda907556a72911aedbfa905ea2faef422f6ef4f7a78e0591353f655ffc3b0f3b66a3fc024381f2de0a143315f32f80c567c63bba47b5453471731d733f97708
7
+ data.tar.gz: b37c30a31998a33d7f4fc5e50256f2c09b4833a541384717473edf90b11bd692c8a7082ec000acf3e184e22c872346fad7b9f85509c023d20e9d452cc8378429
@@ -5,9 +5,14 @@ module Admin
5
5
 
6
6
  include Effective::CrudController
7
7
 
8
+ page_title 'QuickBooks Online'
9
+
8
10
  # /admin/quickbooks
9
11
  def index
10
- @page_title = 'QuickBooks Online'
12
+ end
13
+
14
+ # /admin/quickbooks/items
15
+ def items
11
16
  end
12
17
 
13
18
  end
@@ -0,0 +1,16 @@
1
+ module Admin
2
+ class EffectiveQbItemsDatatable < Effective::Datatable
3
+ datatable do
4
+ col :id, label: 'QuickBooks Item Id'
5
+ col :name, label: 'QuickBooks Item Name'
6
+ col :fully_qualified_name, label: 'QuickBooks Fully Qualified Name'
7
+ end
8
+
9
+ collection do
10
+ EffectiveQbOnline.api.items.map do |item|
11
+ [item.id, item.name, item.fully_qualified_name]
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -26,6 +26,13 @@ module Admin
26
26
  col :status
27
27
  col :result
28
28
 
29
+ col :order_items, label: 'Purchasable Qb Item Names' do |receipt|
30
+ receipt.order.purchasables.map do |purchasable|
31
+ purchasable_id_name = [purchasable.try(:qb_item_id), purchasable.try(:qb_item_name)].compact
32
+ content_tag(:div, purchasable_id_name.join(' or '), class: "col-resource_item")
33
+ end.join.html_safe
34
+ end
35
+
29
36
  actions_col
30
37
  end
31
38
 
@@ -75,19 +75,10 @@ module Effective
75
75
  items
76
76
  .reject { |item| item.type == 'Category' }
77
77
  .sort_by { |item| [item.type, item.name] }
78
- .map { |item| [item_name(item), item.id, {'data-html': item_html(item)}, item.type] }
78
+ .map { |item| [item.name, item.id, {'data-html': item_html(item)}, item.type] }
79
79
  .group_by(&:last)
80
80
  end
81
81
 
82
- def item_name(item)
83
- [
84
- item.name,
85
- ("##{item.id}"),
86
- (item.sku if item.sku.present?),
87
- (item.description if item.description.present?)
88
- ].compact.join(' ')
89
- end
90
-
91
82
  def item_html(item)
92
83
  details = [
93
84
  ("##{item.id}"),
@@ -33,5 +33,9 @@ module Effective
33
33
  'QuickBooks Online Settings'
34
34
  end
35
35
 
36
+ def configured?
37
+ realm_id.present? && access_token.present? && deposit_to_account_id.present? && payment_method_id.present?
38
+ end
39
+
36
40
  end
37
41
  end
@@ -79,7 +79,6 @@ module Effective
79
79
  error!
80
80
  end
81
81
 
82
- true
83
82
  end
84
83
 
85
84
  def skip!
@@ -93,6 +92,9 @@ module Effective
93
92
 
94
93
  def error!
95
94
  errored!
95
+ EffectiveLogger.error(result, associated: self) if defined?(EffectiveLogger)
96
+
97
+ false
96
98
  end
97
99
 
98
100
  end
@@ -29,17 +29,25 @@ module Effective
29
29
  purchasable = receipt_item.order_item.purchasable
30
30
  raise("Expected a purchasable for Effective::OrderItem #{receipt_item.order_item.id}") unless purchasable.present?
31
31
 
32
+ # Either of these could match
33
+ purchasable_id_name = [
34
+ (scrub(purchasable.qb_item_id) if purchasable.try(:qb_item_id)),
35
+ (scrub(purchasable.qb_item_name) if purchasable.try(:qb_item_name))
36
+ ].compact
37
+
32
38
  # Find item by receipt item
33
- item = items.find { |item| [item.id, item.name].include?(receipt_item.item_id) }
39
+ item = items.find do |item|
40
+ [scrub(item.id), scrub(item.name), scrub(item.fully_qualified_name)].include?(scrub(receipt_item.item_id))
41
+ end
34
42
 
35
43
  # Find item by purchasable qb_item_id and qb_item_name
36
- item ||= begin
37
- purchasable_id_name = [purchasable.try(:qb_item_id), purchasable.try(:qb_item_name)]
38
- items.find { |item| ([item.id, item.name] & purchasable_id_name).present? }
44
+ item ||= items.find do |item|
45
+ ([scrub(item.id), scrub(item.name), scrub(item.fully_qualified_name)] & purchasable_id_name).present?
39
46
  end
40
47
 
41
48
  if item.blank?
42
- raise("Unknown QuickBooks Item for #{purchasable} (#{purchasable.class.name} ##{purchasable.id})")
49
+ purchasable_id_name = [purchasable.try(:qb_item_id), purchasable.try(:qb_item_name)].compact
50
+ raise("Unknown Item #{purchasable_id_name.join(' or ')} from #{purchasable} (#{purchasable.class.name} ##{purchasable.id})")
43
51
  end
44
52
 
45
53
  receipt_item.update!(item_id: item.id)
@@ -97,5 +105,11 @@ module Effective
97
105
  sales_receipt
98
106
  end
99
107
 
108
+ private
109
+
110
+ def self.scrub(value)
111
+ value.to_s.downcase.strip
112
+ end
113
+
100
114
  end
101
115
  end
@@ -32,6 +32,9 @@
32
32
  .col= f.select :payment_method_id, api.payment_methods_collection, label: false
33
33
  .col= f.save
34
34
 
35
+ %tr
36
+ %td Items
37
+ %td= link_to 'Quickbooks Items', effective_qb_online.admin_quickbooks_items_path
35
38
 
36
39
  - if company_info.blank?
37
40
  %table.table.table-sm
@@ -11,8 +11,13 @@
11
11
  = card('Test Credentials') do
12
12
  = render('test_credentials', api: api)
13
13
 
14
- = card('Company') do
15
- = render('company', api: api)
14
+ - if api.realm&.configured?
15
+ .mb-2
16
+ = collapse('Show Company Settings') do
17
+ = render('company', api: api)
18
+ - else
19
+ = card('Company') do
20
+ = render('company', api: api)
16
21
 
17
22
  = card('Sales Receipts') do
18
23
  .text-right.mb-2
@@ -0,0 +1,5 @@
1
+ %h1.effective-admin-heading= @page_title
2
+
3
+ %p The following items are present on the connected QuickBooks company.
4
+
5
+ = render_datatable(Admin::EffectiveQbItemsDatatable.new)
data/config/routes.rb CHANGED
@@ -21,6 +21,7 @@ EffectiveQbOnline::Engine.routes.draw do
21
21
  end
22
22
 
23
23
  get '/quickbooks', to: 'qb_online#index', as: :quickbooks
24
+ get '/quickbooks/items', to: 'qb_online#items', as: :quickbooks_items
24
25
  end
25
26
 
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveQbOnline
2
- VERSION = '0.1.5'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.1.5
4
+ version: 0.2.0
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: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -212,6 +212,7 @@ files:
212
212
  - app/controllers/admin/qb_realms_controller.rb
213
213
  - app/controllers/admin/qb_receipts_controller.rb
214
214
  - app/controllers/effective/qb_oauth_controller.rb
215
+ - app/datatables/admin/effective_qb_items_datatable.rb
215
216
  - app/datatables/admin/effective_qb_receipts_datatable.rb
216
217
  - app/helpers/effective_qb_online_helper.rb
217
218
  - app/jobs/qb_sync_order_job.rb
@@ -224,6 +225,7 @@ files:
224
225
  - app/views/admin/qb_online/_connect.html.haml
225
226
  - app/views/admin/qb_online/_test_credentials.html.haml
226
227
  - app/views/admin/qb_online/index.html.haml
228
+ - app/views/admin/qb_online/items.html.haml
227
229
  - app/views/admin/qb_receipts/_form.html.haml
228
230
  - app/views/admin/qb_receipts/edit.html.haml
229
231
  - app/views/admin/qb_receipts/new.html.haml