Skip to content

Commit

Permalink
Merge pull request #891 from GratefulGarmentProject/donation-journal-…
Browse files Browse the repository at this point in the history
…exports

Donation journal exports to reverse clearing house account
  • Loading branch information
smellsblue authored Aug 14, 2024
2 parents a7ee366 + bdc551b commit e349314
Show file tree
Hide file tree
Showing 14 changed files with 563 additions and 102 deletions.
76 changes: 40 additions & 36 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ GEM
gyoku (>= 0.4.0)
nokogiri
ast (2.4.2)
autoprefixer-rails (10.4.16.0)
autoprefixer-rails (10.4.19.0)
execjs (~> 2)
awesome_print (1.9.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.8)
bindex (0.8.1)
bootsnap (1.18.3)
bootsnap (1.18.4)
msgpack (~> 1.2)
bootstrap-datepicker-rails (1.10.0.1)
railties (>= 3.0)
Expand All @@ -107,7 +107,8 @@ GEM
case_transform (0.2)
activesupport
chartkick (5.0.7)
childprocess (5.0.0)
childprocess (5.1.0)
logger (~> 1.5)
climate_control (1.2.0)
coderay (1.1.3)
coffee-rails (5.0.0)
Expand All @@ -117,7 +118,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crass (1.0.6)
csv (3.3.0)
Expand All @@ -136,9 +137,10 @@ GEM
erubi (1.13.0)
execjs (2.9.1)
fakefs (2.5.0)
faraday (2.9.2)
faraday (2.10.1)
faraday-net_http (>= 2.0, < 3.2)
faraday-net_http (3.1.0)
logger
faraday-net_http (3.1.1)
net-http
ffi (1.17.0)
gems (1.2.0)
Expand All @@ -150,21 +152,21 @@ GEM
google-api-client (0.53.0)
google-apis-core (~> 0.1)
google-apis-generator (~> 0.1)
google-apis-core (0.15.0)
google-apis-core (0.15.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.1, < 3.a)
httpclient (>= 2.8.3, < 3.a)
mini_mime (~> 1.0)
mutex_m
representable (~> 3.0)
retriable (>= 2.0, < 4.a)
rexml
google-apis-discovery_v1 (0.17.0)
google-apis-discovery_v1 (0.19.0)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-generator (0.15.0)
google-apis-generator (0.15.1)
activesupport (>= 5.0)
gems (~> 1.2)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-discovery_v1 (~> 0.14)
google-apis-discovery_v1 (~> 0.18)
thor (>= 0.20, < 2.a)
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
Expand All @@ -182,11 +184,11 @@ GEM
http-cookie (1.0.6)
domain_name (~> 0.5)
httpclient (2.8.3)
httpi (4.0.2)
httpi (4.0.4)
base64
mutex_m
nkf
rack (>= 2.0, < 3.1)
rack (>= 2.0, < 4)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
jbuilder (2.12.0)
Expand Down Expand Up @@ -220,6 +222,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
local_time (3.0.2)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -237,10 +240,10 @@ GEM
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0604)
mime-types-data (3.2024.0806)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.24.0)
minitest (5.24.1)
msgpack (1.7.2)
multi_json (1.15.0)
mutex_m (0.2.0)
Expand All @@ -258,25 +261,25 @@ GEM
netrc (0.11.0)
netsuite (0.8.12)
savon (>= 2.3.0)
newrelic_rpm (9.11.0)
newrelic_rpm (9.12.0)
nio4r (2.7.3)
nkf (0.2.0)
nokogiri (1.16.6)
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nori (2.7.0)
nori (2.7.1)
bigdecimal
orm_adapter (0.5.0)
os (1.1.4)
package_json (0.1.0)
paper_trail (12.3.0)
activerecord (>= 5.2)
request_store (~> 1.1)
parallel (1.25.1)
parser (3.3.3.0)
parallel (1.26.2)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
pg (1.5.6)
pg (1.5.7)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
Expand All @@ -287,10 +290,10 @@ GEM
pry (>= 0.13.0)
psych (5.1.2)
stringio
public_suffix (6.0.0)
public_suffix (6.0.1)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.0)
racc (1.8.1)
rack (2.2.9)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
Expand Down Expand Up @@ -361,7 +364,7 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.3.1)
rexml (3.3.4)
strscan
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
Expand All @@ -380,18 +383,18 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.64.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
ruby-ole (1.2.13.1)
ruby-progressbar (1.13.0)
Expand All @@ -408,11 +411,11 @@ GEM
tilt (>= 1.1, < 3)
sassc (2.4.0)
ffi (~> 1.9)
savon (2.15.0)
savon (2.15.1)
akami (~> 1.2)
builder (>= 2.1.2)
gyoku (~> 1.2)
httpi (>= 2.4.5, < 5)
httpi (>= 4, < 5)
mail (~> 2.5)
nokogiri (>= 1.8.1)
nori (~> 2.4)
Expand All @@ -427,11 +430,12 @@ GEM
rack-proxy (>= 0.6.1)
railties (>= 5.2)
semantic_range (>= 2.3.0)
sidekiq (7.2.4)
sidekiq (7.3.0)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
logger
rack (>= 2.2.4)
redis-client (>= 0.19.0)
redis-client (>= 0.22.2)
signet (0.19.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
Expand All @@ -445,7 +449,7 @@ GEM
base64
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
Expand All @@ -467,9 +471,9 @@ GEM
uri (0.13.0)
warden (1.2.9)
rack (>= 2.0.9)
wasabi (5.0.2)
wasabi (5.0.3)
addressable
faraday (~> 2.8)
faraday (>= 1.9, < 3)
nokogiri (>= 1.13.9)
web-console (4.2.1)
actionview (>= 6.0.0)
Expand All @@ -481,7 +485,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.16)
zeitwerk (2.6.17)

