From e37ec4b552bca8a5a3bd46e371c347755c69f933 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 26 May 2022 16:30:52 +1000 Subject: [PATCH] Avoid auto-formatting currencies Each report can define formats for each column. But currency formatting was also applied to all columns that had "price" in the name. Removing this automation gives us more control and we can decide for each case. At the moment, the currency formatting in Excel spreadsheets is not ideal and it's easier to keep it as number. This PR introduces a visual regression as prices are not formatted as nicely but the columns can be used in calculations. --- lib/reporting/report_row_builder.rb | 2 +- spec/system/admin/reports_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/reporting/report_row_builder.rb b/lib/reporting/report_row_builder.rb index 96683138e1..4ece1ec5db 100644 --- a/lib/reporting/report_row_builder.rb +++ b/lib/reporting/report_row_builder.rb @@ -75,7 +75,7 @@ module Reporting return "" if value.nil? # Currency - if report.columns_format[column] == :currency || column.to_s.include?("price") + if report.columns_format[column] == :currency format_currency(value) # Quantity elsif report.columns_format[column] == :quantity && report.html_render? diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 0c2676f64c..aa9400fa35 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -310,17 +310,17 @@ describe ' expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), - product1.primary_taxon.name, "Test", "$100.00", + product1.primary_taxon.name, "Test", "100.0", product1.group_buy_unit_size.to_s, "", "sku1"] expect(page).to have_table_row [product1.supplier.name, product1.supplier.address.city, "Product Name", product1.properties.map(&:presentation).join(", "), - product1.primary_taxon.name, "Something", "$80.00", + product1.primary_taxon.name, "Something", "80.0", product1.group_buy_unit_size.to_s, "", "sku2"] expect(page).to have_table_row [product2.supplier.name, product1.supplier.address.city, "Product 2", product1.properties.map(&:presentation).join(", "), - product2.primary_taxon.name, "100g", "$99.00", + product2.primary_taxon.name, "100g", "99.0", product1.group_buy_unit_size.to_s, "", "product_sku"] end @@ -332,7 +332,7 @@ describe ' expect(page).to have_table_row ['PRODUCT', 'Description', 'Qty', 'Pack Size', 'Unit', 'Unit Price', 'Total', 'GST incl.', 'Grower and growing method', 'Taxon'].map(&:upcase) - expect(page).to have_table_row ['Product 2', '100g', '', '100', 'g', '$99.00', '', '0', + expect(page).to have_table_row ['Product 2', '100g', '', '100', 'g', '99.0', '', '0', 'Supplier Name (Organic - NASAA 12345)', 'Taxon Name'] end end