qube_rails 0.2.0 → 0.3.0

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +321 -0
  3. data/README.md +406 -76
  4. data/app/assets/javascripts/qube_rails/question.js +469 -43
  5. data/app/assets/stylesheets/qube_rails.css +1349 -912
  6. data/app/controllers/qube_rails/connections_controller.rb +42 -9
  7. data/app/controllers/qube_rails/questions_controller.rb +39 -7
  8. data/app/controllers/qube_rails/runs_controller.rb +4 -3
  9. data/app/controllers/qube_rails/storyboard_controller.rb +1 -1
  10. data/app/models/qube_rails/connection.rb +131 -9
  11. data/app/models/qube_rails/quickbooks_record.rb +22 -0
  12. data/app/models/qube_rails/run.rb +28 -10
  13. data/app/views/qube_rails/_error.html.erb +2 -2
  14. data/app/views/qube_rails/_manage_connection.html.erb +19 -0
  15. data/app/views/qube_rails/_question.html.erb +4 -1
  16. data/app/views/qube_rails/question/_choice.html.erb +34 -11
  17. data/app/views/qube_rails/question/_disclosure.html.erb +7 -0
  18. data/app/views/qube_rails/question/_exit_button.html.erb +8 -0
  19. data/app/views/qube_rails/question/_field.html.erb +4 -3
  20. data/app/views/qube_rails/question/_footer.html.erb +12 -4
  21. data/app/views/qube_rails/question/_inline_search.html.erb +12 -0
  22. data/app/views/qube_rails/question/_pick.html.erb +29 -6
  23. data/app/views/qube_rails/question/_picks.html.erb +2 -1
  24. data/app/views/qube_rails/question/_question.html.erb +31 -7
  25. data/app/views/qube_rails/question/_submit.html.erb +9 -0
  26. data/app/views/qube_rails/question/fields/_boolean.html.erb +2 -2
  27. data/app/views/qube_rails/question/fields/_number.html.erb +2 -2
  28. data/app/views/qube_rails/question/fields/_rows.html.erb +17 -4
  29. data/app/views/qube_rails/question/fields/_search.html.erb +6 -3
  30. data/app/views/qube_rails/question/fields/_select.html.erb +6 -5
  31. data/app/views/qube_rails/question/fields/_text.html.erb +2 -2
  32. data/app/views/qube_rails/question/rows/_segmented.html.erb +3 -1
  33. data/app/views/qube_rails/run_status/_detail.html.erb +5 -1
  34. data/app/views/qube_rails/run_status/_status.html.erb +5 -2
  35. data/app/views/qube_rails/storyboard/show.html.erb +4 -3
  36. data/config/locales/en.yml +30 -1
  37. data/config/routes.rb +2 -0
  38. data/db/migrate/20261031000000_add_qube_connection_type_and_run_headline.rb +12 -0
  39. data/db/migrate/20261124000000_add_qube_company_file_change.rb +17 -0
  40. data/lib/generators/qube_rails/templates/connection_events.rb.tt +17 -1
  41. data/lib/generators/qube_rails/templates/initializer.rb.tt +12 -4
  42. data/lib/qube_rails/configuration.rb +5 -2
  43. data/lib/qube_rails/connection_events.rb +70 -7
  44. data/lib/qube_rails/engine.rb +1 -0
  45. data/lib/qube_rails/link_check.rb +274 -0
  46. data/lib/qube_rails/operation.rb +116 -32
  47. data/lib/qube_rails/question_view.rb +293 -35
  48. data/lib/qube_rails/request.rb +2 -0
  49. data/lib/qube_rails/rows_view.rb +18 -5
  50. data/lib/qube_rails/run_status_view.rb +12 -7
  51. data/lib/qube_rails/storyboard/ask_about_add.json +9 -11
  52. data/lib/qube_rails/storyboard/choose.json +10 -7
  53. data/lib/qube_rails/storyboard/enum_select.json +5 -4
  54. data/lib/qube_rails/storyboard/missing_record.json +11 -14
  55. data/lib/qube_rails/storyboard/name_clash.json +51 -21
  56. data/lib/qube_rails/storyboard/near_match.json +18 -15
  57. data/lib/qube_rails/storyboard/number_boolean.json +5 -4
  58. data/lib/qube_rails/storyboard/record_search.json +15 -16
  59. data/lib/qube_rails/storyboard/refusal.json +15 -18
  60. data/lib/qube_rails/storyboard/rows.json +45 -31
  61. data/lib/qube_rails/storyboard.rb +28 -7
  62. data/lib/qube_rails/sync_status.rb +16 -3
  63. data/lib/qube_rails/version.rb +1 -1
  64. data/lib/qube_rails/view_helpers.rb +4 -2
  65. data/lib/qube_rails.rb +11 -2
  66. metadata +10 -2
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "title": "Records not in QuickBooks yet",
3
- "note": "add_transaction's ask_missing: a block per missing record, its fields stacked, each shown while its \"when\" holds. Hardware Kit's add says it's an inventory part, so its type is shown, not asked. \"Set all to:\" sets every record's choice; \"Use for all\" copies a picked value to the others.",
3
+ "note": "The invoice names several records QuickBooks doesn't have. Your user goes through them one at a time, creating each or using an existing one. A new item asks for its type and accounts.",
4
4
  "prompt": {
5
5
  "id": "add_transaction / ask_missing",
6
6
  "kind": "decision",
7
7
  "token": "Yj7sW9xCu5RkD7fF",
8
- "message": "Some records this transaction uses aren't in QuickBooks yet. For each one, create it or pick one QuickBooks already has.",
8
+ "message": "This invoice names records QuickBooks doesn't have. Create each one, or use one it has.",
9
9
  "data": {
10
10
  "operation": "invoice",
11
11
  "missing": [
@@ -33,10 +33,6 @@
33
33
  ]
34
34
  },
35
35
  "details": [
36
- {
37
- "label": "Adding",
38
- "value": "Invoice"
39
- },
40
36
  {
41
37
  "label": "Number",
42
38
  "value": "1042"
@@ -46,24 +42,24 @@
46
42
  "value": "Lone Star Supply"
47
43
  }
48
44
  ],
49
- "options": [],
50
45
  "choices": [
51
46
  {
52
47
  "id": "proceed",
53
- "label": "Add the transaction",
48
+ "label": "Add the invoice",
54
49
  "description": null,
55
50
  "detail": null,
56
51
  "fields": [
57
52
  {
58
53
  "name": "records",
59
54
  "type": "rows",
60
- "label": "Not in QuickBooks yet",
55
+ "label": "",
61
56
  "required": true,
62
57
  "columns": [
63
58
  {
64
59
  "name": "action",
65
60
  "type": "string",
66
61
  "label": "What to do",
62
+ "default": "create",
67
63
  "required": true,
68
64
  "kind": null,
69
65
  "enum": [
@@ -81,7 +77,7 @@
81
77
  {
82
78
  "name": "list_id",
83
79
  "type": "record",
84
- "label": "Existing record",
80
+ "label": "Which one",
85
81
  "required": true,
86
82
  "kind": null,
87
83
  "enum": null,
@@ -250,14 +246,15 @@
250
246
  }
251
247
  ]
252
248
  }
253
- ]
249
+ ],
250
+ "role": "answer"
254
251
  },
255
252
  {
256
253
  "id": "cancel",
257
- "label": "Cancel",
258
- "description": "Stop here. Nothing is created.",
254
+ "label": "Cancel adding the invoice",
259
255
  "detail": null,
260
- "fields": []
256
+ "fields": [],
257
+ "role": "cancel"
261
258
  }
262
259
  ]
263
260
  },
@@ -266,93 +263,110 @@
266
263
  {
267
264
  "value": "80000001-1700000000",
268
265
  "label": "Riverbend Electric",
269
- "detail": "Customer"
266
+ "detail": "Customer",
267
+ "kind": "customer"
270
268
  },
271
269
  {
272
270
  "value": "80000002-1700000000",
273
271
  "label": "Riverbend Supply Co.",
274
- "detail": "Customer"
272
+ "detail": "Customer",
273
+ "kind": "customer"
275
274
  },
276
275
  {
277
276
  "value": "80000003-1700000000",
278
277
  "label": "Lone Star Supply",
279
- "detail": "Customer"
278
+ "detail": "Customer",
279
+ "kind": "customer"
280
280
  },
281
281
  {
282
282
  "value": "80000011-1700000000",
283
283
  "label": "Vinyl Banner 3x6",
284
- "detail": "Inventory part"
284
+ "detail": "Inventory part",
285
+ "kind": "item"
285
286
  },
286
287
  {
287
288
  "value": "80000012-1700000000",
288
289
  "label": "Hardware Kit",
289
- "detail": "Non-inventory part"
290
+ "detail": "Non-inventory part",
291
+ "kind": "item"
290
292
  }
291
293
  ],
292
294
  "records.income_account": [
293
295
  {
294
296
  "value": "8000000A-1700000000",
295
297
  "label": "Sales",
296
- "detail": "Income"
298
+ "detail": "Income",
299
+ "kind": "account"
297
300
  },
298
301
  {
299
302
  "value": "8000000B-1700000000",
300
303
  "label": "Sales:Signs",
301
- "detail": "Income"
304
+ "detail": "Income",
305
+ "kind": "account"
302
306
  },
303
307
  {
304
308
  "value": "80000005-1700000000",
305
309
  "label": "Inventory Asset",
306
- "detail": "Other current asset"
310
+ "detail": "Other current asset",
311
+ "kind": "account"
307
312
  },
308
313
  {
309
314
  "value": "80000006-1700000000",
310
315
  "label": "Cost of Goods Sold",
311
- "detail": "Cost of goods sold"
316
+ "detail": "Cost of goods sold",
317
+ "kind": "account"
312
318
  }
313
319
  ],
314
320
  "records.asset_account": [
315
321
  {
316
322
  "value": "8000000A-1700000000",
317
323
  "label": "Sales",
318
- "detail": "Income"
324
+ "detail": "Income",
325
+ "kind": "account"
319
326
  },
320
327
  {
321
328
  "value": "8000000B-1700000000",
322
329
  "label": "Sales:Signs",
323
- "detail": "Income"
330
+ "detail": "Income",
331
+ "kind": "account"
324
332
  },
325
333
  {
326
334
  "value": "80000005-1700000000",
327
335
  "label": "Inventory Asset",
328
- "detail": "Other current asset"
336
+ "detail": "Other current asset",
337
+ "kind": "account"
329
338
  },
330
339
  {
331
340
  "value": "80000006-1700000000",
332
341
  "label": "Cost of Goods Sold",
333
- "detail": "Cost of goods sold"
342
+ "detail": "Cost of goods sold",
343
+ "kind": "account"
334
344
  }
335
345
  ],
336
346
  "records.cogs_account": [
337
347
  {
338
348
  "value": "8000000A-1700000000",
339
349
  "label": "Sales",
340
- "detail": "Income"
350
+ "detail": "Income",
351
+ "kind": "account"
341
352
  },
342
353
  {
343
354
  "value": "8000000B-1700000000",
344
355
  "label": "Sales:Signs",
345
- "detail": "Income"
356
+ "detail": "Income",
357
+ "kind": "account"
346
358
  },
347
359
  {
348
360
  "value": "80000005-1700000000",
349
361
  "label": "Inventory Asset",
350
- "detail": "Other current asset"
362
+ "detail": "Other current asset",
363
+ "kind": "account"
351
364
  },
352
365
  {
353
366
  "value": "80000006-1700000000",
354
367
  "label": "Cost of Goods Sold",
355
- "detail": "Cost of goods sold"
368
+ "detail": "Cost of goods sold",
369
+ "kind": "account"
356
370
  }
357
371
  ]
358
372
  }
@@ -86,15 +86,21 @@ module QubeRails
86
86
  end
87
87
 
88
88
  def question_view(screen, answer_path, search_path)
89
- QuestionView.new(screen.sample["prompt"], action_url: answer_path, search_url: search_path,
90
- error: screen.sample["error"])
89
+ prompt = screen.sample["prompt"]
90
+ refused = screen.sample["refused"]
91
+ refusal = refused && refused.merge("token" => prompt["token"], "message" => screen.sample["error"])
92
+ QuestionView.new(prompt, action_url: answer_path, search_url: search_path,
93
+ error: refusal ? nil : screen.sample["error"], refusal: refusal)
91
94
  end
92
95
 
93
- # The sample's matches for a search: at most 20 whose label holds q.
94
- def matches(screen, field, q)
96
+ # The sample's matches for a search: at most 20 whose label holds q. In a rows field, only
97
+ # the records of the row's kind, as QuBe Sync's search scopes by row.
98
+ def matches(screen, field, q, row = nil)
95
99
  list = screen && screen.kind == :question ? Array(screen.sample["search"][field.to_s]) : []
100
+ kind = row && row_kind(screen.sample, field.to_s, row.to_s)
96
101
  q = q.to_s.strip.downcase
97
- list.select { |m| m["label"].to_s.downcase.include?(q) }.first(20)
102
+ list.select { |m| kind.nil? || m["kind"].nil? || m["kind"] == kind }
103
+ .select { |m| m["label"].to_s.downcase.include?(q) }.first(20)
98
104
  end
99
105
 
100
106
  # The file an app puts at that path to override a piece.
@@ -105,6 +111,17 @@ module QubeRails
105
111
 
106
112
  private
107
113
 
114
+ # The kind of record a rows field's column takes in that row (its "kinds"), or nil.
115
+ def row_kind(sample, field, row)
116
+ name, column = field.split(".", 2)
117
+ return nil unless column
118
+
119
+ rows_field = Array(sample["prompt"]["choices"]).flat_map { |c| Array(c["fields"]) }
120
+ .find { |f| f["name"] == name && f["type"] == "rows" }
121
+ found = rows_field && Array(rows_field["rows"]).find { |r| r["key"] == row }
122
+ found && (found["kinds"] || {})[column]
123
+ end
124
+
108
125
  def run_status_screens
109
126
  RUN_STATUSES.map do |key, title, status, run, pieces, note|
110
127
  partials = %w[run_status/status run_status/summary] + pieces
@@ -131,8 +148,12 @@ module QubeRails
131
148
  list << "question/details" if Array(prompt["details"]).any?
132
149
  view = QuestionView.new(prompt, action_url: "", search_url: "")
133
150
  list.concat(%w[question/picks question/pick]) if view.picks.any?
134
- list << "question/choice" if view.forms.any? || view.exits.any?
135
- list << "question/footer" if view.exits.any?
151
+ list << "question/inline_search" if view.searches.any?
152
+ list << "question/disclosure" if view.disclosed.any?
153
+ list << "question/choice" if (view.forms + view.exits + view.alongside + view.disclosed).any?
154
+ list << "question/submit" if view.choices.any?
155
+ list << "question/exit_button" if view.joined_form && view.exits.any?
156
+ list << "question/footer" if !view.joined_form && view.exits.any?
136
157
  list << "error" if sample["error"]
137
158
  fields = Array(prompt["choices"]).flat_map { |choice| Array(choice["fields"]) }
138
159
  fields.each do |field|
@@ -10,7 +10,8 @@ module QubeRails
10
10
  # status.status # => :not_sent, :sending, :needs_answer, :in_quickbooks, :done, :failed or
11
11
  # # :cancelled
12
12
  # status.qb_id # the record's QuickBooks id on this connection, when it's linked
13
- # status.error # a failed run's error ({ "message" => ..., ... }), else nil
13
+ # status.error # a failed run's error ({ "code", "type", "message", "quickbooks_message",
14
+ # # "hint" }, or an older run's sentence), else nil
14
15
  # status.retry? # whether starting it again makes sense
15
16
  #
16
17
  # Per connection: an invoice can be in one company file and not another.
