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

(-)a/C4/Circulation.pm (-6 / +6 lines)
Lines 2368-2377 sub AddReturn { Link Here
2368
            else {
2368
            else {
2369
                $messages->{'TransferTrigger'} = $transfer->reason;
2369
                $messages->{'TransferTrigger'} = $transfer->reason;
2370
                if ( $transfer->frombranch eq $branch ) {
2370
                if ( $transfer->frombranch eq $branch ) {
2371
                    $transfer->transit;
2371
                    $messages->{'TransferTo'}    = $transfer->tobranch;
2372
                    $messages->{'WasTransfered'}   = $transfer->tobranch;
2372
                    $messages->{'WasTransfered'} = $transfer->id;
2373
                }
2373
                } else {
2374
                else {
2375
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2374
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2376
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2375
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2377
                }
2376
                }
Lines 2525-2532 sub AddReturn { Link Here
2525
            (C4::Context->preference("UseBranchTransferLimits") and
2524
            (C4::Context->preference("UseBranchTransferLimits") and
2526
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2525
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2527
           )) {
2526
           )) {
2528
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2527
            my $transfer = ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2529
            $messages->{'WasTransfered'} = $returnbranch;
2528
            $messages->{'TransferTo'} = $returnbranch;
2529
            $messages->{'WasTransfered'} = $transfer->id;
2530
            $messages->{'TransferTrigger'} = $transfer_trigger;
2530
            $messages->{'TransferTrigger'} = $transfer_trigger;
2531
        } else {
2531
        } else {
2532
            $messages->{'NeedsTransfer'} = $returnbranch;
2532
            $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 1057-1064 __PACKAGE__->has_many( Link Here
1057
            "$args->{foreign_alias}.datearrived"   => undef,
1057
            "$args->{foreign_alias}.datearrived"   => undef,
1058
            "$args->{foreign_alias}.datecancelled" => undef,
1058
            "$args->{foreign_alias}.datecancelled" => undef,
1059
        };
1059
        };
1060
    },
1060
    }
1061
    { order_by => [ { -desc => 'datesent' }, { -asc => 'daterequested' } ] }
1062
);
1061
);
1063
1062
1064
# Relationship with bundled items
1063
# Relationship with bundled items
(-)a/circ/returns.pl (-4 / +8 lines)
Lines 540-549 my $recalled = 0; Link Here
540
540
541
if ( $messages->{'WasTransfered'} ) {
541
if ( $messages->{'WasTransfered'} ) {
542
    $template->param(
542
    $template->param(
543
        found          => 1,
543
        found      => 1,
544
        transfer       => $messages->{'WasTransfered'},
544
        transfer   => $messages->{'WasTransfered'},
545
        trigger        => $messages->{'TransferTrigger'},
545
        transferto => $messages->{'TransferTo'},
546
        itemnumber     => $itemnumber,
546
        trigger    => $messages->{'TransferTrigger'},
547
        itemnumber => $itemnumber,
547
    );
548
    );
548
}
549
}
549
550
Lines 720-725 foreach my $code ( keys %$messages ) { Link Here
720
    elsif ( $code eq 'WasTransfered' ) {
721
    elsif ( $code eq 'WasTransfered' ) {
721
        ;    # FIXME... anything to do here?
722
        ;    # FIXME... anything to do here?
722
    }
723
    }
724
    elsif ( $code eq 'TransferTo' ) {
725
        ;    # Handled above, along with WasTransfered
726
    }
723
    elsif ( $code eq 'withdrawn' ) {
727
    elsif ( $code eq 'withdrawn' ) {
724
        $err{withdrawn} = 1;
728
        $err{withdrawn} = 1;
725
    }
729
    }
(-)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 754-760 Link Here
754
754
755
                                                <div class="modal-header">
755
                                                <div class="modal-header">
756
                                                    <h3>
756
                                                    <h3>
757
                                                        Please return this item to [% IF transfer %][% Branches.GetName( transfer ) | html %][% ELSE %][% Branches.GetName( returnbranch ) | html %][% END %]
757
                                                        Please return this item to [% IF transferto %][% Branches.GetName( transferto ) | html %][% ELSE %][% Branches.GetName( returnbranch ) | html %][% END %]
758
                                                    </h3>
758
                                                    </h3>
759
                                                </div>
759
                                                </div>
760
                                                <div class="modal-body">
760
                                                <div class="modal-body">
Lines 781-786 Link Here
781
                                                        <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>
781
                                                        <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>
782
                                                        <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>
782
                                                        <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>
783
                                                    [% ELSE %]
783
                                                    [% ELSE %]
784
                                                        <input type="hidden" name="transit" value="[% transfer | uri %]"/>
784
                                                        <button type="button" data-dismiss="modal" class="btn btn-default" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
785
                                                        <button type="button" data-dismiss="modal" class="btn btn-default" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
785
                                                        <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>
786
                                                        <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>
786
                                                    [% END %]
787
                                                    [% END %]
(-)a/t/db_dependent/Circulation.t (-11 / +24 lines)
Lines 6654-6678 subtest 'Tests for transfer not in transit' => sub { Link Here
6654
6654
6655
    plan tests => 2;
6655
    plan tests => 2;
6656
6656
6657
6658
    # These tests are to ensure a 'pending' transfer, generated by
6657
    # These tests are to ensure a 'pending' transfer, generated by
6659
    # stock rotation, will be advanced when checked in
6658
    # stock rotation, will be advanced when checked in
6660
6659
6661
    my $item = $builder->build_sample_item();
6660
    my $item     = $builder->build_sample_item();
6662
    my $transfer = $builder->build_object({ class => 'Koha::Item::Transfers', value => {
6661
    my $transfer = $builder->build_object(
6663
        itemnumber => $item->id,
6662
        {
6664
        reason => 'StockrotationRepatriation',
6663
            class => 'Koha::Item::Transfers',
6665
        datesent => undef,
6664
            value => {
6666
        frombranch => $item->homebranch,
6665
                itemnumber => $item->id,
6667
    }});
6666
                reason     => 'StockrotationRepatriation',
6667
                datesent   => undef,
6668
                frombranch => $item->homebranch,
6669
            }
6670
        }
6671
    );
6668
    my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef );
6672
    my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef );
