From f13c72ebee0d6312512b88cd1c61e24b4e181902 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Sun, 4 May 2014 22:21:17 +0000 Subject: [PATCH] Bug 9593: (follow-up) don't make currency.isocode required This patch changes the price parsing so that it can fall back on the currency name if an ISO code is not supplied; this allows for handling the very common situation where the currency name as entered was already the same as the ISO code. Signed-off-by: Galen Charlton --- C4/Biblio.pm | 1 + .../prog/en/modules/admin/currency.tt | 4 +-- t/db_dependent/MungeMarcPrice.t | 25 ++++++++++++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 78cb5eaa09..0fb453db2f 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1517,6 +1517,7 @@ sub MungeMarcPrice { my $active_currency = C4::Budgets->GetCurrency(); my $symbol = $active_currency->{'symbol'}; my $isocode = $active_currency->{'isocode'}; + $isocode = $active_currency->{'currency'} unless defined $isocode; my $localprice; if ( $symbol ) { my @matches =($price=~ / diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt index 7de59e4e94..3165634b2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt @@ -81,8 +81,8 @@ Required
  • - - Required + +
  • Last updated: [% timestamp %] diff --git a/t/db_dependent/MungeMarcPrice.t b/t/db_dependent/MungeMarcPrice.t index 830f5c0e77..f661323e78 100755 --- a/t/db_dependent/MungeMarcPrice.t +++ b/t/db_dependent/MungeMarcPrice.t @@ -30,7 +30,7 @@ my @prices2test=( { string => '25,5 £, $34,55, $LD35', expected => '34.55 { string => '5.99 (7.75 CAN)', expected => '5.99' }, ); -plan tests => scalar @prices2test; +plan tests => 2 * scalar @prices2test; # set active currency test data my $CURRENCY = 'TEST'; @@ -49,9 +49,26 @@ if ($active_currency) { $dbh->do("INSERT INTO currency ( currency,symbol,isocode,rate,active ) VALUES ('$CURRENCY','$SYMBOL','$ISOCODE','$RATE',1)"); foreach my $price (@prices2test) { - my $mungemarcprice=MungeMarcPrice($price->{'string'}); - my $expected=$price->{'expected'}; - ok ($mungemarcprice eq $expected, "must return $price->{'expected'} from initial string : $price->{'string'}"); + is( + MungeMarcPrice($price->{'string'}), + $price->{'expected'}, + "got expected price from $price->{'string'} (using currency.isocode)", + ); } + +# run tests again, but fall back to currency name +$dbh->do('DELETE FROM aqbasket'); +$dbh->do('DELETE FROM currency'); +$dbh->do("INSERT INTO currency ( currency, symbol, rate, active ) + VALUES ('$ISOCODE', '$SYMBOL', '$RATE', 1)"); + +foreach my $price (@prices2test) { + is( + MungeMarcPrice($price->{'string'}), + $price->{'expected'}, + "got expected price from $price->{'string'} (using ISO code as currency name)", + ); +} + # Cleanup $dbh->rollback; -- 2.39.5