From 8829e8d21473486e29b7f4969165d201aa0a3c81 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 ->current_holds to Koha::Acquisition::Order This patch introduces a method to fetch the current holds associated with the items linked to an order line. It basically implements what's done in parcel.pl, but fully tested and suitable for using on the API. 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 Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- Koha/Acquisition/Order.pm | 34 +++++++++++++++++++++++++++++++++- Koha/Schema/Result/Aqorder.pm | 14 ++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index 6d37e15c2b..0eb5c7f3fa 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -169,6 +169,37 @@ sub subscription { return Koha::Subscription->_new_from_dbic( $subscription_rs ); } +=head3 current_holds + + my $holds = $order->current_holds; + +Returns the current holds associated to the order. It returns a I +resultset in scalar context or a list of I objects in list context. + +It returns B if no I or no I are linked to the order. + +=cut + +sub current_holds { + my ($self) = @_; + + my $items_rs = $self->_result->aqorders_items; + my @item_numbers = $items_rs->get_column('itemnumber')->all; + + return unless @item_numbers; + + my $biblio = $self->biblio; + return unless $biblio; + + return $biblio->current_holds->search( + { + itemnumber => { + -in => \@item_numbers + } + } + ); +} + =head3 items my $items = $order->items @@ -196,7 +227,8 @@ Returns the bibliographic record associated to the order sub biblio { my ( $self ) = @_; - my $biblio_rs= $self->_result->biblionumber; + my $biblio_rs= $self->_result->biblio; + return unless $biblio_rs; return Koha::Biblio->_new_from_dbic( $biblio_rs ); } diff --git a/Koha/Schema/Result/Aqorder.pm b/Koha/Schema/Result/Aqorder.pm index 75917c88f5..f9f307ceb2 100644 --- a/Koha/Schema/Result/Aqorder.pm +++ b/Koha/Schema/Result/Aqorder.pm @@ -664,12 +664,26 @@ __PACKAGE__->many_to_many("borrowernumbers", "aqorder_users", "borrowernumber"); # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-08-31 11:51:37 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GQEXetlivZm7buQohl8m4A +__PACKAGE__->belongs_to( + "biblio", + "Koha::Schema::Result::Biblio", + { 'foreign.biblionumber' => "self.biblionumber" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + sub koha_objects_class { 'Koha::Acquisition::Orders'; } + sub koha_object_class { 'Koha::Acquisition::Order'; } + __PACKAGE__->add_columns( '+uncertainprice' => { is_boolean => 1 } ); -- 2.39.5