From 9e1a3c8dd146b0a6ff3c8220d09f73403faee664 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 1 Feb 2018 14:32:39 -0300 Subject: [PATCH] Bug 4078: Add the ability to display and configure the symbol for prices The symbol of currencies are not displayed (or not correctly) so far. This patch set adds the ability to configure the display of the symbol (with or without a whitespace between the symbol and the price). Test plan: 1. Execute the update DB entry, go to the currency admin page and tick the new "Space separation between symbol and value" checkbox 2. Add a fine to a patron and use their credentials to login at the OPAC 3. You should see the "$ 42 due fines and charges" info in the dashboard 4. Untick the new checkbox to remove the space and reload the OPAC main page. => The space should not be longer displayed ($42) Signed-off-by: Kyle M Hall --- Koha/Number/Price.pm | 8 ++------ t/Number/Price.t | 7 +++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Koha/Number/Price.pm b/Koha/Number/Price.pm index 8e08607..899044f 100644 --- a/Koha/Number/Price.pm +++ b/Koha/Number/Price.pm @@ -86,11 +86,10 @@ sub _format_params { my ( $self, $params ) = @_; my $with_symbol = $params->{with_symbol} || 0; my $p_cs_precedes = $params->{p_cs_precedes}; - my $p_sep_by_space = $params->{p_sep_by_space}; my $currency = Koha::Acquisition::Currencies->get_active; my $currency_format = C4::Context->preference("CurrencyFormat"); - my $int_curr_symbol = q||; + my $int_curr_symbol = $with_symbol ? $currency->symbol : q||; my %format_params = ( decimal_fill => '2', decimal_point => '.', @@ -101,8 +100,6 @@ sub _format_params { ); if ( $currency_format eq 'FR' ) { - # FIXME This test should be done for all currencies - $int_curr_symbol = $currency->symbol if $with_symbol; %format_params = ( decimal_fill => '2', decimal_point => ',', @@ -114,7 +111,6 @@ sub _format_params { } if ( $currency_format eq 'CH' ) { - $int_curr_symbol = $currency->symbol if $with_symbol; %format_params = ( decimal_fill => '2', decimal_point => '.', @@ -127,7 +123,7 @@ sub _format_params { $format_params{p_cs_precedes} = $p_cs_precedes if defined $p_cs_precedes; - $format_params{p_sep_by_space} = ( $int_curr_symbol and defined $p_sep_by_space ) ? $p_sep_by_space : 0; + $format_params{p_sep_by_space} = $currency->p_sep_by_space ? 1 : 0; return \%format_params; } diff --git a/t/Number/Price.t b/t/Number/Price.t index ea58488..4b706b3 100644 --- a/t/Number/Price.t +++ b/t/Number/Price.t @@ -35,15 +35,14 @@ is( Koha::Number::Price->new(1234567890)->format( $format ), is( Koha::Number::Price->new(100000000000000)->format, '100000000000000', 'Numbers too big are not formatted'); -# FIXME This should be display symbol, but it was the case before the creation of this module is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ), - '0.00', 'US: format 0 with symbol' ); + '$0.00', 'US: format 0 with symbol' ); is( Koha::Number::Price->new(3)->format( { %$format, with_symbol => 1 } ), - '3.00', 'US: format 3 with symbol' ); + '$3.00', 'US: format 3 with symbol' ); is( Koha::Number::Price->new(1234567890) ->format( { %$format, with_symbol => 1 }, 'US: format 1234567890 with symbol' ), - '1,234,567,890.00' + '$1,234,567,890.00' ); is( Koha::Number::Price->new->unformat, '0', 'US: unformat 0' ); -- 2.10.2