@@ -20,11 +21,13 @@ module QubeRails
20
21
  # 1. the latest run hasn't ended: :sending (starting or running, an unconfirmed start too:
21
22
  # unconfirmed? says so) or :needs_answer (awaiting input), whatever the link says;
22
23
  # 2. the latest run failed or was cancelled after the link was made (or there's no link):
23
- # :failed or :cancelled;
24
+ # :failed or :cancelled; a start refused as realtime_required is :failed whatever the link;
24
25
  # 3. the record is linked: :in_quickbooks, always with its qb_id;
25
26
  # 4. the latest run completed and linked nothing (an operation that doesn't link its record):
26
27
  # :done, which a start may follow, since nothing in QuickBooks stands for the record;
27
28
  # 5. neither: :not_sent.
29
+ # A run made before the connection last changed company file (company_file_changed_at) counts
30
+ # as none, and a stale link (not yet checked on the new file) as no link.
28
31
  class SyncStatus
29
32
  STATUSES = %i[not_sent sending needs_answer in_quickbooks done failed cancelled].freeze
30
33
 
@@ -33,8 +36,9 @@ module QubeRails
33
36
  # record's status on connection for operation (its SLUG).
34
37
  def self.for(connection, record, operation:)
35
38
  run = QubeRails::Run.where(connection: connection).latest_for(record, operation)
39
+ run = nil if run && before_file_change?(run, connection)
36
40
  type, id = QubeRails::ApplicationRecord.key_for(record)
37
- link = connection.quickbooks_records.where(record_type: type, record_id: id)
41
+ link = connection.quickbooks_records.current.where(record_type: type, record_id: id)
38
42
  .order(updated_at: :desc, id: :desc).first
39
43
  new(status_of(run, link), run, link)
40
44
  end
@@ -48,7 +52,16 @@ module QubeRails
48
52
  self.for(run.connection, record, operation: operation)
49
53
  end
50
54
 
55
+ # A run from before the customer switched the connection to another company file: it was the
56
+ # old file's, so the record reads as not sent on the new one.
57
+ def self.before_file_change?(run, connection)
58
+ changed_at = connection.company_file_changed_at
59
+ !changed_at.nil? && run.created_at < changed_at
60
+ end
61
+ private_class_method :before_file_change?
62
+
51
63
  def self.status_of(run, link)
64
+ return :failed if run&.realtime_required?
52
65
  return in_flight(run) if run && !run.ended?
53
66
  return stopped(run) if stopped_since_link?(run, link)
54
67
  return :in_quickbooks if link
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QubeRails
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -10,8 +10,10 @@ module QubeRails
10
10
  # qube_rails.css.
11
11
  def qube_rails_assets(stylesheet: false)
12
12
  tags = []
13
- tags << stylesheet_link_tag("qube_rails", media: "all") if stylesheet
14
- tags << javascript_include_tag("qube_rails/question", defer: true, nonce: true)
13
+ # data-turbo-track: under Turbo Drive a changed asset (a gem update) reloads the page, rather
14
+ # than keeping the old script, whose once-per-page guard would skip the new one.
15
+ tags << stylesheet_link_tag("qube_rails", media: "all", "data-turbo-track": "reload") if stylesheet
16
+ tags << javascript_include_tag("qube_rails/question", defer: true, nonce: true, "data-turbo-track": "reload")
15
17
  safe_join(tags, "\n")
16
18
  end
17
19
 
data/lib/qube_rails.rb CHANGED
@@ -9,6 +9,7 @@ require "qube_rails/database_dedupe"
9
9
  require "qube_rails/json_coder"
10
10
  require "qube_rails/operation"
11
11
  require "qube_rails/request"
12
+ require "qube_rails/link_check"
12
13
  require "qube_rails/sync_status"
13
14
  require "qube_rails/connection_events"
14
15
  require "qube_rails/question_view"
@@ -31,6 +32,14 @@ module QubeRails
31
32
  # connection.connected at once). The job raises it so the queue retries once it's there.
32
33
  class NotReady < StandardError; end
33
34
 
35
+ # Operation.start or Request.queue for a record whose link waits for its check after a company
36
+ # file change (Connection#checking_link?). Try again once it's settled; a job can retry on it.
37
+ class LinkBeingChecked < NotReady; end
38
+
39
+ # The same for a record whose link the new company file has under another name: the app settles
40
+ # it with Connection#confirm_link or #reject_link (README).
41
+ class LinkNeedsReview < NotReady; end
42
+
34
43
  # Operation.start was given a connection QuBe Sync hasn't made yet (no qube_id): the customer
35
44
  # hasn't finished onboarding, or QuBe Sync didn't answer it.
36
45
  class NotConnected < ArgumentError; end
@@ -41,8 +50,8 @@ module QubeRails
41
50
  # is sent, saying which reference and which record.
42
51
  class MissingReference < ArgumentError; end
43
52
 
44
- # QuBe Sync refused a start (422 realtime_required): workflows run on realtime connections, and
45
- # this one is standard. Its message says how to upgrade it.
53
+ # Operation.start on a standard connection, or a start QuBe Sync refused (422
54
+ # realtime_required): workflows run on realtime connections. Its message says how to upgrade.
46
55
  class RealtimeRequired < StandardError; end
47
56
 
48
57
  # Seconds after an event before a record's pages are told to refresh once more.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qube_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Lancaster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-27 00:00:00.000000000 Z
11
+ date: 2026-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: qube_sync
@@ -85,16 +85,21 @@ files:
85
85
  - app/models/qube_rails/run.rb
86
86
  - app/models/qube_rails/sync_mark.rb
87
87
  - app/views/qube_rails/_error.html.erb
88
+ - app/views/qube_rails/_manage_connection.html.erb
88
89
  - app/views/qube_rails/_question.html.erb
89
90
  - app/views/qube_rails/_run_status.html.erb
90
91
  - app/views/qube_rails/question/_choice.html.erb
91
92
  - app/views/qube_rails/question/_details.html.erb
93
+ - app/views/qube_rails/question/_disclosure.html.erb
94
+ - app/views/qube_rails/question/_exit_button.html.erb
92
95
  - app/views/qube_rails/question/_field.html.erb
93
96
  - app/views/qube_rails/question/_footer.html.erb
97
+ - app/views/qube_rails/question/_inline_search.html.erb
94
98
  - app/views/qube_rails/question/_message.html.erb
95
99
  - app/views/qube_rails/question/_pick.html.erb
96
100
  - app/views/qube_rails/question/_picks.html.erb
97
101
  - app/views/qube_rails/question/_question.html.erb
102
+ - app/views/qube_rails/question/_submit.html.erb
98
103
  - app/views/qube_rails/question/fields/_boolean.html.erb
99
104
  - app/views/qube_rails/question/fields/_number.html.erb
100
105
  - app/views/qube_rails/question/fields/_rows.html.erb
@@ -117,6 +122,8 @@ files:
117
122
  - db/migrate/20261026230000_add_qube_sync_status_indexes.rb
118
123
  - db/migrate/20261027000000_create_qube_sync_marks.rb
119
124
  - db/migrate/20261028000000_create_qube_requests.rb
125
+ - db/migrate/20261031000000_add_qube_connection_type_and_run_headline.rb
126
+ - db/migrate/20261124000000_add_qube_company_file_change.rb
120
127
  - lib/generators/qube_rails/install_generator.rb
121
128
  - lib/generators/qube_rails/templates/connection_events.rb.tt
122
129
  - lib/generators/qube_rails/templates/initializer.rb.tt
@@ -129,6 +136,7 @@ files:
129
136
  - lib/qube_rails/database_dedupe.rb
130
137
  - lib/qube_rails/engine.rb
131
138
  - lib/qube_rails/json_coder.rb
139
+ - lib/qube_rails/link_check.rb
132
140
  - lib/qube_rails/operation.rb
133
141
  - lib/qube_rails/question_view.rb
134
142
  - lib/qube_rails/request.rb