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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7661088e53e1d6c02bb8ce7ae766d2253e742cee52900ff1f88b5dda913cc81d
|
4
|
+
data.tar.gz: 9d34f24a3e7d7765012f38476771ce3ff5ef9767349e63e2c74e544be50fe1a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|