From 92c4bd9eb7dd1aa1bf0043b42169b031c1bcaf90 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Tue, 17 Jan 2023 10:50:18 +0100 Subject: [PATCH] introduces format_percentage in ReportRowBuilder#format_cell --- config/locales/en.yml | 1 + lib/reporting/report_row_builder.rb | 9 +++++++++ .../reports/sales_tax/sales_tax_totals_by_producer.rb | 11 +++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 8e88db9b5f..bf7619dc28 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1373,6 +1373,7 @@ en: total_by_customer: Total By Customer total_by_supplier: Total By Supplier supplier_totals: Order Cycle Supplier Totals + percentage: "%{value} %" supplier_totals_by_distributor: Order Cycle Supplier Totals by Distributor totals_by_supplier: Order Cycle Distributor Totals by Supplier customer_totals: Order Cycle Customer Totals diff --git a/lib/reporting/report_row_builder.rb b/lib/reporting/report_row_builder.rb index 94846e4820..3cde18e014 100644 --- a/lib/reporting/report_row_builder.rb +++ b/lib/reporting/report_row_builder.rb @@ -85,6 +85,9 @@ module Reporting # Numeric elsif report.columns_format[column] == :numeric format_numeric(value) + # Percentage, a number between 0 and 1 + elsif report.columns_format[column] == :percentage + format_percentage(value) # Boolean elsif value.in? [true, false] format_boolean(value) @@ -124,5 +127,11 @@ module Reporting def format_numeric(value) number_with_delimiter(value) end + + def format_percentage(value) + return '' if value.blank? + + I18n.t('admin.reports.percentage', value: value * 100) + end end end diff --git a/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb b/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb index 16c343f79b..408497962f 100644 --- a/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb +++ b/lib/reporting/reports/sales_tax/sales_tax_totals_by_producer.rb @@ -51,6 +51,12 @@ module Reporting } end + def columns_format + { + tax_rate: :percentage + } + end + def rules [ { @@ -108,10 +114,7 @@ module Reporting end def tax_rate_amount(query_result_row) - amount = tax_rate(query_result_row)&.amount - return if amount.nil? - - "#{amount * 100} %" + tax_rate(query_result_row)&.amount end def total_excl_tax(query_result_row)