effective_qb_online 0.9.7 → 0.9.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a76e27c7de7949bc0eda143d1f54b01a24f9242df10ded427287d952758451a
4
- data.tar.gz: bbd314c5c7a59814c67386a44f2e097ae71cf46759736ce2e2b3652ff0f34a7b
3
+ metadata.gz: e9c2123d98959752c1fc3282eaed56393c472270627852362f18f481df53effb
4
+ data.tar.gz: 5337ce9494f3677d72d3d8b5fb95ed43612d3a1580631cc6954d0f0dbac20f83
5
5
  SHA512:
6
- metadata.gz: 108bfb5e515c03ea0fa47c0718298504718fb3d0ee63d448131fc0fdc32ddc6517facd9eb382fa8e1d3471096c54e4c0845a376ad43eb2b1d6f05f48cc49fd59
7
- data.tar.gz: 43653ac4f849fe09de8bb7b06b23b458d76f514423a3f92f14fce53727f382871613afe6d85c8c534dc7c8b2138710698a3d61454b01a94fb25a13558e6d3135
6
+ metadata.gz: ba8008ddd33147f3cf9f793a9f8a2477ed231ba91588cbaa47246ce571b91107eff55298d4a1eef5fb28144279ee011d35c7b5fe5b0ca1680cb1eaa6a3714f26
7
+ data.tar.gz: 3ab35742a9bd30d10248a8a8efeaf4511c42bc9a1390283f6a5387a69ec76e95e3faeb39673e97b31065d336a5c6e8d5229597dcbfc529d13afe610661aecbc7
@@ -79,6 +79,11 @@ module Effective
79
79
  .group_by(&:last)
80
80
  end
81
81
 
82
+ # Array of strings
83
+ def item_names
84
+ items_collection.values.flatten(1).map(&:first).map(&:to_s).reject(&:blank?).uniq.sort
85
+ end
86
+
82
87
  def item_html(item)
83
88
  details = [
84
89
  ("##{item.id}"),
@@ -88,7 +88,7 @@ module Effective
88
88
  assign_attributes(result: 'completed successfully', sales_receipt_id: sales_receipt.id)
89
89
  complete!
90
90
  rescue => e
91
- result = [e.message, ("(intuit_tid: #{e.intuit_tid})" if e.try(:intuit_tid).present?), e.backtrace.first(15)].compact.flatten.join("\n\n")
91
+ result = [e.message, ("(intuit_tid: #{e.intuit_tid})" if e.try(:intuit_tid).present?)].compact.join("\n\n")
92
92
  assign_attributes(result: result)
93
93
  error!
94
94
  end
@@ -19,7 +19,7 @@ module Effective
19
19
  end
20
20
 
21
21
  def order_item_qb_name
22
- item_id || order_item.purchasable.try(:qb_item_id) || order_item.purchasable.try(:qb_item_name)
22
+ item_id.presence || order_item.purchasable.try(:qb_item_id) || order_item.purchasable.try(:qb_item_name)
23
23
  end
24
24
 
25
25
  end
@@ -100,7 +100,7 @@ module Effective
100
100
 
101
101
  receipt.qb_receipt_items.each do |receipt_item|
102
102
  order_item = receipt_item.order_item
103
- line_item = Quickbooks::Model::Line.new(amount: api.price_to_amount(order_item.subtotal), description: order_item.name)
103
+ line_item = Quickbooks::Model::Line.new(amount: api.price_to_amount(order_item.subtotal), description: strip_html(order_item.name))
104
104
 
105
105
  line_item.sales_item! do |line|
106
106
  line.item_id = receipt_item.item_id
@@ -161,5 +161,15 @@ module Effective
161
161
  value.to_s.downcase.strip
162
162
  end
163
163
 
164
+ # Order item names may contain HTML (e.g. an EventRegistrant's "Member" badge).
165
+ # QuickBooks line item descriptions are plain text, so strip the markup while keeping
166
+ # the badge text. Convert line breaks to spaces first so adjacent text doesn't run together.
167
+ def self.strip_html(value)
168
+ return value if value.blank?
169
+
170
+ text = value.to_s.gsub(/<br\s*\/?>/i, ' ')
171
+ ActionView::Base.full_sanitizer.sanitize(text).squish
172
+ end
173
+
164
174
  end
165
175
  end
@@ -28,7 +28,7 @@
28
28
  = f.fields_for :qb_receipt_items do |fi|
29
29
  %tr
30
30
  %td= fi.object.order_item_id
31
- %td= fi.object.order_item
31
+ %td= fi.object.order_item.to_s.html_safe
32
32
  %td
33
33
  - if fi.object.item_id.present?
34
34
  - existing = items.find { |(name, id)| id == fi.object.item_id }&.first
@@ -12,7 +12,7 @@
12
12
  = @order.billing_name
13
13
  %p
14
14
  - @order.order_items.each do |oi|
15
- = "#{oi.name} (#{oi.try(:qb_item_name)})"
15
+ = oi.to_s.html_safe
16
16
  %br
17
17
 
18
18
  %p
@@ -1,3 +1,3 @@
1
1
  module EffectiveQbOnline
2
- VERSION = '0.9.7'.freeze
2
+ VERSION = '0.9.9'.freeze
3
3
  end
@@ -61,4 +61,28 @@ module EffectiveQbOnline
61
61
  qb_receipt.skip!
62
62
  end
63
63
 
64
+ # Syncs the QuickBooks Online item names down into Effective::ItemName
65
+ def self.sync_item_names!
66
+ client = api()
67
+ raise 'expected a connected QuickBooks Online realm' if client.blank?
68
+
69
+ qb_item_names = client.item_names
70
+ raise 'QuickBooks Online returned no items' if qb_item_names.blank?
71
+
72
+ qb_item_names.each do |name|
73
+ item_name = Effective::ItemName.where(name: name).first_or_initialize
74
+
75
+ if item_name.new_record?
76
+ item_name.save!
77
+ elsif item_name.archived?
78
+ item_name.unarchive!
79
+ end
80
+ end
81
+
82
+ Effective::ItemName.unarchived.where.not(name: qb_item_names).find_each do |item_name|
83
+ item_name.archive!
84
+ end
85
+
86
+ true
87
+ end
64
88
  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.9.7
4
+ version: 0.9.9
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-13 00:00:00.000000000 Z
11
+ date: 2026-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails