Skip to content

Commit

Permalink
fix crashes; add counts to initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewroth committed Dec 12, 2024
1 parent e970c9b commit 25acefd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/admin/issuances.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
# permitted
# end

filter :creator
filter :issuer
filter :gift_card_type
filter :status
filter :card_amount
filter :quantitiy
filter :begin_use_date
filter :end_use_date
filter :expiration_date
filter :allocated_certificates
filter :numbering
filter :issued_at
filter :created_at
filter :updated_at

index do
id_column
tag_column :status
Expand All @@ -31,6 +46,11 @@
column :max_certificate do |issuance|
issuance.allocated_certificates.split(Issuance::CERTIFICATE_DISPLAY_SEPARATOR).last
end
column :used do |issuance|
used = issuance.gift_cards.where(registrations_available: 0).count
total = issuance.gift_cards.count
raw("#{number_with_delimiter(used)}/#{number_with_delimiter(issuance.gift_cards.count)}<br/>(#{(used / total.to_f * 100).round(1)}%)")
end
column :begin_use_date
column :end_use_date
column :expiration_date
Expand Down
2 changes: 1 addition & 1 deletion app/models/issuance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Issuance < ApplicationRecord
end

def to_s
if preview?
if previewing?
"Gift Card Issuance (Preview)"
elsif issued?
"Issuance by #{issuer.full_name} #{created_at}"
Expand Down
4 changes: 4 additions & 0 deletions import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,7 @@
end

GiftCard.import(batch)

Issuance.where(quantity: [nil, 0]).each do |i|
i.update(quantity: i.gift_cards.count)
end

0 comments on commit 25acefd

Please sign in to comment.