Currencies in reports


#1

Hi all,

I’m developing some use cases for adding new currencies to rates and reports. I’ve achieved to add these to rates ( an user can add, edit or save rates with one of these currencies: Dollars, Euros, Pounds or Yens) but I don’t know how to do it in reports.

I have been reviewing the code and I have found a function “number_to_currency” called by “format_currency_with_delimiter” in which the dollar symbol appear. I think that is in this function where the currency is added to reports because how only there is a currency, this is fixed. Is this true? Is in there? I’m very confuse because I have changed the “$” for a “€”, did reports and the currency displayed continues to be the dollar.

Thanks a lot,

Tamara.


#2

@sergio_ocon


#3

Hi @gtanzillo, could you help us with this when you can? We have got to a point where things are not working as expected and we are stuck.

Thanks a lot,
Sergio


#4

@tledesma The code that applies the format to the cost values in the report is here https://github.com/ManageIQ/manageiq/blob/master/app/models/miq_report/formatting.rb#L130-L137. That method calls number_to_currency to format the value of the cost. The number_to_currency method supports passing an option called :unit that can override the default ‘$’ unit. You can pass a specific currency symbol there. I did a test with the unit hard coded to ‘€’ and it successfully used that for the costs. Here’s my diff:

diff --git a/app/models/miq_report/formatting.rb b/app/models/miq_report/formatting.rb
index 53a5062..a221868 100644
--- a/app/models/miq_report/formatting.rb
+++ b/app/models/miq_report/formatting.rb
@@ -131,6 +131,7 @@ module MiqReport::Formatting
     av_options = {}
     av_options[:delimiter] = options[:delimiter] if options.key?(:delimiter)
     av_options[:separator] = options[:separator] if options.key?(:separator)
+    av_options[:unit] = '€'
     val = apply_format_precision(val, options[:precision])
     val = ActionView::Base.new.number_to_currency(val, av_options)
     apply_prefix_and_suffix(val, options)

The trick is to let the end user specify the currency, save it with the report and make it available to the format method.


#5

Thank you very much @gtanzillo. I changed it and it worked well! Now, I can continue doing the changes in order to save the currency selected by the user with the report.
Thanks again.