Bug 17736: [QA Follow-up] We do not need GetItemHolds in acqui
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Fri, 6 Jan 2017 12:22:07 +0000 (13:22 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 31 Mar 2017 12:04:16 +0000 (12:04 +0000)
The solution of Jonathan can be applied in two other cases, effectively
making GetItemHolds obsolete.

Test plan:
[1] Git grep on GetItemHolds
[2] Add an order, place a hold, delete order.
[3] Add an order, receive, place hold, delete order.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
C4/Items.pm
acqui/basket.pl
acqui/parcel.pl

index d7b2600..dda02a3 100644 (file)
@@ -91,7 +91,6 @@ BEGIN {
         ShelfToCart
 
        GetAnalyticsCount
-        GetItemHolds
 
         SearchItemsByField
         SearchItems
@@ -2564,27 +2563,6 @@ sub GetAnalyticsCount {
     return ($result);
 }
 
-=head2 GetItemHolds
-
-  $holds = &GetItemHolds($biblionumber, $itemnumber);
-
-This function return the count of holds with $biblionumber and $itemnumber
-
-=cut
-
-sub GetItemHolds {
-    my ($biblionumber, $itemnumber) = @_;
-    my $holds;
-    my $dbh            = C4::Context->dbh;
-    my $query          = "SELECT count(*)
-        FROM  reserves
-        WHERE biblionumber=? AND itemnumber=?";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($biblionumber, $itemnumber);
-    $holds = $sth->fetchrow;
-    return $holds;
-}
-
 =head2 SearchItemsByField
 
     my $items = SearchItemsByField($field, $value);
index 4940821..0677e33 100755 (executable)
@@ -470,13 +470,8 @@ sub get_order_infos {
     my $itemcount   = $biblio->items->count;
     my $holds_count = $biblio->holds->count;
     my @items = GetItemnumbersFromOrder( $ordernumber );
-    my $itemholds;
-    foreach my $item (@items){
-        my $nb = GetItemHolds($biblionumber, $item);
-        if ($nb){
-            $itemholds += $nb;
-        }
-    }
+    my $itemholds  = $biblio ? $biblio->holds->search({ itemnumber => { -in => \@items } })->count : 0;
+
     # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680
     $line{can_del_bib}          = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds_count);
     $line{items}                = ($itemcount) - (scalar @items);
index fbd376f..f89261f 100755 (executable)
@@ -245,13 +245,7 @@ unless( defined $invoice->{closedate} ) {
         my $itemcount   = $biblio->items->count;
         my $holds_count = $biblio->holds->count;
         my @items = GetItemnumbersFromOrder( $ordernumber );
-        my $itemholds;
-        foreach my $item (@items){
-            my $nb = GetItemHolds($biblionumber, $item);
-            if ($nb){
-                $itemholds += $nb;
-            }
-        }
+        my $itemholds = $biblio ? $biblio->holds->search({ itemnumber => { -in => \@items } })->count : 0;
 
         my $suggestion   = GetSuggestionInfoFromBiblionumber($line{biblionumber});
         $line{suggestionid}         = $suggestion->{suggestionid};