View | Details | Raw Unified | Return to bug 25757
Collapse All | Expand All

(-)a/Koha/Exceptions/Item/Transfer.pm (+5 lines)
Lines 15-21 use Exception::Class ( Link Here
15
    'Koha::Exceptions::Item::Transfer::Limit' => {
15
    'Koha::Exceptions::Item::Transfer::Limit' => {
16
        isa => 'Koha::Exceptions::Item::Transfer',
16
        isa => 'Koha::Exceptions::Item::Transfer',
17
        description => "Transfer not allowed"
17
        description => "Transfer not allowed"
18
    },
19
    'Koha::Exceptions::Item::Transfer::Out' => {
20
        isa => 'Koha::Exceptions::Item::Transfer',
21
        description => "Transfer item is currently checked out"
18
    }
22
    }
23
19
);
24
);
20
25
21
1;
26
1;
(-)a/Koha/Item/Transfer.pm (+37 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Carp;
20
use Carp;
21
21
22
use C4::Items;
23
22
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils;
26
use Koha::Exceptions::Item::Transfer;
23
27
24
use base qw(Koha::Object);
28
use base qw(Koha::Object);
25
29
Lines 47-52 sub item { Link Here
47
    return Koha::Item->_new_from_dbic($item_rs);
51
    return Koha::Item->_new_from_dbic($item_rs);
48
}
52
}
49
53
54
=head3 transit
55
56
Set the transfer as in transit by updating the datesent time.
57
58
Also, update date last seen and ensure item holdingbranch is correctly set.
59
60
=cut
61
62
sub transit {
63
    my ($self) = @_;
64
65
    # Throw exception if item is still checked out
66
    Koha::Exceptions::Item::Transfer::Out->throw() if ( $self->item->checkout );
67
68
    # Remove the 'shelving cart' location status if it is being used (Bug 3701)
69
    CartToShelf( $self->item->itemnumber )
70
      if $self->item->location
71
      && $self->item->location eq 'CART'
72
      && (!$self->item->permanent_location
73
        || $self->item->permanent_location ne 'CART' );
74
75
    # Update the transit state
76
    $self->set(
77
        {
78
            frombranch => $self->item->holdingbranch,
79
            datesent   => dt_from_string,
80
        }
81
    )->store;
82
83
    ModDateLastSeen( $self->item->itemnumber );
84
    return $self;
85
}
86
50
=head3 type
87
=head3 type
51
88
52
=cut
89
=cut
(-)a/t/db_dependent/Koha/Item/Transfer.t (-1 / +92 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2020 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Koha::Database;
23
24
use t::lib::TestBuilder;
25
26
use Test::More tests => 1;
27
use Test::Exception;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'transit tests' => sub {
33
    plan tests => 7;
34
35
    $schema->storage->txn_begin;
36
37
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
38
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
39
    my $item     = $builder->build_sample_item(
40
        {
41
            homebranch    => $library1->branchcode,
42
            holdingbranch => $library2->branchcode,
43
            datelastseen  => undef
44
        }
45
    );
46
47
    my $transfer = $builder->build_object(
48
        {
49
            class => 'Koha::Item::Transfers',
50
            value => {
51
                itemnumber => $item->itemnumber,
52
                frombranch => $library2->branchcode,
53
                tobranch   => $library1->branchcode,
54
                reason     => 'Manual'
55
            }
56
        }
57
    );
58
    is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
59
60
    # Item checked out should result in failure
61
    my $checkout = $builder->build_object(
62
        {
63
            class => 'Koha::Checkouts',
64
            value => {
65
                itemnumber => $item->itemnumber
66
            }
67
        }
68
    );
69
    is( ref($checkout), 'Koha::Checkout', 'Mock checkout added' );
70
71
    throws_ok { $transfer->transit() }
72
    'Koha::Exceptions::Item::Transfer::Out',
73
      'Exception thrown if item is checked out';
74
75
    $checkout->delete;
76
77
    # CartToShelf test
78
    $item->set({ location => 'CART', permanent_location => 'TEST' })->store();
79
    is ( $item->location, 'CART', 'Item location set to CART');
80
    $transfer->discard_changes;
81
    $transfer->transit();
82
    $item->discard_changes;
83
    is ( $item->location, 'TEST', 'Item location correctly restored to match permanent location');
84
85
    # Transit state set
86
    ok( $transfer->datesent, 'Transit set the datesent for the transfer' );
87
88
    # Last seen
89
    ok ( $item->datelastseen, 'Transit set item datelastseen date');
90
91
    $schema->storage->txn_rollback;
92
};

Return to bug 25757