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

(-)a/C4/Circulation.pm (-6 / +6 lines)
Lines 2364-2373 sub AddReturn { Link Here
2364
            else {
2364
            else {
2365
                $messages->{'TransferTrigger'} = $transfer->reason;
2365
                $messages->{'TransferTrigger'} = $transfer->reason;
2366
                if ( $transfer->frombranch eq $branch ) {
2366
                if ( $transfer->frombranch eq $branch ) {
2367
                    $transfer->transit;
2367
                    $messages->{'TransferTo'}    = $transfer->tobranch;
2368
                    $messages->{'WasTransfered'}   = $transfer->tobranch;
2368
                    $messages->{'WasTransfered'} = $transfer->id;
2369
                }
2369
                } else {
2370
                else {
2371
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2370
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2372
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2371
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2373
                }
2372
                }
Lines 2521-2528 sub AddReturn { Link Here
2521
            (C4::Context->preference("UseBranchTransferLimits") and
2520
            (C4::Context->preference("UseBranchTransferLimits") and
2522
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2521
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2523
           )) {
2522
           )) {
2524
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2523
            my $transfer = ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2525
            $messages->{'WasTransfered'} = $returnbranch;
2524
            $messages->{'TransferTo'} = $returnbranch;
2525
            $messages->{'WasTransfered'} = $transfer->id;
2526
            $messages->{'TransferTrigger'} = $transfer_trigger;
2526
            $messages->{'TransferTrigger'} = $transfer_trigger;
2527
        } else {
2527
        } else {
2528
            $messages->{'NeedsTransfer'} = $returnbranch;
2528
            $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 795-803 we still expect the item to end up at a final location eventually. Link Here
795
795
796
sub get_transfer {
796
sub get_transfer {
797
    my ($self) = @_;
797
    my ($self) = @_;
798
    my $transfers = $self->_result->current_branchtransfers->search(
799
        undef,
800
        { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] }
801
    );
798
802
799
    my $transfer = $self->_result->current_branchtransfers->next;
803
    my $transfer = $transfers->next;
800
    return  Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer;
804
    return Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer;
801
}
805
}
802
806
803
=head3 transfer
807
=head3 transfer
Lines 841-849 we still expect the item to end up at a final location eventually. Link Here
841
sub get_transfers {
845
sub get_transfers {
842
    my ($self) = @_;
846
    my ($self) = @_;
843
847
844
    my $transfer_rs = $self->_result->current_branchtransfers;
848
    my $transfers_rs = $self->_result->current_branchtransfers->search(
849
        undef,
850
        { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] }
851
    );
845
852
846
    return Koha::Item::Transfers->_new_from_dbic($transfer_rs);
853
    return Koha::Item::Transfers->_new_from_dbic($transfers_rs);
847
}
854
}
848
855
849
=head3 last_returned_by
856
=head3 last_returned_by
(-)a/Koha/Schema/Result/Item.pm (-2 / +1 lines)
Lines 1048-1055 __PACKAGE__->has_many( Link Here
1048
            "$args->{foreign_alias}.datearrived"   => undef,
1048
            "$args->{foreign_alias}.datearrived"   => undef,
1049
            "$args->{foreign_alias}.datecancelled" => undef,
1049
            "$args->{foreign_alias}.datecancelled" => undef,
1050
        };
1050
        };
1051
    },
1051
    }
1052
    { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] }
1053
);
1052
);
1054
1053
1055
# Relationship with bundled items
1054
# Relationship with bundled items
(-)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 6262-6286 subtest 'Tests for transfer not in transit' => sub { Link Here
6262
6262
6263
    plan tests => 2;
6263
    plan tests => 2;
6264
6264
6265
6266
    # These tests are to ensure a 'pending' transfer, generated by
6265
    # These tests are to ensure a 'pending' transfer, generated by
6267
    # stock rotation, will be advanced when checked in
6266
    # stock rotation, will be advanced when checked in
6268
6267
6269
    my $item = $builder->build_sample_item();
6268
    my $item     = $builder->build_sample_item();
6270
    my $transfer = $builder->build_object({ class => 'Koha::Item::Transfers', value => {
6269
    my $transfer = $builder->build_object(
6271
        itemnumber => $item->id,
6270
        {
6272
        reason => 'StockrotationRepatriation',
6271
            class => 'Koha::Item::Transfers',
6273
        datesent => undef,
6272
            value => {
6274
        frombranch => $item->homebranch,
6273
                itemnumber => $item->id,
6275
    }});
6274
                reason     => 'StockrotationRepatriation',
6275
                datesent   => undef,
6276
                frombranch => $item->homebranch,
6277
            }
6278
        }
6279
    );
6276
    my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef );
6280
    my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef );
6277
    is_deeply(
6281
    is_deeply(
6278
        \@return,
6282
        \@return,
6279
        [ 0, { WasTransfered => $transfer->tobranch, TransferTrigger => 'StockrotationRepatriation', NotIssued => $item->barcode }, undef, {} ], "Item is reported to have been transferred");
6283
        [
6284
            0,
6285
            {
6286
                TransferTo      => $transfer->tobranch,         WasTransfered => $transfer->id,
6287
                TransferTrigger => 'StockrotationRepatriation', NotIssued     => $item->barcode
6288
            },
6289
            undef,
6290
            {}
6291
        ],
6292
        "Item is reported to have been transferred"
6293
    );
6280
6294
6281
    $transfer->discard_changes;
6295
    $transfer->discard_changes;
6282
    ok( $transfer->datesent, 'The datesent field is populated, i.e. transfer is initiated');
6296
    is( $transfer->datesent, undef, 'The datesent field remains unpopulated, i.e. transfer is not yet initiated' );
