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

(-)a/C4/Circulation.pm (-6 / +6 lines)
Lines 2380-2389 sub AddReturn { Link Here
2380
            else {
2380
            else {
2381
                $messages->{'TransferTrigger'} = $transfer->reason;
2381
                $messages->{'TransferTrigger'} = $transfer->reason;
2382
                if ( $transfer->frombranch eq $branch ) {
2382
                if ( $transfer->frombranch eq $branch ) {
2383
                    $transfer->transit;
2383
                    $messages->{'TransferTo'}    = $transfer->tobranch;
2384
                    $messages->{'WasTransfered'}   = $transfer->tobranch;
2384
                    $messages->{'WasTransfered'} = $transfer->id;
2385
                }
2385
                } else {
2386
                else {
2387
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2386
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2388
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2387
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2389
                }
2388
                }
Lines 2537-2544 sub AddReturn { Link Here
2537
            (C4::Context->preference("UseBranchTransferLimits") and
2536
            (C4::Context->preference("UseBranchTransferLimits") and
2538
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2537
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2539
           )) {
2538
           )) {
2540
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2539
            my $transfer = ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2541
            $messages->{'WasTransfered'} = $returnbranch;
2540
            $messages->{'TransferTo'} = $returnbranch;
2541
            $messages->{'WasTransfered'} = $transfer->id;
2542
            $messages->{'TransferTrigger'} = $transfer_trigger;
2542
            $messages->{'TransferTrigger'} = $transfer_trigger;
2543
        } else {
2543
        } else {
2544
            $messages->{'NeedsTransfer'} = $returnbranch;
2544
            $messages->{'NeedsTransfer'} = $returnbranch;
(-)a/C4/Items.pm (-1 / +1 lines)
Lines 386-392 sub ModItemTransfer { Link Here
386
        $transfer->transit({ skip_record_index => $params->{skip_record_index} });
386
        $transfer->transit({ skip_record_index => $params->{skip_record_index} });
387
    }
387
    }
388
388
389
    return;
389
    return $transfer;
390
}
390
}
391
391
392
=head2 ModDateLastSeen
392
=head2 ModDateLastSeen
(-)a/Koha/Item.pm (-4 / +11 lines)
Lines 776-784 we still expect the item to end up at a final location eventually. Link Here
776
776
777
sub get_transfer {
777
sub get_transfer {
778
    my ($self) = @_;
778
    my ($self) = @_;
779
    my $transfers = $self->_result->current_branchtransfers->search(
780
        undef,
781
        { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] }
782
    );
779
783
780
    my $transfer = $self->_result->current_branchtransfers->next;
784
    my $transfer = $transfers->next;
781
    return  Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer;
785
    return Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer;
782
}
786
}
783
787
784
=head3 get_transfers
788
=head3 get_transfers
Lines 801-809 we still expect the item to end up at a final location eventually. Link Here
801
sub get_transfers {
805
sub get_transfers {
802
    my ($self) = @_;
806
    my ($self) = @_;
803
807
804
    my $transfer_rs = $self->_result->current_branchtransfers;
808
    my $transfers_rs = $self->_result->current_branchtransfers->search(
809
        undef,
810
        { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] }
811
    );
805
812
806
    return Koha::Item::Transfers->_new_from_dbic($transfer_rs);
813
    return Koha::Item::Transfers->_new_from_dbic($transfers_rs);
807
}
814
}
808
815
809
=head3 last_returned_by
816
=head3 last_returned_by
(-)a/Koha/Schema/Result/Item.pm (-2 / +1 lines)
Lines 1024-1031 __PACKAGE__->has_many( Link Here
1024
            "$args->{foreign_alias}.datearrived"   => undef,
1024
            "$args->{foreign_alias}.datearrived"   => undef,
1025
            "$args->{foreign_alias}.datecancelled" => undef,
1025
            "$args->{foreign_alias}.datecancelled" => undef,
1026
        };
1026
        };
1027
    },
1027
    }
1028
    { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] }
