From 4c1ee9865a068952f54372e7bd3bae817db67abe Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 16 Jan 2020 15:58:25 -0300 Subject: [PATCH] Bug 24440: Add ->holds and ->holds_count to Koha::Acquisition::Order This patch introduces a method to fetch the holds associated with the items associated to an order line. It also adds a method to get that holds count, which will be handy on the API for embedding such information on request. To test: 1. Apply this patches 2. Run: $ kshell k$ prove t/db_dependent/Koha/Acquisition/Order.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind --- Koha/Acquisition/Order.pm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index 6d37e15c2b..3ee51b926d 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -25,6 +25,7 @@ use Koha::Acquisition::Invoices; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Biblios; +use Koha::Holds; use Koha::Items; use Koha::Subscriptions; @@ -169,6 +170,44 @@ sub subscription { return Koha::Subscription->_new_from_dbic( $subscription_rs ); } +=head3 holds + + my $holds = $order->holds + +Returns the holds associated to the order. It returns a I +resultset in scalar context or a list of I objects in list context. + +=cut + +sub holds { + my ($self) = @_; + + my $items_rs = $self->_result->aqorders_items; + my @item_numbers = $items_rs->get_column( 'itemnumber' )->all; + + return Koha::Holds->search( + { + itemnumber => { + -in => \@item_numbers + } + } + ); +} + +=head3 holds_count + + my $count = $order->holds_count + +Returns the holds count associated to the order. + +=cut + +sub holds_count { + my ($self) = @_; + + return $self->holds->count; +} + =head3 items my $items = $order->items -- 2.11.0