Bug 35994: Add $biblio->acq_status
This allows you to see quickly if a biblio has linked orders or not. And if they are all cancelled, or some still in processing, or some are complete (and the rest cancelled). Test plan: Run t/db_dependent/Koha/Biblio.t Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Emily Lamancusa <emily.lamancusa@montgomerycountymd.gov> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
dbc7a74427
commit
9f8186eaa1
2 changed files with 45 additions and 6 deletions
|
@ -158,6 +158,32 @@ sub uncancelled_orders {
|
|||
return $self->orders->filter_out_cancelled;
|
||||
}
|
||||
|
||||
=head3 acq_status
|
||||
|
||||
print $biblio->acq_status;
|
||||
|
||||
This status can be:
|
||||
- unlinked: not any linked order found in the system
|
||||
- acquired: some lines are complete, rest is cancelled
|
||||
- cancelled: all lines are cancelled
|
||||
- processing: some lines are active or new
|
||||
|
||||
=cut
|
||||
|
||||
sub acq_status {
|
||||
my ($self) = @_;
|
||||
my $orders = $self->orders;
|
||||
unless ( $orders->count ) {
|
||||
return 'unlinked';
|
||||
} elsif ( !$self->uncancelled_orders->count ) {
|
||||
return 'cancelled';
|
||||
} elsif ( $orders->search( { orderstatus => [ 'new', 'ordered', 'partial' ] } )->count ) {
|
||||
return 'processing';
|
||||
} else {
|
||||
return 'acquired'; # some lines must be complete here
|
||||
}
|
||||
}
|
||||
|
||||
=head3 tickets
|
||||
|
||||
my $tickets = $biblio->tickets();
|
||||
|
|
|
@ -942,9 +942,9 @@ subtest 'get_volumes_query' => sub {
|
|||
);
|
||||
};
|
||||
|
||||
subtest 'orders() and uncancelled_orders() tests' => sub {
|
||||
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub {
|
||||
|
||||
plan tests => 5;
|
||||
plan tests => 9;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
|
@ -965,8 +965,9 @@ subtest 'orders() and uncancelled_orders() tests' => sub {
|
|||
{
|
||||
class => 'Koha::Acquisition::Orders',
|
||||
value => {
|
||||
biblionumber => $biblio->biblionumber,
|
||||
datecancellationprinted => '2019-12-31'
|
||||
biblionumber => $biblio->biblionumber,
|
||||
datecancellationprinted => '2019-12-31',
|
||||
orderstatus => 'cancelled',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -976,8 +977,11 @@ subtest 'orders() and uncancelled_orders() tests' => sub {
|
|||
{
|
||||
class => 'Koha::Acquisition::Orders',
|
||||
value => {
|
||||
biblionumber => $biblio->biblionumber,
|
||||
datecancellationprinted => undef
|
||||
biblionumber => $biblio->biblionumber,
|
||||
datecancellationprinted => undef,
|
||||
orderstatus => 'ordered',
|
||||
quantity => 1,
|
||||
quantityreceived => 0,
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -989,6 +993,15 @@ subtest 'orders() and uncancelled_orders() tests' => sub {
|
|||
is( ref($uncancelled_orders), 'Koha::Acquisition::Orders', 'Result type is correct' );
|
||||
is( $orders->count, $uncancelled_orders->count + 2, '->uncancelled_orders->count returns the right count' );
|
||||
|
||||
# Check acq status
|
||||
is( $biblio->acq_status, 'processing', 'Processing for presence of ordered lines' );
|
||||
$orders->filter_by_active->update( { orderstatus => 'new' } );
|
||||
is( $biblio->acq_status, 'processing', 'Still processing for presence of new lines' );
|
||||
$orders->filter_out_cancelled->update( { orderstatus => 'complete' } );
|
||||
is( $biblio->acq_status, 'acquired', 'Acquired: some complete, rest cancelled' );
|
||||
$orders->cancel;
|
||||
is( $biblio->acq_status, 'cancelled', 'Cancelled for only cancelled lines' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue