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

(-)a/Koha/Item/Transfer.pm (+19 lines)
Lines 84-89 sub transit { Link Here
84
    return $self;
84
    return $self;
85
}
85
}
86
86
87
=head3 receive
88
89
Receive the transfer by setting the datearrived time.
90
91
=cut
92
93
sub receive {
94
    my ($self) = @_;
95
96
    # Throw exception if item is checked out
97
    Koha::Exceptions::Item::Transfer::Out->throw() if ($self->item->checkout);
98
99
    # Update the arrived date
100
    $self->set({ datearrived => dt_from_string })->store;
101
102
    ModDateLastSeen( $self->item->itemnumber );
103
    return $self;
104
}
105
87
=head3 type
106
=head3 type
88
107
89
=cut
108
=cut
(-)a/t/db_dependent/Koha/Item/Transfer.t (-2 / +58 lines)
Lines 23-29 use Koha::Database; Link Here
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
25
26
use Test::More tests => 2;
26
use Test::More tests => 3;
27
use Test::Exception;
27
use Test::Exception;
28
28
29
my $schema  = Koha::Database->new->schema;
29
my $schema  = Koha::Database->new->schema;
Lines 112-114 subtest 'transit tests' => sub { Link Here
112
112
113
    $schema->storage->txn_rollback;
113
    $schema->storage->txn_rollback;
114
};
114
};
115
- 
115
116
subtest 'receive tests' => sub {
117
    plan tests => 5;
118
119
    $schema->storage->txn_begin;
120
121
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
122
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
123
    my $item     = $builder->build_sample_item(
124
        {
125
            homebranch    => $library1->branchcode,
126
            holdingbranch => $library2->branchcode,
127
            datelastseen  => undef
128
        }
129
    );
130
131
    my $transfer = $builder->build_object(
132
        {
133
            class => 'Koha::Item::Transfers',
134
            value => {
135
                itemnumber   => $item->itemnumber,
136
                frombranch   => $library2->branchcode,
137
                tobranch     => $library1->branchcode,
138
                datearrived => undef,
139
                reason       => 'Manual'
140
            }
141
        }
142
    );
143
    is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
144
145
    # Item checked out should result in failure
146
    my $checkout = $builder->build_object(
147
        {
148
            class => 'Koha::Checkouts',
149
            value => {
150
                itemnumber => $item->itemnumber
151
            }
152
        }
153
    );
154
    is( ref($checkout), 'Koha::Checkout', 'Mock checkout added' );
155
156
    throws_ok { $transfer->receive() }
157
    'Koha::Exceptions::Item::Transfer::Out',
158
      'Exception thrown if item is checked out';
159
160
    $checkout->delete;
161
162
    # Transit state set
163
    $transfer->discard_changes;
164
    $transfer->receive();
165
    ok( $transfer->datearrived, 'Receipt set the datearrived for the transfer' );
166
167
    # Last seen
168
    ok( $item->datelastseen, 'Receipt set item datelastseen date' );
169
170
    $schema->storage->txn_rollback;
171
};

Return to bug 25767