Bug 25767: Add Koha::Item::Transfer->receive method
Was Bug 25767: Add Koha::Item::Transfer->receipt method 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> Bug 25767: Add unit tests for Koha::Item::Transfer->receipt 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> Bug 25767: (QA follow-up) receipt -> receive 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:
parent
62e16bbbe4
commit
ca9ce62ee8
|
|
@ -84,6 +84,25 @@ sub transit {
|
|||
return $self;
|
||||
}
|
||||
|
||||
=head3 receive
|
||||
|
||||
Receive the transfer by setting the datearrived time.
|
||||
|
||||
=cut
|
||||
|
||||
sub receive {
|
||||
my ($self) = @_;
|
||||
|
||||
# Throw exception if item is checked out
|
||||
Koha::Exceptions::Item::Transfer::Out->throw() if ($self->item->checkout);
|
||||
|
||||
# Update the arrived date
|
||||
$self->set({ datearrived => dt_from_string })->store;
|
||||
|
||||
ModDateLastSeen( $self->item->itemnumber );
|
||||
return $self;
|
||||
}
|
||||
|
||||
=head3 type
|
||||
|
||||
=cut
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use Koha::Database;
|
|||
|
||||
use t::lib::TestBuilder;
|
||||
|
||||
use Test::More tests => 2;
|
||||
use Test::More tests => 3;
|
||||
use Test::Exception;
|
||||
|
||||
my $schema = Koha::Database->new->schema;
|
||||
|
|
@ -112,3 +112,60 @@ subtest 'transit tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'receive tests' => sub {
|
||||
plan tests => 5;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
my $item = $builder->build_sample_item(
|
||||
{
|
||||
homebranch => $library1->branchcode,
|
||||
holdingbranch => $library2->branchcode,
|
||||
datelastseen => undef
|
||||
}
|
||||
);
|
||||
|
||||
my $transfer = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Item::Transfers',
|
||||
value => {
|
||||
itemnumber => $item->itemnumber,
|
||||
frombranch => $library2->branchcode,
|
||||
tobranch => $library1->branchcode,
|
||||
datearrived => undef,
|
||||
reason => 'Manual'
|
||||
}
|
||||
}
|
||||
);
|
||||
is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
|
||||
|
||||
# Item checked out should result in failure
|
||||
my $checkout = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Checkouts',
|
||||
value => {
|
||||
itemnumber => $item->itemnumber
|
||||
}
|
||||
}
|
||||
);
|
||||
is( ref($checkout), 'Koha::Checkout', 'Mock checkout added' );
|
||||
|
||||
throws_ok { $transfer->receive() }
|
||||
'Koha::Exceptions::Item::Transfer::Out',
|
||||
'Exception thrown if item is checked out';
|
||||
|
||||
$checkout->delete;
|
||||
|
||||
# Transit state set
|
||||
$transfer->discard_changes;
|
||||
$transfer->receive();
|
||||
ok( $transfer->datearrived, 'Receipt set the datearrived for the transfer' );
|
||||
|
||||
# Last seen
|
||||
ok( $item->datelastseen, 'Receipt set item datelastseen date' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue