Bug 4078: Add the ability to display and configure the symbol for prices
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 1 Feb 2018 17:32:39 +0000 (14:32 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Mar 2018 14:45:38 +0000 (11:45 -0300)
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 <kyle@bywatersolutions.com>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Number/Price.pm
t/Number/Price.t

index 8e08607..899044f 100644 (file)
@@ -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;
 }
index ea58488..4b706b3 100644 (file)
@@ -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' );