6669
    is_deeply(
6673
    is_deeply(
6670
        \@return,
6674
        \@return,
6671
        [ 0, { WasTransfered => $transfer->tobranch, TransferTrigger => 'StockrotationRepatriation', NotIssued => $item->barcode }, undef, {} ], "Item is reported to have been transferred");
6675
        [
6676
            0,
6677
            {
6678
                TransferTo      => $transfer->tobranch,         WasTransfered => $transfer->id,
6679
                TransferTrigger => 'StockrotationRepatriation', NotIssued     => $item->barcode
6680
            },
6681
            undef,
6682
            {}
6683
        ],
6684
        "Item is reported to have been transferred"
6685
    );
6672
6686
6673
    $transfer->discard_changes;
6687
    $transfer->discard_changes;
6674
    ok( $transfer->datesent, 'The datesent field is populated, i.e. transfer is initiated');
6688
    is( $transfer->datesent, undef, 'The datesent field remains unpopulated, i.e. transfer is not yet initiated' );
6675
6676
};
6689
};
6677
6690
6678
subtest 'Tests for RecordLocalUseOnReturn' => sub {
6691
subtest 'Tests for RecordLocalUseOnReturn' => sub {
(-)a/t/db_dependent/Koha/Item.t (-3 / +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 1198-1205 subtest 'Tests for itemtype|item_type' => sub { Link Here
1198
    $schema->storage->txn_rollback;
1198
    $schema->storage->txn_rollback;
1199
};
1199
};
1200
1200
1201
subtest 'get_transfer' => sub {
1202
    plan tests => 8;
1203
    $schema->storage->txn_begin;
1204
1205
    my $item = $builder->build_sample_item();
1206
1207
    my $transfer = $item->get_transfer();
1208
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item has no queued transfers' );
1209
1210
    my $library_to = $builder->build( { source => 'Branch' } );
1211
1212
    my $transfer_1 = $builder->build_object(
1213
        {
1214
            class => 'Koha::Item::Transfers',
1215
            value => {
1216
                itemnumber    => $item->itemnumber,
1217
                frombranch    => $item->holdingbranch,
1218
                tobranch      => $library_to->{branchcode},
1219
                reason        => 'Manual',
1220
                datesent      => undef,
1221
                datearrived   => undef,
1222
                datecancelled => undef,
1223
                daterequested => \'NOW()'
1224
            }
1225
        }
1226
    );
1227
1228
    $transfer = $item->get_transfer();
1229
    is(
1230
        ref($transfer), 'Koha::Item::Transfer',
1231
        'Koha::Item->get_transfer should return a Koha::Item::Transfer object'
1232
    );
1233
1234
    my $transfer_2 = $builder->build_object(
1235
        {
1236
            class => 'Koha::Item::Transfers',
1237
            value => {
1238
                itemnumber    => $item->itemnumber,
1239
                frombranch    => $item->holdingbranch,
1240
                tobranch      => $library_to->{branchcode},
1241
                reason        => 'Manual',
1242
                datesent      => undef,
1243
                datearrived   => undef,
1244
                datecancelled => undef,
1245
                daterequested => \'NOW()'
1246
            }
1247
        }
1248
    );
1249
1250
    $transfer = $item->get_transfer();
1251
    is(
1252
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1253
        'Koha::Item->get_transfer returns the oldest transfer request'
1254
    );
1255
1256
    $transfer_2->datesent( \'NOW()' )->store;
1257
    $transfer = $item->get_transfer();
1258
    is(
1259
        $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1260
        'Koha::Item->get_transfer returns the in_transit transfer'
1261
    );
1262
1263
    my $transfer_3 = $builder->build_object(
1264
        {
1265
            class => 'Koha::Item::Transfers',
1266
            value => {
1267
                itemnumber    => $item->itemnumber,
1268
                frombranch    => $item->holdingbranch,
1269
                tobranch      => $library_to->{branchcode},
1270
                reason        => 'Manual',
1271
                datesent      => undef,
1272
                datearrived   => undef,
1273
                datecancelled => undef,
1274
                daterequested => \'NOW()'
1275
            }
1276
        }
1277
    );
1278
1279
    $transfer_2->datearrived( \'NOW()' )->store;
1280
    $transfer = $item->get_transfer();
1281
    is(
1282
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1283
        'Koha::Item->get_transfer returns the next queued transfer'
1284
    );
1285
    is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1286
1287
    $transfer_1->datecancelled( \'NOW()' )->store;
1288
    $transfer = $item->get_transfer();
1289
    is(
1290
        $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1291
        'Koha::Item->get_transfer ignores cancelled transfers'
1292
    );
1293
1294
    subtest "Ensure prefetches don't affect which transfer if returned" => sub {
1295
        plan tests => 5;
1296
1297
        # Reset test data
1298
        $transfer_1->datecancelled(undef)->store;
1299
        $transfer_2->set( { datesent => undef, datearrived => undef } )->store;
1300
1301
        my $prefetched_item = Koha::Items->search(
1302
            { 'me.itemnumber' => $item->itemnumber },
1303
            { prefetch        => ['current_branchtransfers'] }
1304
        )->next;
1305
1306
        $transfer = $prefetched_item->get_transfer();
1307
        is(
1308
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1309
            'Koha::Item->get_transfer returns the oldest transfer request'
1310
        );
1311
1312
        $transfer_2->datesent( \'NOW()' )->store;
1313
        $prefetched_item = Koha::Items->search(
1314
            { 'me.itemnumber' => $item->itemnumber },
1315
            { prefetch        => ['current_branchtransfers'] }
1316
        )->next;
1317
1318
        $transfer = $prefetched_item->get_transfer();
1319
        is(
1320
            $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1321
            'Koha::Item->get_transfer returns the in_transit transfer'
1322
        );
1323
1324
        $transfer_2->datearrived( \'NOW()' )->store;
1325
        $prefetched_item = Koha::Items->search(
1326
            { 'me.itemnumber' => $item->itemnumber },
1327
            { prefetch        => ['current_branchtransfers'] }
1328
        )->next;
1329
        $transfer = $prefetched_item->get_transfer();
1330
        is(
1331
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1332
            'Koha::Item->get_transfer returns the next queued transfer'
1333
        );
1334
        is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1335
1336
        $transfer_1->datecancelled( \'NOW()' )->store;
1337
        $prefetched_item = Koha::Items->search(
1338
            { 'me.itemnumber' => $item->itemnumber },
1339
            { prefetch        => ['current_branchtransfers'] }
1340
        )->next;
1341
        $transfer = $prefetched_item->get_transfer();
1342
        is(
1343
            $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1344
            'Koha::Item->get_transfer ignores cancelled transfers'
1345
        );
1346
    };
1347
    $schema->storage->txn_rollback;
1348
};
1349
1201
subtest 'get_transfers' => sub {
1350
subtest 'get_transfers' => sub {
1202
    plan tests => 16;
1351
    plan tests => 17;
1203
    $schema->storage->txn_begin;
1352
    $schema->storage->txn_begin;
1204
1353
1205
    my $item = $builder->build_sample_item();
1354
    my $item = $builder->build_sample_item();
Lines 1294-1299 subtest 'get_transfers' => sub { Link Here
1294
    $result_1 = $transfers->next;
1443
    $result_1 = $transfers->next;
1295
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1444
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1296
1445
1446
    subtest "Ensure prefetches don't affect the return order" => sub {
1447
        plan tests => 13;
1448
1449
        # Reset test data
1450
        $transfer_2->datesent(undef)->store;
1451
        $transfer_2->datearrived(undef)->store;
1452
        $transfer_1->datecancelled(undef)->store;
1453
1454
        my $prefetched_item = Koha::Items->search(
1455
            { 'me.itemnumber' => $item->itemnumber },
1456
            { prefetch        => ['current_branchtransfers'] }
1457
        )->next;
1458
1459
        $transfers = $prefetched_item->get_transfers();
1460
        is(
1461
            $transfers->count, 3,
1462
            'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all'
1463
        );
1464
        $result_1 = $transfers->next;
1465
        $result_2 = $transfers->next;
1466
        $result_3 = $transfers->next;
1467
        is(
1468
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1469
            'Koha::Item->get_transfers returns the oldest transfer request first'
1470
        );
1471
        is(
1472
            $result_2->branchtransfer_id, $transfer_2->branchtransfer_id,
1473
            'Koha::Item->get_transfers returns the newer transfer request second'
1474
        );
1475
        is(
1476
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1477
            'Koha::Item->get_transfers returns the newest transfer request last'
1478
        );
1479
1480
        $transfer_2->datesent( \'NOW()' )->store;
1481
        $prefetched_item = Koha::Items->search(
1482
            { 'me.itemnumber' => $item->itemnumber },
1483
            { prefetch        => ['current_branchtransfers'] }
1484
        )->next;
1485
        $transfers = $prefetched_item->get_transfers();
1486
        is(
1487
            $transfers->count, 3,
1488
            'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all'
1489
        );
1490
        $result_1 = $transfers->next;
1491
        $result_2 = $transfers->next;
1492
        $result_3 = $transfers->next;
1493
        is(
1494
            $result_1->branchtransfer_id, $transfer_2->branchtransfer_id,
1495
            'Koha::Item->get_transfers returns the active transfer request first'
1496
        );
1497
        is(
1498
            $result_2->branchtransfer_id, $transfer_1->branchtransfer_id,
1499
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1500
        );
1501
        is(
1502
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1503
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1504
        );
1505
1506
        $transfer_2->datearrived( \'NOW()' )->store;
1507
        $prefetched_item = Koha::Items->search(
1508
            { 'me.itemnumber' => $item->itemnumber },
1509
            { prefetch        => ['current_branchtransfers'] }
1510
        )->next;
1511
        $transfers = $prefetched_item->get_transfers();
1512
        is(
1513
            $transfers->count, 2,
1514
            'Once a transfer is received, it no longer appears in the list from ->get_transfers()'
1515
        );
1516
        $result_1 = $transfers->next;
1517
        $result_2 = $transfers->next;
1518
        is(
1519
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1520
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1521
        );
1522
        is(
1523
            $result_2->branchtransfer_id, $transfer_3->branchtransfer_id,
1524
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1525
        );
1526
1527
        $transfer_1->datecancelled( \'NOW()' )->store;
1528
        $prefetched_item = Koha::Items->search(
1529
            { 'me.itemnumber' => $item->itemnumber },
1530
            { prefetch        => ['current_branchtransfers'] }
1531
        )->next;
1532
        $transfers = $prefetched_item->get_transfers();
1533
        is(
1534
            $transfers->count, 1,
1535
            'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()'
1536
        );
1537
        $result_1 = $transfers->next;
1538
        is(
1539
            $result_1->branchtransfer_id, $transfer_3->branchtransfer_id,
1540
            'Koha::Item->get_transfers returns the only transfer that remains'
1541
        );
1542
    };
1543
1297
    $schema->storage->txn_rollback;
1544
    $schema->storage->txn_rollback;
1298
};
1545
};
1299
1546
1300
- 

Return to bug 35100