945a0f09e7
Bug 12979 refactored the way to display prices. The price format configuration was duplicated everywhere it was used. All calls looks good except the one in admin/aqbudgetperiods.pl In this one, the prices are formatted for an edition field (input). This means the input is incorrectly filled even if the user does not update the field. At the end, maybe should we manage formatted prices everywhere, even in inputs, but it's not in the scope of this bug. Technically, a new subroutine format_for_editing is added to the Koha::Number::Price module. It should be called everywhere a price is displayed in an input field. At the moment, it only does a sprintf("%.2f"), but it is a first step to let the number of decimals to display configurable. To test: 1/ Verify the issue described is fixed (editing a budget with a total amount > 1000 (With CurrencyFormat is US or FR). 2/ Verify you can edit a fund with a total amount > 1000 Signed-off-by: Paola Rossi <paola.rossi@cineca.it> Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
412 lines
12 KiB
Perl
412 lines
12 KiB
Perl
use Modern::Perl;
|
|
use Test::More tests => 16;
|
|
use Test::MockModule;
|
|
|
|
use t::lib::Mocks;
|
|
|
|
BEGIN {
|
|
my $context_module = t::lib::Mocks::mock_dbh;
|
|
use_ok('C4::Acquisition');
|
|
use_ok('C4::Bookseller');
|
|
use_ok('C4::Context');
|
|
use_ok('Koha::Number::Price');
|
|
};
|
|
|
|
t::lib::Mocks::mock_preference( 'gist', '0.02|0.05|0.196' );
|
|
|
|
my $bookseller_module = Test::MockModule->new('Koha::Acquisition::Bookseller');
|
|
|
|
my ( $basketno_0_0, $basketno_1_1, $basketno_1_0, $basketno_0_1 );
|
|
my ( $invoiceid_0_0, $invoiceid_1_1, $invoiceid_1_0, $invoiceid_0_1 );
|
|
my $today;
|
|
|
|
for my $currency_format ( qw( US FR ) ) {
|
|
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
|
|
subtest 'Configuration 1: 0 0' => sub {
|
|
plan tests => 7;
|
|
$bookseller_module->mock(
|
|
'fetch',
|
|
sub {
|
|
return { listincgst => 0, invoiceincgst => 0 };
|
|
}
|
|
);
|
|
|
|
my $biblionumber_0_0 = 42;
|
|
|
|
my $order_0_0 = {
|
|
biblionumber => $biblionumber_0_0,
|
|
quantity => 2,
|
|
listprice => 82.000000,
|
|
unitprice => 73.80000,
|
|
quantityreceived => 2,
|
|
basketno => $basketno_0_0,
|
|
invoiceid => $invoiceid_0_0,
|
|
rrp => 82.00,
|
|
ecost => 73.80,
|
|
gstrate => 0.0500,
|
|
discount => 10.0000,
|
|
datereceived => $today
|
|
};
|
|
$order_0_0 = C4::Acquisition::populate_order_with_prices(
|
|
{
|
|
order => $order_0_0,
|
|
booksellerid => 'just_something',
|
|
ordering => 1,
|
|
}
|
|
);
|
|
|
|
# Note that this configuration is correct \o/
|
|
compare(
|
|
{
|
|
got => $order_0_0->{rrpgsti},
|
|
expected => 86.10,
|
|
conf => '0 0',
|
|
field => 'rrpgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_0->{rrpgste},
|
|
expected => 82.00,
|
|
conf => '0 0',
|
|
field => 'rrpgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_0->{ecostgsti},
|
|
expected => 77.49,
|
|
conf => '0 0',
|
|
field => 'ecostgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_0->{ecostgste},
|
|
expected => 73.80,
|
|
conf => '0 0',
|
|
field => 'ecostgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_0->{gstvalue},
|
|
expected => 7.38,
|
|
conf => '0 0',
|
|
field => 'gstvalue'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_0->{totalgsti},
|
|
expected => 154.98,
|
|
conf => '0 0',
|
|
field => 'totalgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_0->{totalgste},
|
|
expected => 147.60,
|
|
conf => '0 0',
|
|
field => 'totalgste'
|
|
}
|
|
);
|
|
};
|
|
|
|
subtest 'Configuration 1: 1 1' => sub {
|
|
plan tests => 7;
|
|
$bookseller_module->mock(
|
|
'fetch',
|
|
sub {
|
|
return { listincgst => 1, invoiceincgst => 1 };
|
|
}
|
|
);
|
|
|
|
my $biblionumber_1_1 = 43;
|
|
my $order_1_1 = {
|
|
biblionumber => $biblionumber_1_1,
|
|
quantity => 2,
|
|
listprice => 82.000000,
|
|
unitprice => 73.800000,
|
|
quantityreceived => 2,
|
|
basketno => $basketno_1_1,
|
|
invoiceid => $invoiceid_1_1,
|
|
rrp => 82.00,
|
|
ecost => 73.80,
|
|
gstrate => 0.0500,
|
|
discount => 10.0000,
|
|
datereceived => $today
|
|
};
|
|
|
|
$order_1_1 = C4::Acquisition::populate_order_with_prices(
|
|
{
|
|
order => $order_1_1,
|
|
booksellerid => 'just_something',
|
|
ordering => 1,
|
|
}
|
|
);
|
|
|
|
# Note that this configuration is *not* correct
|
|
# gstvalue should be 7.03 instead of 7.02
|
|
compare(
|
|
{
|
|
got => $order_1_1->{rrpgsti},
|
|
expected => 82.00,
|
|
conf => '1 1',
|
|
field => 'rrpgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_1->{rrpgste},
|
|
expected => 78.10,
|
|
conf => '1 1',
|
|
field => 'rrpgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_1->{ecostgsti},
|
|
expected => 73.80,
|
|
conf => '1 1',
|
|
field => 'ecostgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_1->{ecostgste},
|
|
expected => 70.29,
|
|
conf => '1 1',
|
|
field => 'ecostgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_1->{gstvalue},
|
|
expected => 7.02,
|
|
conf => '1 1',
|
|
field => 'gstvalue'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_1->{totalgsti},
|
|
expected => 147.60,
|
|
conf => '1 1',
|
|
field => 'totalgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_1->{totalgste},
|
|
expected => 140.58,
|
|
conf => '1 1',
|
|
field => 'totalgste'
|
|
}
|
|
);
|
|
};
|
|
|
|
subtest 'Configuration 1: 1 0' => sub {
|
|
plan tests => 7;
|
|
$bookseller_module->mock(
|
|
'fetch',
|
|
sub {
|
|
return { listincgst => 1, invoiceincgst => 0 };
|
|
}
|
|
);
|
|
|
|
my $biblionumber_1_0 = 44;
|
|
my $order_1_0 = {
|
|
biblionumber => $biblionumber_1_0,
|
|
quantity => 2,
|
|
listprice => 82.000000,
|
|
unitprice => 73.804500,
|
|
quantityreceived => 2,
|
|
basketno => $basketno_1_1,
|
|
invoiceid => $invoiceid_1_1,
|
|
rrp => 82.01,
|
|
ecost => 73.80,
|
|
gstrate => 0.0500,
|
|
discount => 10.0000,
|
|
datereceived => $today
|
|
};
|
|
|
|
$order_1_0 = C4::Acquisition::populate_order_with_prices(
|
|
{
|
|
order => $order_1_0,
|
|
booksellerid => 'just_something',
|
|
ordering => 1,
|
|
}
|
|
);
|
|
|
|
# Note that this configuration is *not* correct!
|
|
# rrp gsti should be 82 (what we inserted!)
|
|
# gstvalue should be 7.03 instead of 7.02
|
|
|
|
compare(
|
|
{
|
|
got => $order_1_0->{rrpgsti},
|
|
expected => 82.01,
|
|
conf => '1 0',
|
|
field => 'rrpgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_0->{rrpgste},
|
|
expected => 78.10,
|
|
conf => '1 0',
|
|
field => 'rrpgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_0->{ecostgsti},
|
|
expected => 73.80,
|
|
conf => '1 0',
|
|
field => 'ecostgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_0->{ecostgste},
|
|
expected => 70.29,
|
|
conf => '1 0',
|
|
field => 'ecostgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_0->{gstvalue},
|
|
expected => 7.02,
|
|
conf => '1 0',
|
|
field => 'gstvalue'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_0->{totalgsti},
|
|
expected => 147.60,
|
|
conf => '1 0',
|
|
field => 'totalgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_1_0->{totalgste},
|
|
expected => 140.58,
|
|
conf => '1 0',
|
|
field => 'totalgste'
|
|
}
|
|
);
|
|
};
|
|
|
|
subtest 'Configuration 1: 0 1' => sub {
|
|
plan tests => 7;
|
|
$bookseller_module->mock(
|
|
'fetch',
|
|
sub {
|
|
return { listincgst => 0, invoiceincgst => 1 };
|
|
}
|
|
);
|
|
|
|
my $biblionumber_0_1 = 45;
|
|
my $order_0_1 = {
|
|
biblionumber => $biblionumber_0_1,
|
|
quantity => 2,
|
|
listprice => 82.000000,
|
|
unitprice => 73.800000,
|
|
quantityreceived => 2,
|
|
basketno => $basketno_1_1,
|
|
invoiceid => $invoiceid_1_1,
|
|
rrp => 82.00,
|
|
ecost => 73.80,
|
|
gstrate => 0.0500,
|
|
discount => 10.0000,
|
|
datereceived => $today
|
|
};
|
|
|
|
$order_0_1 = C4::Acquisition::populate_order_with_prices(
|
|
{
|
|
order => $order_0_1,
|
|
booksellerid => 'just_something',
|
|
ordering => 1,
|
|
}
|
|
);
|
|
|
|
# Note that this configuration is correct \o/
|
|
compare(
|
|
{
|
|
got => $order_0_1->{rrpgsti},
|
|
expected => 86.10,
|
|
conf => '1 0',
|
|
field => 'rrpgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_1->{rrpgste},
|
|
expected => 82.00,
|
|
conf => '1 0',
|
|
field => 'rrpgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_1->{ecostgsti},
|
|
expected => 77.49,
|
|
conf => '1 0',
|
|
field => 'ecostgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_1->{ecostgste},
|
|
expected => 73.80,
|
|
conf => '1 0',
|
|
field => 'ecostgste'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_1->{gstvalue},
|
|
expected => 7.38,
|
|
conf => '1 0',
|
|
field => 'gstvalue'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_1->{totalgsti},
|
|
expected => 154.98,
|
|
conf => '1 0',
|
|
field => 'totalgsti'
|
|
}
|
|
);
|
|
compare(
|
|
{
|
|
got => $order_0_1->{totalgste},
|
|
expected => 147.60,
|
|
conf => '1 0',
|
|
field => 'totalgste'
|
|
}
|
|
);
|
|
};
|
|
}
|
|
|
|
sub compare {
|
|
my ($params) = @_;
|
|
is(
|
|
Koha::Number::Price->new( $params->{got} )->format,
|
|
Koha::Number::Price->new( $params->{expected} )->format,
|
|
"configuration $params->{conf}: $params->{field} should be correctly calculated"
|
|
);
|
|
}
|
|
|
|
# format_for_editing
|
|
for my $currency_format ( qw( US FR ) ) {
|
|
t::lib::Mocks::mock_preference( 'CurrencyFormat', $currency_format );
|
|
is( Koha::Number::Price->new( 1234567 )->format_for_editing, '1234567.00', 'format_for_editing should return unformated integer part with 2 decimals' );
|
|
is( Koha::Number::Price->new( 1234567.89 )->format_for_editing, '1234567.89', 'format_for_editing should return unformated integer part with 2 decimals' );
|
|
}
|