6283
6284
};
6297
};
6285
6298
6286
subtest 'Tests for RecordLocalUseOnReturn' => sub {
6299
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 => 34;
23
use Test::More tests => 35;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
26
Lines 1191-1198 subtest 'Tests for itemtype' => sub { Link Here
1191
    $schema->storage->txn_rollback;
1191
    $schema->storage->txn_rollback;
1192
};
1192
};
1193
1193
1194
subtest 'get_transfer' => sub {
1195
    plan tests => 8;
1196
    $schema->storage->txn_begin;
1197
1198
    my $item = $builder->build_sample_item();
1199
1200
    my $transfer = $item->get_transfer();
1201
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item has no queued transfers' );
1202
1203
    my $library_to = $builder->build( { source => 'Branch' } );
1204
1205
    my $transfer_1 = $builder->build_object(
1206
        {
1207
            class => 'Koha::Item::Transfers',
1208
            value => {
1209
                itemnumber    => $item->itemnumber,
1210
                frombranch    => $item->holdingbranch,
1211
                tobranch      => $library_to->{branchcode},
1212
                reason        => 'Manual',
1213
                datesent      => undef,
1214
                datearrived   => undef,
1215
                datecancelled => undef,
1216
                daterequested => \'NOW()'
1217
            }
1218
        }
1219
    );
1220
1221
    $transfer = $item->get_transfer();
1222
    is(
1223
        ref($transfer), 'Koha::Item::Transfer',
1224
        'Koha::Item->get_transfer should return a Koha::Item::Transfer object'
1225
    );
1226
1227
    my $transfer_2 = $builder->build_object(
1228
        {
1229
            class => 'Koha::Item::Transfers',
1230
            value => {
1231
                itemnumber    => $item->itemnumber,
1232
                frombranch    => $item->holdingbranch,
1233
                tobranch      => $library_to->{branchcode},
1234
                reason        => 'Manual',
1235
                datesent      => undef,
1236
                datearrived   => undef,
1237
                datecancelled => undef,
1238
                daterequested => \'NOW()'
1239
            }
1240
        }
1241
    );
1242
1243
    $transfer = $item->get_transfer();
1244
    is(
1245
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1246
        'Koha::Item->get_transfer returns the oldest transfer request'
1247
    );
1248
1249
    $transfer_2->datesent( \'NOW()' )->store;
1250
    $transfer = $item->get_transfer();
1251
    is(
1252
        $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1253
        'Koha::Item->get_transfer returns the in_transit transfer'
1254
    );
1255
1256
    my $transfer_3 = $builder->build_object(
1257
        {
1258
            class => 'Koha::Item::Transfers',
1259
            value => {
1260
                itemnumber    => $item->itemnumber,
1261
                frombranch    => $item->holdingbranch,
1262
                tobranch      => $library_to->{branchcode},
1263
                reason        => 'Manual',
1264
                datesent      => undef,
1265
                datearrived   => undef,
1266
                datecancelled => undef,
1267
                daterequested => \'NOW()'
1268
            }
1269
        }
1270
    );
1271
1272
    $transfer_2->datearrived( \'NOW()' )->store;
1273
    $transfer = $item->get_transfer();
1274
    is(
1275
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1276
        'Koha::Item->get_transfer returns the next queued transfer'
1277
    );
1278
    is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1279
1280
    $transfer_1->datecancelled( \'NOW()' )->store;
1281
    $transfer = $item->get_transfer();
1282
    is(
1283
        $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1284
        'Koha::Item->get_transfer ignores cancelled transfers'
1285
    );
1286
1287
    subtest "Ensure prefetches don't affect which transfer if returned" => sub {
1288
        plan tests => 5;
1289
1290
        # Reset test data
1291
        $transfer_1->datecancelled(undef)->store;
1292
        $transfer_2->set( { datesent => undef, datearrived => undef } )->store;
1293
1294
        my $prefetched_item = Koha::Items->search(
1295
            { 'me.itemnumber' => $item->itemnumber },
1296
            { prefetch        => ['current_branchtransfers'] }
1297
        )->next;
1298
1299
        $transfer = $prefetched_item->get_transfer();
1300
        is(
1301
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1302
            'Koha::Item->get_transfer returns the oldest transfer request'
1303
        );
1304
1305
        $transfer_2->datesent( \'NOW()' )->store;
1306
        $prefetched_item = Koha::Items->search(
1307
            { 'me.itemnumber' => $item->itemnumber },
1308
            { prefetch        => ['current_branchtransfers'] }
1309
        )->next;
1310
1311
        $transfer = $prefetched_item->get_transfer();
1312
        is(
1313
            $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1314
            'Koha::Item->get_transfer returns the in_transit transfer'
1315
        );
1316
1317
        $transfer_2->datearrived( \'NOW()' )->store;
1318
        $prefetched_item = Koha::Items->search(
1319
            { 'me.itemnumber' => $item->itemnumber },
1320
            { prefetch        => ['current_branchtransfers'] }
1321
        )->next;
1322
        $transfer = $prefetched_item->get_transfer();
1323
        is(
1324
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1325
            'Koha::Item->get_transfer returns the next queued transfer'
1326
        );
1327
        is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1328
1329
        $transfer_1->datecancelled( \'NOW()' )->store;
1330
        $prefetched_item = Koha::Items->search(
1331
            { 'me.itemnumber' => $item->itemnumber },
1332
            { prefetch        => ['current_branchtransfers'] }
1333
        )->next;
1334
        $transfer = $prefetched_item->get_transfer();
1335
        is(
1336
            $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1337
            'Koha::Item->get_transfer ignores cancelled transfers'
1338
        );
1339
    };
1340
    $schema->storage->txn_rollback;
1341
};
1342
1194
subtest 'get_transfers' => sub {
1343
subtest 'get_transfers' => sub {
1195
    plan tests => 16;
1344
    plan tests => 17;
1196
    $schema->storage->txn_begin;
1345
    $schema->storage->txn_begin;
1197
1346
1198
    my $item = $builder->build_sample_item();
1347
    my $item = $builder->build_sample_item();
Lines 1287-1292 subtest 'get_transfers' => sub { Link Here
1287
    $result_1 = $transfers->next;
1436
    $result_1 = $transfers->next;
1288
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1437
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1289
1438
1439
    subtest "Ensure prefetches don't affect the return order" => sub {
1440
        plan tests => 13;
1441
1442
        # Reset test data
1443
        $transfer_2->datesent(undef)->store;
1444
        $transfer_2->datearrived(undef)->store;
1445
        $transfer_1->datecancelled(undef)->store;
1446
1447
        my $prefetched_item = Koha::Items->search(
1448
            { 'me.itemnumber' => $item->itemnumber },
1449
            { prefetch        => ['current_branchtransfers'] }
1450
        )->next;
1451
1452
        $transfers = $prefetched_item->get_transfers();
1453
        is(
1454
            $transfers->count, 3,
1455
            'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all'
1456
        );
1457
        $result_1 = $transfers->next;
1458
        $result_2 = $transfers->next;
1459
        $result_3 = $transfers->next;
1460
        is(
1461
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1462
            'Koha::Item->get_transfers returns the oldest transfer request first'
1463
        );
1464
        is(
1465
            $result_2->branchtransfer_id, $transfer_2->branchtransfer_id,
1466
            'Koha::Item->get_transfers returns the newer transfer request second'
1467
        );
1468
        is(
1469
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1470
            'Koha::Item->get_transfers returns the newest transfer request last'
1471
        );
1472
1473
        $transfer_2->datesent( \'NOW()' )->store;
1474
        $prefetched_item = Koha::Items->search(
1475
            { 'me.itemnumber' => $item->itemnumber },
1476
            { prefetch        => ['current_branchtransfers'] }
1477
        )->next;
1478
        $transfers = $prefetched_item->get_transfers();
1479
        is(
1480
            $transfers->count, 3,
1481
            'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all'
1482
        );
1483
        $result_1 = $transfers->next;
1484
        $result_2 = $transfers->next;
1485
        $result_3 = $transfers->next;
1486
        is(
1487
            $result_1->branchtransfer_id, $transfer_2->branchtransfer_id,
1488
            'Koha::Item->get_transfers returns the active transfer request first'
1489
        );
1490
        is(
1491
            $result_2->branchtransfer_id, $transfer_1->branchtransfer_id,
1492
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1493
        );
1494
        is(
1495
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1496
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1497
        );
1498
1499
        $transfer_2->datearrived( \'NOW()' )->store;
1500
        $prefetched_item = Koha::Items->search(
1501
            { 'me.itemnumber' => $item->itemnumber },
1502
            { prefetch        => ['current_branchtransfers'] }
1503
        )->next;
1504
        $transfers = $prefetched_item->get_transfers();
1505
        is(
1506
            $transfers->count, 2,
1507
            'Once a transfer is received, it no longer appears in the list from ->get_transfers()'
1508
        );
1509
        $result_1 = $transfers->next;
1510
        $result_2 = $transfers->next;
1511
        is(
1512
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1513
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1514
        );
1515
        is(
1516
            $result_2->branchtransfer_id, $transfer_3->branchtransfer_id,
1517
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1518
        );
1519
1520
        $transfer_1->datecancelled( \'NOW()' )->store;
1521
        $prefetched_item = Koha::Items->search(
1522
            { 'me.itemnumber' => $item->itemnumber },
1523
            { prefetch        => ['current_branchtransfers'] }
1524
        )->next;
1525
        $transfers = $prefetched_item->get_transfers();
1526
        is(
1527
            $transfers->count, 1,
1528
            'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()'
1529
        );
1530
        $result_1 = $transfers->next;
1531
        is(
1532
            $result_1->branchtransfer_id, $transfer_3->branchtransfer_id,
1533
            'Koha::Item->get_transfers returns the only transfer that remains'
1534
        );
1535
    };
1536
1290
    $schema->storage->txn_rollback;
1537
    $schema->storage->txn_rollback;
1291
};
1538
};
1292
1539
(-)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 => 17;
22
use Test::More tests => 16;
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