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 <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomás Cohen Arazi 2020-01-16 15:58:25 -03:00 committed by Martin Renvoize
parent a567c99087
commit 8829e8d214
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
2 changed files with 47 additions and 1 deletions

View file

@ -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<Koha::Holds>
resultset in scalar context or a list of I<Koha::Hold> objects in list context.
It returns B<undef> if no I<biblio> or no I<items> 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 );
}

View file

@ -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 }
);