Bug 15962: Block the currency deletion if used

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 c20496aea9)
Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
This commit is contained in:
Julian Maurice 2016-04-14 14:29:38 +02:00 committed by Frédéric Demians
parent 2f59171ca9
commit d3faa9cc53
2 changed files with 19 additions and 10 deletions

View File

@ -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;

View File

@ -125,10 +125,17 @@
[% 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>