Bug 15962: Block the currency deletion if used
authorJulian Maurice <julian.maurice@biblibre.com>
Thu, 14 Apr 2016 12:29:38 +0000 (14:29 +0200)
committerFrédéric Demians <f.demians@tamil.fr>
Wed, 27 Apr 2016 14:52:44 +0000 (16:52 +0200)
A currency should not be deleted if used by a vendor or a basket.

Test plan:
1/ Add a new currency
2/ Create a vendor using this currency
3/ Create a basket using this currency
4/ Try to delete the currency
5/ Delete the basket
6/ Try to delete the currency
7/ Delete the vendor
8/ Delete the currency

Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
(cherry picked from commit c20496aea938e1faaa53daff5e2cf3d697b0eac9)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>

admin/currency.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tt

index f62f761..d0c4be3 100755 (executable)
@@ -132,21 +132,23 @@ sub delete_confirm {
     my $curr = shift;
 
     $template->param( delete_confirm => 1 );
-    my $total_row = $dbh->selectrow_hashref(
-        'select count(*) as total from aqbooksellers where currency=?',
-        {}, $curr );
+    my ($nb_of_vendors) = $dbh->selectrow_array(q{
+        select count(*) from aqbooksellers
+        where listprice = ? or invoiceprice = ?
+    }, {}, $curr, $curr);
+    my ($nb_of_orders) = $dbh->selectrow_array(q{
+        select count(*) from aqorders
+        where currency = ?
+    }, {}, $curr);
 
     my $curr_ref = $dbh->selectrow_hashref(
         'select currency,rate from currency where currency=?',
         {}, $curr );
 
-    if ( $total_row->{total} ) {
-        $template->param( totalgtzero => 1 );
-    }
-
     $template->param(
         rate  => $curr_ref->{rate},
-        total => $total_row->{total}
+        nb_of_orders => $nb_of_orders,
+        nb_of_vendors => $nb_of_vendors,
     );
 
     return;
index 57c38cf..45ba3fd 100644 (file)
 [% END %]
 
 [% IF ( delete_confirm ) %]
-    [% IF ( totalgtzero ) %]
+    [% IF ( nb_of_orders or nb_of_vendors ) %]
     <div class="dialog message">
         <h3>Cannot delete currency <span class="ex">'[% searchfield %]'</span></h3>
-        <p>This currency is used [% total %] times. Deletion not possible</p>
+        <p>
+            [% IF nb_of_orders %]
+                This currency is used by [% nb_of_orders %] orders.
+            [% ELSIF nb_of_vendors %]
+                This currency is used by [% nb_of_vendors %] vendors.
+            [% END %]
+            Deletion not possible
+        </p>
         <form action="[% script_name %]" method="post">
             <input type="submit" value="OK" class="approve" />
         </form>