@@ -, +, @@ $ kshell k$ prove t/db_dependent/Koha/Acquisition/Order.t --- Koha/Acquisition/Order.pm | 34 +++++++++++++++++++++++++++++++++- Koha/Schema/Result/Aqorder.pm | 14 ++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) --- a/Koha/Acquisition/Order.pm +++ a/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 ); } --- a/Koha/Schema/Result/Aqorder.pm +++ a/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 } ); --