Bug 9593: (follow-up) don't make currency.isocode required
authorGalen Charlton <gmc@esilibrary.com>
Sun, 4 May 2014 22:21:17 +0000 (22:21 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Sun, 4 May 2014 22:21:17 +0000 (22:21 +0000)
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 <gmc@esilibrary.com>
C4/Biblio.pm
koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt
t/db_dependent/MungeMarcPrice.t

index 78cb5ea..0fb453d 100644 (file)
@@ -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=~ /
index 7de59e4..3165634 100644 (file)
@@ -81,8 +81,8 @@
             <input type="text" name="symbol" id="symbol" size="5" maxlength="5" value="[% symbol %]" required="required" class="required" /> <span class="required">Required</span>
         </li>
         <li>
-            <label for="isocode" class="required">ISO code: </label>
-            <input type="text" name="isocode" id="isocode" size="5" maxlength="5" value="[% isocode %]" required="required"  class="required" /> <span class="required">Required</span>
+            <label for="isocode">ISO code: </label>
+            <input type="text" name="isocode" id="isocode" size="5" maxlength="5" value="[% isocode %]" />
         </li>
         <li>
             <span class="label">Last updated: </span>[% timestamp %]
index 830f5c0..f661323 100755 (executable)
@@ -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;