PLATFORMS
ruby
Expand Down
5 changes: 3 additions & 2 deletions app/jobs/export_donation_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ class ExportDonationJob < ApplicationJob

def perform(donation_id)
donation = Donation.find(donation_id)
raise "Donation #{donation.id} should not be synced" unless donation.can_be_synced?(syncing_now: true)

begin
NetSuiteIntegration.export_in_progress(donation)
NetSuiteIntegration.exports_in_progress(donation, additional_prefixes: :journal)
NetSuiteIntegration::DonationExporter.new(donation).export
rescue => e
FailedNetSuiteExport.record_error(donation, e)
NetSuiteIntegration.export_failed(donation)
NetSuiteIntegration.exports_failed(donation, additional_prefixes: :journal)
Rails.logger.error("Error exporting donation #{donation.id}: #{ErrorUtil.error_details(e)}")
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/export_order_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def perform(order_id)
rescue => e
FailedNetSuiteExport.record_error(order, e)
NetSuiteIntegration.exports_failed(order, additional_prefixes: :journal)
Rails.logger.error("Error exporting order #{order.id}: (#{e.class}) #{e.message}\n #{e.backtrace.join("\n ")}")
Rails.logger.error("Error exporting order #{order.id}: #{ErrorUtil.error_details(e)}")
end
end
end
2 changes: 1 addition & 1 deletion app/models/concerns/users/donation_manipulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def can_sync_donations?
end

def can_sync_donation?(donation)
can_sync_donations? && donation.closed? && !donation.synced?
can_sync_donations? && donation.can_be_synced?
end

def create_donation(params)
Expand Down
23 changes: 21 additions & 2 deletions app/models/donation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require "set"

class Donation < ApplicationRecord
CHANGEABLE_ATTRS = Set.new(%w[external_id journal_external_id]).freeze
include SoftDeletable

belongs_to :donor
Expand Down Expand Up @@ -46,8 +49,8 @@ def close

transaction do
create_values_for_programs
NetSuiteIntegration::DonationExporter.new(self).export_later
self.closed_at = Time.zone.now
NetSuiteIntegration::DonationExporter.new(self).export_later
save!
end
end
Expand All @@ -66,10 +69,26 @@ def sync_status_available?
external_id.present?
end

def journal_sync_status_available?
journal_external_id.present?
end

def can_be_synced?(syncing_now: false)
if syncing_now
closed? && donor.synced? && NetSuiteIntegration.any_not_exported_successfully?(self, additional_prefixes: :journal)
else
closed? && donor.synced? && (!synced? || !journal_synced?)
end
end

def synced?
external_id.present? && !NetSuiteIntegration.export_failed?(self)
end

def journal_synced?
journal_external_id.present? && !NetSuiteIntegration.export_failed?(self, prefix: :journal)
end

def formatted_donation_date
donation_date.strftime("%-m/%-d/%Y") if donation_date.present?
end
Expand Down Expand Up @@ -138,7 +157,7 @@ def not_changing_after_closed
# Changing nothing won't really have any affect on the closed donation
return if changed == []
# Allow changing external id later, otherwise syncing to NetSuite will fail
return if changed == %w[external_id]
return if changed.all? { |attr| CHANGEABLE_ATTRS.include?(attr) }
errors.add(:base, "cannot change a closed donation!")
end
end
Loading

0 comments on commit e349314

Please sign in to comment.