Bug 24430: Add ->orders and ->active_orders_count to Koha::Biblio
This patch introduces an accessor to the related orders, and a method
that returns the active orders count. The target usage for the count is the
API. In the rest of the codebase, we would just call:
$biblio->orders->count
To test:
1. Apply this patches
2. Run:
$ kshell
k$ prove t/db_dependent/Koha/Biblio.t
=> SUCCESS: Tests pass!
3. Sign off :-D
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
f06578b34e
commit
f30c2874cd
|
|
@ -32,6 +32,7 @@ use Koha::DateUtils qw( dt_from_string );
|
|||
|
||||
use base qw(Koha::Object);
|
||||
|
||||
use Koha::Acquisition::Orders;
|
||||
use Koha::ArticleRequest::Status;
|
||||
use Koha::ArticleRequests;
|
||||
use Koha::Biblio::Metadatas;
|
||||
|
|
@ -82,6 +83,37 @@ sub metadata {
|
|||
return Koha::Biblio::Metadata->_new_from_dbic($metadata);
|
||||
}
|
||||
|
||||
=head3 orders
|
||||
|
||||
my $orders = $biblio->orders();
|
||||
|
||||
Returns a Koha::Acquisition::Orders object
|
||||
|
||||
=cut
|
||||
|
||||
sub orders {
|
||||
my ( $self ) = @_;
|
||||
|
||||
my $orders = $self->_result->orders;
|
||||
return Koha::Acquisition::Orders->_new_from_dbic($orders);
|
||||
}
|
||||
|
||||
=head3 active_orders_count
|
||||
|
||||
my $orders_count = $biblio->active_orders_count();
|
||||
|
||||
Returns the number of 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 {
|
||||
my ( $self ) = @_;
|
||||
|
||||
return $self->orders->search({ datecancellationprinted => undef })->count;
|
||||
}
|
||||
|
||||
=head3 can_article_request
|
||||
|
||||
my $bool = $biblio->can_article_request( $borrower );
|
||||
|
|
|
|||
|
|
@ -417,6 +417,13 @@ __PACKAGE__->has_one(
|
|||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->has_many(
|
||||
"orders",
|
||||
"Koha::Schema::Result::Aqorder",
|
||||
{ "foreign.biblionumber" => "self.biblionumber" },
|
||||
{ cascade_copy => 0, cascade_delete => 0 },
|
||||
);
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
"+serial" => { is_boolean => 1 }
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue