@@ -, +, @@ --- Koha/Acquisition/Order.pm | 14 -------------- Koha/Biblio.pm | 22 ++++------------------ Koha/Object.pm | 9 ++++++++- acqui/basket.pl | 4 ++-- acqui/parcel.pl | 2 +- 5 files changed, 15 insertions(+), 36 deletions(-) --- a/Koha/Acquisition/Order.pm +++ a/Koha/Acquisition/Order.pm @@ -194,20 +194,6 @@ sub holds { ); } -=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 --- a/Koha/Biblio.pm +++ a/Koha/Biblio.pm @@ -100,18 +100,18 @@ sub orders { =head3 active_orders_count -my $orders_count = $biblio->active_orders_count(); +my $active_orders = $biblio->active_orders(); -Returns the number of active acquisition orders related to this biblio. +Returns the active acquisition orders related to this biblio. An order is considered active when it is not cancelled (i.e. when datecancellation is not undef). =cut -sub active_orders_count { +sub active_orders { my ( $self ) = @_; - return $self->orders->search({ datecancellationprinted => undef })->count; + return $self->orders->search({ datecancellationprinted => undef }); } =head3 can_article_request @@ -411,20 +411,6 @@ sub items { return Koha::Items->_new_from_dbic( $items_rs ); } -=head3 items_count - -my $items_count = $biblio->items(); - -Returns the count of the the related Koha::Items object for this biblio - -=cut - -sub items_count { - my ($self) = @_; - - return $self->_result->items->count; -} - =head3 itemtype my $itemtype = $biblio->itemtype(); --- a/Koha/Object.pm +++ a/Koha/Object.pm @@ -431,7 +431,14 @@ sub to_api { my $curr = $embed; my $next = $embeds->{$curr}->{children}; - my $children = $self->$curr; + my $children; + my $method = $curr; + if ( $method =~ q{^(.*)_count$} ) { + $children = $self->$1; + $children = $children->count; + } else { + $children = $self->$curr; + } if ( defined $children and ref($children) eq 'ARRAY' ) { my @list = map { --- a/acqui/basket.pl +++ a/acqui/basket.pl @@ -136,7 +136,7 @@ if ( $op eq 'delete_confirm' ) { foreach my $myorder (@orders){ my $biblionumber = $myorder->{'biblionumber'}; my $biblio = Koha::Biblios->find( $biblionumber ); - my $countbiblio = $biblio->active_orders_count; + my $countbiblio = $biblio->active_orders->count; my $ordernumber = $myorder->{'ordernumber'}; my $cnt_subscriptions = $biblio->subscriptions->count; my $itemcount = $biblio->items->count; @@ -477,7 +477,7 @@ sub get_order_infos { my $biblionumber = $order->{'biblionumber'}; if ( $biblionumber ) { # The biblio still exists my $biblio = Koha::Biblios->find( $biblionumber ); - my $countbiblio = $biblio->active_orders_count; + my $countbiblio = $biblio->active_orders->count; my $ordernumber = $order->{'ordernumber'}; my $cnt_subscriptions = $biblio->subscriptions->count; --- a/acqui/parcel.pl +++ a/acqui/parcel.pl @@ -241,7 +241,7 @@ unless( defined $invoice->{closedate} ) { my $biblionumber = $line{'biblionumber'}; my $biblio = Koha::Biblios->find( $biblionumber ); - my $countbiblio = $biblio->active_orders_count; + my $countbiblio = $biblio->active_orders->count; my $ordernumber = $line{'ordernumber'}; my $order_object = Koha::Acquisition::Orders->find($ordernumber); my $cnt_subscriptions = $biblio ? $biblio->subscriptions->count: 0; --