diff --git a/app/models/chargeback_rate_detail.rb b/app/models/chargeback_rate_detail.rb index 16e0d040265d..c53854552293 100644 --- a/app/models/chargeback_rate_detail.rb +++ b/app/models/chargeback_rate_detail.rb @@ -84,12 +84,23 @@ def sub_metric_human sub_metric.present? ? sub_metric.capitalize : 'All' end + def format_rate(rate, suffix = "") + MiqReport.new.format_currency_with_delimiter(rate, :unit => detail_currency.symbol) + " / " + PER_TIME_TYPES[per_time] + suffix + end + + def format_unit(rate_unit) + unit = showback_unit(rate_unit) + unit.present? ? unit : Dictionary.gettext(per_unit, :notfound => :titleize) + end + def rate_values(consumption, options) fixed_rate, variable_rate = find_rate(chargeable_field.measure(consumption, options, sub_metric)) - hourly_fixed_rate = hourly(fixed_rate, consumption) - hourly_variable_rate = hourly(variable_rate, consumption) - "#{hourly_fixed_rate}/#{hourly_variable_rate}" + rates = [] + rates.push(format_rate(fixed_rate)) if fixed_rate > 0.0 + rates.push(format_rate(variable_rate, " / #{format_unit(per_unit)}")) if variable_rate > 0.0 + + "#{rates.join(" + ")}" end def charge(consumption, options) diff --git a/spec/models/chargeback_vm_spec.rb b/spec/models/chargeback_vm_spec.rb index 4811fea384a5..31a4114486a6 100644 --- a/spec/models/chargeback_vm_spec.rb +++ b/spec/models/chargeback_vm_spec.rb @@ -24,6 +24,7 @@ let(:hourly_variable_tier_rate) { {:variable_rate => hourly_rate.to_s} } let(:count_hourly_variable_tier_rate) { {:variable_rate => count_hourly_rate.to_s} } + let(:fixed_compute_tier_rate) { {:fixed_rate => hourly_rate.to_s} } let(:detail_params) do { @@ -35,7 +36,7 @@ :chargeback_rate_detail_net_io_used => {:tiers => [hourly_variable_tier_rate]}, :chargeback_rate_detail_storage_used => {:tiers => [count_hourly_variable_tier_rate]}, :chargeback_rate_detail_storage_allocated => {:tiers => [count_hourly_variable_tier_rate]}, - :chargeback_rate_detail_fixed_compute_cost => {:tiers => [hourly_variable_tier_rate]} + :chargeback_rate_detail_fixed_compute_cost => {:tiers => [fixed_compute_tier_rate]} } end @@ -183,8 +184,8 @@ def pluck_rollup(metric_rollup_records) end it 'shows rates' do - expect(subject.storage_allocated_sdd_rate).to eq("0.0/1.0") - expect(subject.storage_allocated_hdd_rate).to eq("0.0/1.0") + expect(subject.storage_allocated_sdd_rate).to eq("€1.00 / Hourly / GiB") + expect(subject.storage_allocated_hdd_rate).to eq("€1.00 / Hourly / GiB") end it "doesn't return removed cloud volume types fields" do @@ -740,15 +741,15 @@ def result_row_by(chargeback_result, date) let(:hourly_variable_tier_rate) { {:fixed_rate => 100, :variable_rate => hourly_rate.to_s} } it 'shows rates' do - expect(subject.cpu_allocated_rate).to eq("0.0/1.0") - expect(subject.cpu_used_rate).to eq("100.0/0.01") - expect(subject.disk_io_used_rate).to eq("100.0/0.01") - expect(subject.fixed_compute_1_rate).to eq("100.0/0.01") - expect(subject.memory_allocated_rate).to eq("100.0/0.01") - expect(subject.memory_used_rate).to eq("100.0/0.01") - expect(subject.net_io_used_rate).to eq("100.0/0.01") - expect(subject.storage_allocated_rate).to eq("0.0/1.0") - expect(subject.storage_used_rate).to eq("0.0/1.0") + expect(subject.cpu_allocated_rate).to eq("€1.00 / Hourly / Cpu") + expect(subject.cpu_used_rate).to eq("€100.00 / Hourly + €0.01 / Hourly / MHz") + expect(subject.disk_io_used_rate).to eq("€100.00 / Hourly + €0.01 / Hourly / Mbps") + expect(subject.fixed_compute_1_rate).to eq("€0.01 / Hourly") + expect(subject.memory_allocated_rate).to eq("€100.00 / Hourly + €0.01 / Hourly / MiB") + expect(subject.memory_used_rate).to eq("€100.00 / Hourly + €0.01 / Hourly / MiB" ) + expect(subject.net_io_used_rate).to eq("€100.00 / Hourly + €0.01 / Hourly / Mbps") + expect(subject.storage_allocated_rate).to eq("€1.00 / Hourly / GiB" ) + expect(subject.storage_used_rate).to eq("€1.00 / Hourly / GiB") end end