Bug 26481: Add Koha::Item::Transfer->in_transit method

This method returns a boolean representing the in_transit state of the
transfer.

Test plan
1/ Run the included tests

Signed-off-by: Kathleen Milne <kathleen.milne@cne-siar.gov.uk>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2020-12-18 16:35:44 +00:00 committed by Jonathan Druart
parent ca9ce62ee8
commit 6becadc96e
2 changed files with 51 additions and 1 deletions

View file

@ -82,6 +82,19 @@ sub transit {
ModDateLastSeen( $self->item->itemnumber );
return $self;
}
=head3 in_transit
Boolean returning whether the transfer is in transit or waiting
=cut
sub in_transit {
my ($self) = @_;
return ( defined( $self->datesent ) && !defined( $self->datearrived ) );
}
=head3 receive

View file

@ -20,10 +20,11 @@
use Modern::Perl;
use Koha::Database;
use Koha::DateUtils;
use t::lib::TestBuilder;
use Test::More tests => 3;
use Test::More tests => 4;
use Test::Exception;
my $schema = Koha::Database->new->schema;
@ -167,5 +168,41 @@ subtest 'receive tests' => sub {
# Last seen
ok( $item->datelastseen, 'Receipt set item datelastseen date' );
$schema->storage->txn_rollback;
};
subtest 'in_transit tests' => sub {
plan tests => 3;
$schema->storage->txn_begin;
my $library_from = $builder->build_object( { class => 'Koha::Libraries' } );
my $library_to = $builder->build_object( { class => 'Koha::Libraries' } );
my $item = $builder->build_sample_item(
{
homebranch => $library_to->branchcode,
holdingbranch => $library_from->branchcode,
}
);
my $transfer = Koha::Item::Transfer->new(
{
itemnumber => $item->itemnumber,
frombranch => $library_from->branchcode,
tobranch => $library_to->branchcode,
daterequested => dt_from_string,
}
)->store;
ok( !$transfer->in_transit, 'in_transit returns false when only daterequested is defined' );
$transfer->datesent(dt_from_string)->store;
ok( $transfer->in_transit, 'in_transit returns true when datesent is defined');
$transfer->datearrived(dt_from_string)->store;
ok( !$transfer->in_transit, 'in_transit returns false when datearrived is defined');
$schema->storage->txn_rollback;
};