1029
);
1028
);
1030
1029
1031
# Relationship with bundled items
1030
# Relationship with bundled items
(-)a/catalogue/detail.pl (-1 / +2 lines)
Lines 196-202 $params->{ itemlost } = 0 if $patron->category->hidelostitems && !$showallitems; Link Here
196
my $items_params = {
196
my $items_params = {
197
    ( $invalid_marc_record ? () : ( host_items => 1 ) ),
197
    ( $invalid_marc_record ? () : ( host_items => 1 ) ),
198
};
198
};
199
my $items = $biblio->items($items_params)->search_ordered( $params, { prefetch => ['issue','current_branchtransfers'] } );
199
my $items =
200
    $biblio->items($items_params)->search_ordered( $params, { prefetch => [ 'issue', 'current_branchtransfers' ] } );
200
201
201
# flag indicating existence of at least one item linked via a host record
202
# flag indicating existence of at least one item linked via a host record
202
my $hostrecords = $biblio->host_items->count;
203
my $hostrecords = $biblio->host_items->count;
(-)a/circ/returns.pl (-4 / +8 lines)
Lines 520-529 my $recalled = 0; Link Here
520
520
521
if ( $messages->{'WasTransfered'} ) {
521
if ( $messages->{'WasTransfered'} ) {
522
    $template->param(
522
    $template->param(
523
        found          => 1,
523
        found      => 1,
524
        transfer       => $messages->{'WasTransfered'},
524
        transfer   => $messages->{'WasTransfered'},
525
        trigger        => $messages->{'TransferTrigger'},
525
        transferto => $messages->{'TransferTo'},
526
        itemnumber     => $itemnumber,
526
        trigger    => $messages->{'TransferTrigger'},
527
        itemnumber => $itemnumber,
527
    );
528
    );
528
}
529
}
529
530
Lines 697-702 foreach my $code ( keys %$messages ) { Link Here
697
    elsif ( $code eq 'WasTransfered' ) {
698
    elsif ( $code eq 'WasTransfered' ) {
698
        ;    # FIXME... anything to do here?
699
        ;    # FIXME... anything to do here?
699
    }
700
    }
701
    elsif ( $code eq 'TransferTo' ) {
702
        ;    # Handled above, along with WasTransfered
703
    }
700
    elsif ( $code eq 'withdrawn' ) {
704
    elsif ( $code eq 'withdrawn' ) {
701
        $err{withdrawn} = 1;
705
        $err{withdrawn} = 1;
702
    }
706
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (-2 / +3 lines)
Lines 122-128 Link Here
122
                                </div> <!-- /.hold-auto-filled -->
122
                                </div> <!-- /.hold-auto-filled -->
123
                            [% END # /IF hold_auto_filled %]
123
                            [% END # /IF hold_auto_filled %]
124
124
125
                            [% IF ( trigger ) %]
125
                            [% IF ( trigger && !transfertodo ) %]
126
                                 <div id="transfer-trigger" class="dialog message">
126
                                 <div id="transfer-trigger" class="dialog message">
127
                                     <h3>Reason for transfer</h3>
127
                                     <h3>Reason for transfer</h3>
128
                                     <p>
128
                                     <p>
Lines 745-751 Link Here
745
745
746
                                                <div class="modal-header">
746
                                                <div class="modal-header">
747
                                                    <h3>
747
                                                    <h3>
748
                                                        Please return this item to [% IF transfer %][% Branches.GetName( transfer ) | html %][% ELSE %][% Branches.GetName( returnbranch ) | html %][% END %]
748
                                                        Please return this item to [% IF transferto %][% Branches.GetName( transferto ) | html %][% ELSE %][% Branches.GetName( returnbranch ) | html %][% END %]
749
                                                    </h3>
749
                                                    </h3>
750
                                                </div>
750
                                                </div>
751
                                                <div class="modal-body">
751
                                                <div class="modal-body">
Lines 772-777 Link Here
772
                                                        <button type="button" name="dotransfer" class="btn btn-default print openWin" data-url="transfer-slip.pl?transferitem=[% itemnumber | uri %]&amp;&amp;branchcode=[% returnbranch | uri %]&amp;op=slip"><i class="fa fa-print"></i> Yes, print slip</button>
772
                                                        <button type="button" name="dotransfer" class="btn btn-default print openWin" data-url="transfer-slip.pl?transferitem=[% itemnumber | uri %]&amp;&amp;branchcode=[% returnbranch | uri %]&amp;op=slip"><i class="fa fa-print"></i> Yes, print slip</button>
773
                                                        <button type="button" data-dismiss="modal" class="btn btn-default deny" name="notransfer" value="No" accesskey="n"><i class="fa fa-times"></i> No (N)</button>
773
                                                        <button type="button" data-dismiss="modal" class="btn btn-default deny" name="notransfer" value="No" accesskey="n"><i class="fa fa-times"></i> No (N)</button>
774
                                                    [% ELSE %]
774
                                                    [% ELSE %]
775
                                                        <input type="hidden" name="transit" value="[% transfer | uri %]"/>
775
                                                        <button type="button" data-dismiss="modal" class="btn btn-default" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
776
                                                        <button type="button" data-dismiss="modal" class="btn btn-default" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
776
                                                        <button type="button" data-dismiss="modal" class="btn btn-default openWin" data-url="transfer-slip.pl?transferitem=[% itemnumber | uri %]&amp;branchcode=[% transfer | uri %]&amp;op=slip" accesskey="p"><i class="fa fa-print"></i> Print slip (P)</button>
777
                                                        <button type="button" data-dismiss="modal" class="btn btn-default openWin" data-url="transfer-slip.pl?transferitem=[% itemnumber | uri %]&amp;branchcode=[% transfer | uri %]&amp;op=slip" accesskey="p"><i class="fa fa-print"></i> Print slip (P)</button>
777
                                                    [% END %]
778
                                                    [% END %]
(-)a/t/db_dependent/Circulation.t (-11 / +24 lines)
Lines 6093-6117 subtest 'Tests for transfer not in transit' => sub { Link Here
6093
6093
6094
    plan tests => 2;
6094
    plan tests => 2;
6095
6095
6096
6097
    # These tests are to ensure a 'pending' transfer, generated by
6096
    # These tests are to ensure a 'pending' transfer, generated by
6098
    # stock rotation, will be advanced when checked in
6097
    # stock rotation, will be advanced when checked in
6099
6098
6100
    my $item = $builder->build_sample_item();
6099
    my $item     = $builder->build_sample_item();
6101
    my $transfer = $builder->build_object({ class => 'Koha::Item::Transfers', value => {
6100
    my $transfer = $builder->build_object(
6102
        itemnumber => $item->id,
6101
        {
6103
        reason => 'StockrotationRepatriation',
6102
            class => 'Koha::Item::Transfers',
6104
        datesent => undef,
6103
            value => {
6105
        frombranch => $item->homebranch,
6104
                itemnumber => $item->id,
6106
    }});
6105
                reason     => 'StockrotationRepatriation',
6106
                datesent   => undef,
6107
                frombranch => $item->homebranch,
6108
            }
6109
        }
6110
    );
6107
    my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef );
6111
    my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef );
6108
    is_deeply(
6112
    is_deeply(
6109
        \@return,
6113
        \@return,
6110
        [ 0, { WasTransfered => $transfer->tobranch, TransferTrigger => 'StockrotationRepatriation', NotIssued => $item->barcode }, undef, {} ], "Item is reported to have been transferred");
6114
        [
6115
            0,
6116
            {
6117
                TransferTo      => $transfer->tobranch,         WasTransfered => $transfer->id,
6118
                TransferTrigger => 'StockrotationRepatriation', NotIssued     => $item->barcode
6119
            },
6120
            undef,
6121
            {}
6122
        ],
6123
        "Item is reported to have been transferred"
6124
    );
6111
6125
6112
    $transfer->discard_changes;
6126
    $transfer->discard_changes;
6113
    ok( $transfer->datesent, 'The datesent field is populated, i.e. transfer is initiated');
6127
    is( $transfer->datesent, undef, 'The datesent field remains unpopulated, i.e. transfer is not yet initiated' );
6114
6115
};
6128
};
6116
6129
6117
subtest 'Tests for RecordLocalUseOnReturn' => sub {
6130
subtest 'Tests for RecordLocalUseOnReturn' => sub {
(-)a/t/db_dependent/Koha/Item.t (-2 / +249 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use utf8;
21
use utf8;
22
22
23
use Test::More tests => 31;
23
use Test::More tests => 32;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
26
Lines 1100-1107 subtest 'Tests for itemtype' => sub { Link Here
1100
    $schema->storage->txn_rollback;
1100
    $schema->storage->txn_rollback;
1101
};
1101
};
1102
1102
1103
subtest 'get_transfer' => sub {
1104
    plan tests => 8;
1105
    $schema->storage->txn_begin;
1106
1107
    my $item = $builder->build_sample_item();
1108
1109
    my $transfer = $item->get_transfer();
1110
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item has no queued transfers' );
1111
1112
    my $library_to = $builder->build( { source => 'Branch' } );
1113
1114
    my $transfer_1 = $builder->build_object(
1115
        {
1116
            class => 'Koha::Item::Transfers',
1117
            value => {
1118
                itemnumber    => $item->itemnumber,
1119
                frombranch    => $item->holdingbranch,
1120
                tobranch      => $library_to->{branchcode},
1121
                reason        => 'Manual',
1122
                datesent      => undef,
1123
                datearrived   => undef,
1124
                datecancelled => undef,
1125
                daterequested => \'NOW()'
1126
            }
1127
        }
1128
    );
1129
1130
    $transfer = $item->get_transfer();
1131
    is(
1132
        ref($transfer), 'Koha::Item::Transfer',
1133
        'Koha::Item->get_transfer should return a Koha::Item::Transfer object'
1134
    );
1135
1136
    my $transfer_2 = $builder->build_object(
1137
        {
1138
            class => 'Koha::Item::Transfers',
1139
            value => {
1140
                itemnumber    => $item->itemnumber,
1141
                frombranch    => $item->holdingbranch,
1142
                tobranch      => $library_to->{branchcode},
1143
                reason        => 'Manual',
1144
                datesent      => undef,
1145
                datearrived   => undef,
1146
                datecancelled => undef,
1147
                daterequested => \'NOW()'
1148
            }
1149
        }
1150
    );
1151
1152
    $transfer = $item->get_transfer();
1153
    is(
1154
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1155
        'Koha::Item->get_transfer returns the oldest transfer request'
1156
    );
1157
1158
    $transfer_2->datesent( \'NOW()' )->store;
1159
    $transfer = $item->get_transfer();
1160
    is(
1161
        $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1162
        'Koha::Item->get_transfer returns the in_transit transfer'
1163
    );
1164
1165
    my $transfer_3 = $builder->build_object(
1166
        {
1167
            class => 'Koha::Item::Transfers',
1168
            value => {
1169
                itemnumber    => $item->itemnumber,
1170
                frombranch    => $item->holdingbranch,
1171
                tobranch      => $library_to->{branchcode},
1172
                reason        => 'Manual',
1173
                datesent      => undef,
1174
                datearrived   => undef,
1175
                datecancelled => undef,
1176
                daterequested => \'NOW()'
1177
            }
1178
        }
1179
    );
1180
1181
    $transfer_2->datearrived( \'NOW()' )->store;
1182
    $transfer = $item->get_transfer();
1183
    is(
1184
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1185
        'Koha::Item->get_transfer returns the next queued transfer'
1186
    );
1187
    is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1188
1189
    $transfer_1->datecancelled( \'NOW()' )->store;
1190
    $transfer = $item->get_transfer();
1191
    is(
1192
        $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1193
        'Koha::Item->get_transfer ignores cancelled transfers'
1194
    );
1195
1196
    subtest "Ensure prefetches don't affect which transfer if returned" => sub {
1197
        plan tests => 5;
1198
1199
        # Reset test data
1200
        $transfer_1->datecancelled(undef)->store;
1201
        $transfer_2->set( { datesent => undef, datearrived => undef } )->store;
1202
1203
        my $prefetched_item = Koha::Items->search(
1204
            { 'me.itemnumber' => $item->itemnumber },
1205
            { prefetch        => ['current_branchtransfers'] }
1206
        )->next;
1207
1208
        $transfer = $prefetched_item->get_transfer();
1209
        is(
1210
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1211
            'Koha::Item->get_transfer returns the oldest transfer request'
1212
        );
1213
1214
        $transfer_2->datesent( \'NOW()' )->store;
1215
        $prefetched_item = Koha::Items->search(
1216
            { 'me.itemnumber' => $item->itemnumber },
1217
            { prefetch        => ['current_branchtransfers'] }
1218
        )->next;
1219
1220
        $transfer = $prefetched_item->get_transfer();
1221
        is(
1222
            $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1223
            'Koha::Item->get_transfer returns the in_transit transfer'
1224
        );
1225
1226
        $transfer_2->datearrived( \'NOW()' )->store;
1227
        $prefetched_item = Koha::Items->search(
1228
            { 'me.itemnumber' => $item->itemnumber },
1229
            { prefetch        => ['current_branchtransfers'] }
1230
        )->next;
1231
        $transfer = $prefetched_item->get_transfer();
1232
        is(
1233
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1234
            'Koha::Item->get_transfer returns the next queued transfer'
1235
        );
1236
        is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1237
1238
        $transfer_1->datecancelled( \'NOW()' )->store;
1239
        $prefetched_item = Koha::Items->search(
1240
            { 'me.itemnumber' => $item->itemnumber },
1241
            { prefetch        => ['current_branchtransfers'] }
1242
        )->next;
1243
        $transfer = $prefetched_item->get_transfer();
1244
        is(
1245
            $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1246
            'Koha::Item->get_transfer ignores cancelled transfers'
1247
        );
1248
    };
1249
    $schema->storage->txn_rollback;
1250
};
1251
1103
subtest 'get_transfers' => sub {
1252
subtest 'get_transfers' => sub {
1104
    plan tests => 16;
1253
    plan tests => 17;
1105
    $schema->storage->txn_begin;
1254
    $schema->storage->txn_begin;
1106
1255
1107
    my $item = $builder->build_sample_item();
1256
    my $item = $builder->build_sample_item();
Lines 1196-1201 subtest 'get_transfers' => sub { Link Here
1196
    $result_1 = $transfers->next;
1345
    $result_1 = $transfers->next;
1197
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1346
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1198
1347
1348
    subtest "Ensure prefetches don't affect the return order" => sub {
1349
        plan tests => 13;
1350
1351
        # Reset test data
1352
        $transfer_2->datesent(undef)->store;
1353
        $transfer_2->datearrived(undef)->store;
1354
        $transfer_1->datecancelled(undef)->store;
1355
1356
        my $prefetched_item = Koha::Items->search(
1357
            { 'me.itemnumber' => $item->itemnumber },
1358
            { prefetch        => ['current_branchtransfers'] }
1359
        )->next;
1360
1361
        $transfers = $prefetched_item->get_transfers();
1362
        is(
1363
            $transfers->count, 3,
1364
            'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all'
1365
        );
1366
        $result_1 = $transfers->next;
1367
        $result_2 = $transfers->next;
1368
        $result_3 = $transfers->next;
1369
        is(
1370
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1371
            'Koha::Item->get_transfers returns the oldest transfer request first'
1372
        );
1373
        is(
1374
            $result_2->branchtransfer_id, $transfer_2->branchtransfer_id,
1375
            'Koha::Item->get_transfers returns the newer transfer request second'
1376
        );
1377
        is(
1378
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1379
            'Koha::Item->get_transfers returns the newest transfer request last'
1380
        );
1381
1382
        $transfer_2->datesent( \'NOW()' )->store;
1383
        $prefetched_item = Koha::Items->search(
1384
            { 'me.itemnumber' => $item->itemnumber },
1385
            { prefetch        => ['current_branchtransfers'] }
1386
        )->next;
1387
        $transfers = $prefetched_item->get_transfers();
1388
        is(
1389
            $transfers->count, 3,
1390
            'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all'
1391
        );
1392
        $result_1 = $transfers->next;
1393
        $result_2 = $transfers->next;
1394
        $result_3 = $transfers->next;
1395
        is(
1396
            $result_1->branchtransfer_id, $transfer_2->branchtransfer_id,
1397
            'Koha::Item->get_transfers returns the active transfer request first'
1398
        );
1399
        is(
1400
            $result_2->branchtransfer_id, $transfer_1->branchtransfer_id,
1401
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1402
        );
1403
        is(
1404
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1405
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1406
        );
1407
1408
        $transfer_2->datearrived( \'NOW()' )->store;
1409
        $prefetched_item = Koha::Items->search(
1410
            { 'me.itemnumber' => $item->itemnumber },
1411
            { prefetch        => ['current_branchtransfers'] }
1412
        )->next;
1413
        $transfers = $prefetched_item->get_transfers();
1414
        is(
1415
            $transfers->count, 2,
1416
            'Once a transfer is received, it no longer appears in the list from ->get_transfers()'
1417
        );
1418
        $result_1 = $transfers->next;
1419
        $result_2 = $transfers->next;
1420
        is(
1421
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1422
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1423
        );
1424
        is(
1425
            $result_2->branchtransfer_id, $transfer_3->branchtransfer_id,
1426
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1427
        );
1428
1429
        $transfer_1->datecancelled( \'NOW()' )->store;
1430
        $prefetched_item = Koha::Items->search(
1431
            { 'me.itemnumber' => $item->itemnumber },
1432
            { prefetch        => ['current_branchtransfers'] }
1433
        )->next;
1434
        $transfers = $prefetched_item->get_transfers();
1435
        is(
1436
            $transfers->count, 1,
1437
            'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()'
1438
        );
1439
        $result_1 = $transfers->next;
1440
        is(
1441
            $result_1->branchtransfer_id, $transfer_3->branchtransfer_id,
1442
            'Koha::Item->get_transfers returns the only transfer that remains'
1443
        );
1444
    };
1445
1199
    $schema->storage->txn_rollback;
1446
    $schema->storage->txn_rollback;
1200
};
1447
};
1201
1448
(-)a/t/db_dependent/Koha/Items.t (-78 / +1 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 16;
22
use Test::More tests => 15;
23
23
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Exception;
25
use Test::Exception;
Lines 1382-1463 subtest 'store' => sub { Link Here
1382
    };
1382
    };
1383
};
1383
};
1384
1384
1385
subtest 'get_transfer' => sub {
1386
    plan tests => 7;
1387
1388
    my $transfer = $new_item_1->get_transfer();
1389
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' );
1390
1391
    my $library_to = $builder->build( { source => 'Branch' } );
1392
1393
    my $transfer_1 = $builder->build_object(
1394
        {
1395
            class => 'Koha::Item::Transfers',
1396
            value => {
1397
                itemnumber    => $new_item_1->itemnumber,
1398
                frombranch    => $new_item_1->holdingbranch,
1399
                tobranch      => $library_to->{branchcode},
1400
                reason        => 'Manual',
1401
                datesent      => undef,
1402
                datearrived   => undef,
1403
                datecancelled => undef,
1404
                daterequested => \'NOW()'
1405
            }
1406
        }
1407
    );
1408
1409
    $transfer = $new_item_1->get_transfer();
1410
    is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfer object' );
1411
1412
    my $transfer_2 = $builder->build_object(
1413
        {
1414
            class => 'Koha::Item::Transfers',
1415
            value => {
1416
                itemnumber    => $new_item_1->itemnumber,
1417
                frombranch    => $new_item_1->holdingbranch,
1418
                tobranch      => $library_to->{branchcode},
1419
                reason        => 'Manual',
1420
                datesent      => undef,
1421
                datearrived   => undef,
1422
                datecancelled => undef,
1423
                daterequested => \'NOW()'
1424
            }
1425
        }
1426
    );
1427
1428
    $transfer = $new_item_1->get_transfer();
1429
    is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the oldest transfer request');
1430
1431
    $transfer_2->datesent(\'NOW()')->store;
1432
    $transfer = $new_item_1->get_transfer();
1433
    is( $transfer->branchtransfer_id, $transfer_2->branchtransfer_id, 'Koha::Item->get_transfer returns the in_transit transfer');
1434
1435
    my $transfer_3 = $builder->build_object(
1436
        {
1437
            class => 'Koha::Item::Transfers',
1438
            value => {
1439
                itemnumber    => $new_item_1->itemnumber,
1440
                frombranch    => $new_item_1->holdingbranch,
1441
                tobranch      => $library_to->{branchcode},
1442
                reason        => 'Manual',
1443
                datesent      => undef,
1444
                datearrived   => undef,
1445
                datecancelled => undef,
1446
                daterequested => \'NOW()'
1447
            }
1448
        }
1449
    );
1450
1451
    $transfer_2->datearrived(\'NOW()')->store;
1452
    $transfer = $new_item_1->get_transfer();
1453
    is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the next queued transfer');
1454
    is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1455
1456
    $transfer_1->datecancelled(\'NOW()')->store;
1457
    $transfer = $new_item_1->get_transfer();
1458
    is( $transfer->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfer ignores cancelled transfers');
1459
};
1460
1461
subtest 'holds' => sub {
1385
subtest 'holds' => sub {
1462
    plan tests => 5;
1386
    plan tests => 5;
1463
1387
1464
- 

Return to bug 35100