effective_qb_sync 1.3.5 → 1.3.6

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: bd0557466e309a81b913eecd1970ef494d071c3c01d03e004a537ea466345fa9
4
- data.tar.gz: 5c84e45ed198cf35fe3ac792fd4076efadb45d161803aedc12d6823118fb0a76
3
+ metadata.gz: 7661088e53e1d6c02bb8ce7ae766d2253e742cee52900ff1f88b5dda913cc81d
4
+ data.tar.gz: 9d34f24a3e7d7765012f38476771ce3ff5ef9767349e63e2c74e544be50fe1a9
5
5
  SHA512:
6
- metadata.gz: 8ec10245d4723b3e6debaa9a3958094c45365a03c348a9fac7a2df9ccd1c4c49f9f8a45f0ffe53acc8d79eaacc1db51eb29616b1d7596f7346c244a139fb493f
7
- data.tar.gz: ae9643278ae801730b9d2d7c21b3552eb9b7d1726a3ed54d298c56c3e69a8fcf2c2938cfcae7d36d2221a85cd22d92fd9d96cc79eeca55c58d23d478a4c57ad0
6
+ metadata.gz: a939efae8b650ac173d0b7f5adaca44d6c23f2183faafae00df54775699744fe49db531393daf08f144a598879de956bc92c84076d666e13ccf48a5514a1fa02
7
+ data.tar.gz: 58cb299e4125fce20c337e25aa0e7339622f29ab1471caca5553c2be1bf135347ba711955f89aceebe8fd96ab5e091717e172732f82c519d55f1fec9d35c0532
@@ -52,14 +52,7 @@ module Admin
52
52
  def set_all_orders_finished
53
53
  Effective::QbTicket.transaction do
54
54
  begin
55
- @qb_ticket = Effective::QbTicket.new(state: 'Finished')
56
- @qb_ticket.qb_logs.build(message: 'Set all orders Finished')
57
- @qb_ticket.save!
58
-
59
- Effective::QbRequest.new_requests_for_unsynced_items.each do |qb_request|
60
- qb_request.qb_ticket = @qb_ticket
61
- qb_request.transition_to_finished
62
- end
55
+ Effective::QbTicket.set_all_orders_finished!
63
56
 
64
57
  flash[:success] = 'Successfully set all orders finished'
65
58
  rescue => e
@@ -30,10 +30,16 @@ module Effective
30
30
 
31
31
  # creates (does not persist) QbRequests for outstanding orders. The caller may choose to
32
32
  # persist a request when that request starts communicating with QuickBooks
33
- def self.new_requests_for_unsynced_items
33
+ def self.new_requests_for_unsynced_items(before: nil)
34
34
  finished_order_ids = Effective::QbRequest.where(state: 'Finished').pluck(:order_id)
35
- Effective::Order.purchased.includes(order_items: [:purchasable, :qb_order_item])
36
- .where.not(id: finished_order_ids).map { |order| Effective::QbRequest.new(order: order) }
35
+ finished_orders = Effective::Order.purchased.includes(order_items: [:purchasable, :qb_order_item]).where.not(id: finished_order_ids)
36
+
37
+ if before.present?
38
+ raise('expected before to be a date') unless before.respond_to?(:strftime)
39
+ finished_orders = finished_orders.where('purchased_at < ?', before)
40
+ end
41
+
42
+ finished_orders.map { |order| Effective::QbRequest.new(order: order) }
37
43
  end
38
44
 
39
45
  # Finds a QbRequest using response qb_xml. If the response could not be parsed, or if there was no
@@ -30,6 +30,19 @@ module Effective
30
30
 
31
31
  validates :state, inclusion: { in: STATES }
32
32
 
33
+ def self.set_all_orders_finished!(before: nil)
34
+ qb_ticket = Effective::QbTicket.new(state: 'Finished')
35
+ qb_ticket.qb_logs.build(message: 'Set all orders Finished')
36
+ qb_ticket.save!
37
+
38
+ Effective::QbRequest.new_requests_for_unsynced_items(before: before).each do |qb_request|
39
+ qb_request.qb_ticket = qb_ticket
40
+ qb_request.transition_to_finished
41
+ end
42
+
43
+ true
44
+ end
45
+
33
46
  def request_error!(error, atts={})
34
47
  self.error!(error, atts.reverse_merge(state: 'RequestError'))
35
48
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveQbSync
2
- VERSION = '1.3.5'.freeze
2
+ VERSION = '1.3.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_qb_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect