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

(-)a/Koha/Exceptions/Item/Transfer.pm (-1 / +4 lines)
Lines 19-26 use Exception::Class ( Link Here
19
    'Koha::Exceptions::Item::Transfer::Out' => {
19
    'Koha::Exceptions::Item::Transfer::Out' => {
20
        isa => 'Koha::Exceptions::Item::Transfer',
20
        isa => 'Koha::Exceptions::Item::Transfer',
21
        description => "Transfer item is currently checked out"
21
        description => "Transfer item is currently checked out"
22
    },
23
    'Koha::Exceptions::Item::Transfer::Transit' => {
24
        isa => 'Koha::Exceptions::Item::Transfer',
25
        description => "Transfer item is currently in transit"
22
    }
26
    }
23
24
);
27
);
25
28
26
1;
29
1;
(-)a/Koha/Item.pm (-3 / +7 lines)
Lines 467-476 if it exists, otherwise the oldest unsatisfied transfer will be returned. Link Here
467
sub get_transfer {
467
sub get_transfer {
468
    my ($self) = @_;
468
    my ($self) = @_;
469
    my $transfer_rs = $self->_result->branchtransfers->search(
469
    my $transfer_rs = $self->_result->branchtransfers->search(
470
        { datearrived => undef },
471
        {
470
        {
472
            order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ],
471
            datearrived   => undef,
473
            rows     => 1
472
            datecancelled => undef
473
        },
474
        {
475
            order_by =>
476
              [ { -desc => 'datesent' }, { -asc => 'daterequested' } ],
477
            rows => 1
474
        }
478
        }
475
    )->first;
479
    )->first;
476
    return unless $transfer_rs;
480
    return unless $transfer_rs;
(-)a/Koha/Item/Transfer.pm (+18 lines)
Lines 116-121 sub receive { Link Here
116
    return $self;
116
    return $self;
117
}
117
}
118
118
119
=head3 cancel
120
121
Cancel the transfer by setting the datecancelled time.
122
123
=cut
124
125
sub cancel {
126
    my ($self) = @_;
127
128
    # Throw exception if item is in transit already
129
    Koha::Exceptions::Item::Transfer::Transit->throw() if ( $self->in_transit );
130
131
    # Update the cancelled date
132
    $self->set( { datecancelled => dt_from_string } )->store;
133
134
    return $self;
135
}
136
119
=head3 type
137
=head3 type
120
138
121
=cut
139
=cut
(-)a/t/db_dependent/Koha/Item/Transfer.t (-1 / +50 lines)
Lines 24-30 use Koha::DateUtils; Link Here
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
26
26
27
use Test::More tests => 4;
27
use Test::More tests => 5;
28
use Test::Exception;
28
use Test::Exception;
29
29
30
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
Lines 204-208 subtest 'in_transit tests' => sub { Link Here
204
    ok( !$transfer->in_transit, 'in_transit returns false when datearrived is defined');
204
    ok( !$transfer->in_transit, 'in_transit returns false when datearrived is defined');
205
205
206
206
207
    $schema->storage->txn_rollback;
208
};
209
210
subtest 'cancel tests' => sub {
211
    plan tests => 4;
212
213
    $schema->storage->txn_begin;
214
215
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
216
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
217
    my $item     = $builder->build_sample_item(
218
        {
219
            homebranch    => $library1->branchcode,
220
            holdingbranch => $library2->branchcode,
221
            datelastseen  => undef
222
        }
223
    );
224
225
    my $transfer = $builder->build_object(
226
        {
227
            class => 'Koha::Item::Transfers',
228
            value => {
229
                itemnumber    => $item->itemnumber,
230
                frombranch    => $library2->branchcode,
231
                tobranch      => $library1->branchcode,
232
                datesent      => \'NOW()',
233
                datearrived   => undef,
234
                datecancelled => undef,
235
                reason        => 'Manual'
236
            }
237
        }
238
    );
239
    is( ref($transfer), 'Koha::Item::Transfer', 'Mock transfer added' );
240
241
    # Item in transit should result in failure
242
    throws_ok { $transfer->cancel() }
243
    'Koha::Exceptions::Item::Transfer::Transit',
244
      'Exception thrown if item is in transit';
245
246
    $transfer->datesent(undef)->store();
247
248
    # Transit state set
249
    $transfer->discard_changes;
250
    $transfer->cancel();
251
    ok( $transfer->datecancelled, 'Cancellation date set upon call to cancel' );
252
253
    # Last seen
254
    is( $transfer->reason, 'Manual', 'Reason is not updated by cancelling the transfer' );
255
207
    $schema->storage->txn_rollback;
256
    $schema->storage->txn_rollback;
208
};
257
};
(-)a/t/db_dependent/Koha/Items.t (-14 / +20 lines)
Lines 811-817 subtest 'store' => sub { Link Here
811
};
811
};
812
812
813
subtest 'get_transfer' => sub {
813
subtest 'get_transfer' => sub {
814
    plan tests => 6;
814
    plan tests => 7;
815
815
816
    my $transfer = $new_item_1->get_transfer();
816
    my $transfer = $new_item_1->get_transfer();
817
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' );
817
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' );
Lines 828-833 subtest 'get_transfer' => sub { Link Here
828
                reason        => 'Manual',
828
                reason        => 'Manual',
829
                datesent      => undef,
829
                datesent      => undef,
830
                datearrived   => undef,
830
                datearrived   => undef,
831
                datecancelled => undef,
831
                daterequested => \'NOW()'
832
                daterequested => \'NOW()'
832
            }
833
            }
833
        }
834
        }
Lines 840-851 subtest 'get_transfer' => sub { Link Here
840
        {
841
        {
841
            class => 'Koha::Item::Transfers',
842
            class => 'Koha::Item::Transfers',
842
            value => {
843
            value => {
843
                itemnumber  => $new_item_1->itemnumber,
844
                itemnumber    => $new_item_1->itemnumber,
844
                frombranch  => $new_item_1->holdingbranch,
845
                frombranch    => $new_item_1->holdingbranch,
845
                tobranch    => $library_to->{branchcode},
846
                tobranch      => $library_to->{branchcode},
846
                reason      => 'Manual',
847
                reason        => 'Manual',
847
                datesent    => undef,
848
                datesent      => undef,
848
                datearrived => undef,
849
                datearrived   => undef,
850
                datecancelled => undef,
849
                daterequested => \'NOW()'
851
                daterequested => \'NOW()'
850
            }
852
            }
851
        }
853
        }
Lines 862-873 subtest 'get_transfer' => sub { Link Here
862
        {
864
        {
863
            class => 'Koha::Item::Transfers',
865
            class => 'Koha::Item::Transfers',
864
            value => {
866
            value => {
865
                itemnumber  => $new_item_1->itemnumber,
867
                itemnumber    => $new_item_1->itemnumber,
866
                frombranch  => $new_item_1->holdingbranch,
868
                frombranch    => $new_item_1->holdingbranch,
867
                tobranch    => $library_to->{branchcode},
869
                tobranch      => $library_to->{branchcode},
868
                reason      => 'Manual',
870
                reason        => 'Manual',
869
                datesent    => undef,
871
                datesent      => undef,
870
                datearrived => undef,
872
                datearrived   => undef,
873
                datecancelled => undef,
871
                daterequested => \'NOW()'
874
                daterequested => \'NOW()'
872
            }
875
            }
873
        }
876
        }
Lines 877-882 subtest 'get_transfer' => sub { Link Here
877
    $transfer = $new_item_1->get_transfer();
880
    $transfer = $new_item_1->get_transfer();
878
    is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the next queued transfer');
881
    is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the next queued transfer');
879
    is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
882
    is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
883
884
    $transfer_1->datecancelled(\'NOW()')->store;
885
    $transfer = $new_item_1->get_transfer();
886
    is( $transfer->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfer ignores cancelled transfers');
880
};
887
};
881
888
882
subtest 'holds' => sub {
889
subtest 'holds' => sub {
883
- 

Return to bug 26057