View | Details | Raw Unified | Return to bug 12844
Collapse All | Expand All

(-)a/Koha/Number/Price.pm (+5 lines)
Lines 56-61 sub unformat { Link Here
56
sub _format_params {
56
sub _format_params {
57
    my ( $self, $params ) = @_;
57
    my ( $self, $params ) = @_;
58
    my $with_symbol = $params->{with_symbol} || 0;
58
    my $with_symbol = $params->{with_symbol} || 0;
59
    my $p_cs_precedes = $params->{p_cs_precedes};
60
    my $p_sep_by_space = $params->{p_sep_by_space};
59
    my $currency        = GetCurrency();
61
    my $currency        = GetCurrency();
60
    my $currency_format = C4::Context->preference("CurrencyFormat");
62
    my $currency_format = C4::Context->preference("CurrencyFormat");
61
63
Lines 79-84 sub _format_params { Link Here
79
        );
81
        );
80
    }
82
    }
81
83
84
    $format_params{p_cs_precedes}  = $p_cs_precedes  if defined $p_cs_precedes;
85
    $format_params{p_sep_by_space} = $p_sep_by_space if defined $p_sep_by_space;
86
82
    return \%format_params;
87
    return \%format_params;
83
}
88
}
84
89
(-)a/t/Number/Price.t (-13 / +16 lines)
Lines 11-16 my $currency; Link Here
11
$budget_module->mock( 'GetCurrency', sub { return $currency; } );
11
$budget_module->mock( 'GetCurrency', sub { return $currency; } );
12
use_ok('Koha::Number::Price');
12
use_ok('Koha::Number::Price');
13
13
14
my $format = {
15
    p_cs_precedes => 1, # Force to place the symbol at the beginning
16
    p_sep_by_space => 0, # Force to not add a space between the symbol and the number
17
};
14
t::lib::Mocks::mock_preference( 'CurrencyFormat', 'US' );
18
t::lib::Mocks::mock_preference( 'CurrencyFormat', 'US' );
15
$currency = {
19
$currency = {
16
    currency => 'USD',
20
    currency => 'USD',
Lines 19-37 $currency = { Link Here
19
    active   => 1,
23
    active   => 1,
20
};
24
};
21
25
22
is( Koha::Number::Price->new->format,    '0.00', 'US: format 0' );
26
is( Koha::Number::Price->new->format( $format ),    '0.00', 'US: format 0' );
23
is( Koha::Number::Price->new(3)->format, '3.00', 'US: format 3' );
27
is( Koha::Number::Price->new(3)->format( $format ), '3.00', 'US: format 3' );
24
is( Koha::Number::Price->new(1234567890)->format,
28
is( Koha::Number::Price->new(1234567890)->format( $format ),
25
    '1,234,567,890.00', 'US: format 1234567890' );
29
    '1,234,567,890.00', 'US: format 1234567890' );
26
30
27
# FIXME This should be display symbol, but it was the case before the creation of this module
31
# FIXME This should be display symbol, but it was the case before the creation of this module
28
is( Koha::Number::Price->new->format( { with_symbol => 1 } ),
32
is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ),
29
    '0.00', 'US: format 0 with symbol' );
33
    '0.00', 'US: format 0 with symbol' );
30
is( Koha::Number::Price->new(3)->format( { with_symbol => 1 } ),
34
is( Koha::Number::Price->new(3)->format( { %$format, with_symbol => 1 } ),
31
    '3.00', 'US: format 3 with symbol' );
35
    '3.00', 'US: format 3 with symbol' );
32
is(
36
is(
33
    Koha::Number::Price->new(1234567890)
37
    Koha::Number::Price->new(1234567890)
34
      ->format( { with_symbol => 1 }, 'US: format 1234567890 with symbol' ),
38
      ->format( { %$format, with_symbol => 1 }, 'US: format 1234567890 with symbol' ),
35
    '1,234,567,890.00'
39
    '1,234,567,890.00'
36
);
40
);
37
41
Lines 50-69 $currency = { Link Here
50
54
51
# Actually,the price formating for France is 3,00€
55
# Actually,the price formating for France is 3,00€
52
# How put the symbol at the end with Number::Format?
56
# How put the symbol at the end with Number::Format?
53
is( Koha::Number::Price->new->format,    '0,00', 'FR: format 0' );
57
is( Koha::Number::Price->new->format( $format ),    '0,00', 'FR: format 0' );
54
is( Koha::Number::Price->new(3)->format, '3,00', 'FR: format 3' );
58
is( Koha::Number::Price->new(3)->format( $format ), '3,00', 'FR: format 3' );
55
is(
59
is(
56
    Koha::Number::Price->new(1234567890)->format,
60
    Koha::Number::Price->new(1234567890)->format( $format ),
57
    '1 234 567 890,00',
61
    '1 234 567 890,00',
58
    'FR: format 1234567890'
62
    'FR: format 1234567890'
59
);
63
);
60
is( Koha::Number::Price->new->format( { with_symbol => 1 } ),
64
is( Koha::Number::Price->new->format( { %$format, with_symbol => 1 } ),
61
    '€0,00', 'FR: format 0 with symbol' );
65
    '€0,00', 'FR: format 0 with symbol' );
62
is( Koha::Number::Price->new(3)->format( { with_symbol => 1 } ),
66
is( Koha::Number::Price->new(3)->format( { %$format, with_symbol => 1 } ),
63
    '€3,00', 'FR: format 3 with symbol' );
67
    '€3,00', 'FR: format 3 with symbol' );
64
is(
68
is(
65
    Koha::Number::Price->new(1234567890)
69
    Koha::Number::Price->new(1234567890)
66
      ->format( { with_symbol => 1 }, 'FR: format 123567890 with symbol' ),
70
      ->format( { %$format, with_symbol => 1 }, 'FR: format 123567890 with symbol' ),
67
    '€1 234 567 890,00'
71
    '€1 234 567 890,00'
68
);
72
);
69
73
70
- 

Return to bug 12844