houdini
houdini copied to clipboard
Use nonprofit currency symbol on donation queries
Description
Uses the nonprofit currency symbol to display the amount of money on donation queries
Closes #1235 Co-authored-by: Giulia Lobo [email protected]
Motivation to implement it
The amount of money was being displayed based on the currency configured on postgres by using postgres type cast to money:
Qexpr.new.select([
'donations.created_at',
'(payments.gross_amount/100.00)::money::text AS amount',
'COUNT(recurring_donations.id) > 0 AS recurring',
"STRING_AGG(campaign_gift_options.name, ',') AS campaign_gift_names"
]...
Because of this, the rails spec
command ended up failing in systems with different currency from USD, the right behavior in this cases is to use the nonprofit currency symbol instead of postgres type cast.
Solution summary
Instead of using postgres type cast, we decided to use the print_currency
existing function from ApplicationHelper, for that we used map based on the query results to change the amount to the currency string displayed.
result = QexprQueryChunker.get_chunk_of_query(offset, limit, skip_header) do
full_search_expr(npo_id, query).select(
'recurring_donations.created_at',
'recurring_donations.amount AS amount',
"concat('Every ', recurring_donations.interval, ' ', recurring_donations.time_unit, '(s)') AS interval",
'(SUM(paid_charges.amount) / 100.0)::money::text AS total_contributed',
...
end
result.map { |r| update_amount_with_currency(r, currency) }
update_amount_with_currency function:
def self.update_amount_with_currency(query_row, currency)
if query_row[1] != 'Amount'
query_row[1] = print_currency(query_row[1], currency, true, true)
end
query_row
end
Hi @wwahammy, we made the changes you asked in the code but we don't know how and where should we add the documentation for the print_currency method. Can you help us with that?
Hi @murilogds, sorry about not getting back to you until now.
You should document the method using the YARD documentation standard. In particularly, the description, the parameters and what is returned. An example of doing so can be found at https://yardoc.org/features.html
Hi @murilogds, sorry about not getting back to you until now.
You should document the method using the YARD documentation standard. In particularly, the description, the parameters and what is returned. An example of doing so can be found at https://yardoc.org/features.html
Thanks for the guide @wwahammy I updated the Pull Request with the documentation, can you review it?
Hi @murilogds @Giuulob89, just checking in. Is this ready for review?
Sorry for the delay @wwahammy I forgot to ask your review
Thanks for all the help @murilogds @Giuulob89!