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

(-)a/C4/Circulation.pm (-6 / +6 lines)
Lines 2374-2383 sub AddReturn { Link Here
2374
            else {
2374
            else {
2375
                $messages->{'TransferTrigger'} = $transfer->reason;
2375
                $messages->{'TransferTrigger'} = $transfer->reason;
2376
                if ( $transfer->frombranch eq $branch ) {
2376
                if ( $transfer->frombranch eq $branch ) {
2377
                    $transfer->transit;
2377
                    $messages->{'TransferTo'}    = $transfer->tobranch;
2378
                    $messages->{'WasTransfered'}   = $transfer->tobranch;
2378
                    $messages->{'WasTransfered'} = $transfer->id;
2379
                }
2379
                } else {
2380
                else {
2381
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2380
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2382
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2381
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2383
                }
2382
                }
Lines 2531-2538 sub AddReturn { Link Here
2531
            (C4::Context->preference("UseBranchTransferLimits") and
2530
            (C4::Context->preference("UseBranchTransferLimits") and
2532
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2531
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2533
           )) {
2532
           )) {
2534
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2533
            my $transfer = ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2535
            $messages->{'WasTransfered'} = $returnbranch;
2534
            $messages->{'TransferTo'} = $returnbranch;
2535
            $messages->{'WasTransfered'} = $transfer->id;
2536
            $messages->{'TransferTrigger'} = $transfer_trigger;
2536
            $messages->{'TransferTrigger'} = $transfer_trigger;
2537
        } else {
2537
        } else {
2538
            $messages->{'NeedsTransfer'} = $returnbranch;
2538
            $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 810-818 we still expect the item to end up at a final location eventually. Link Here
810
810
811
sub get_transfer {
811
sub get_transfer {
812
    my ($self) = @_;
812
    my ($self) = @_;
813
    my $transfers = $self->_result->current_branchtransfers->search(
814
        undef,
815
        { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] }
816
    );
813
817
814
    my $transfer = $self->_result->current_branchtransfers->next;
818
    my $transfer = $transfers->next;
815
    return  Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer;
819
    return Koha::Item::Transfer->_new_from_dbic($transfer) if $transfer;
816
}
820
}
817
821
818
=head3 transfer
822
=head3 transfer
Lines 856-864 we still expect the item to end up at a final location eventually. Link Here
856
sub get_transfers {
860
sub get_transfers {
857
    my ($self) = @_;
861
    my ($self) = @_;
858
862
859
    my $transfer_rs = $self->_result->current_branchtransfers;
863
    my $transfers_rs = $self->_result->current_branchtransfers->search(
864
        undef,
865
        { 'order_by' => [ { '-desc' => 'datesent' }, { '-asc' => 'daterequested' } ] }
866
    );
860
867
861
    return Koha::Item::Transfers->_new_from_dbic($transfer_rs);
868
    return Koha::Item::Transfers->_new_from_dbic($transfers_rs);
862
}
869
}
863
870
864
=head3 last_returned_by
871
=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="alert alert-info">
126
                                 <div id="transfer-trigger" class="alert alert-info">
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
                                                    <h1 class="modal-title">
756
                                                    <h1 class="modal-title">
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
                                                    </h1>
758
                                                    </h1>
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-bs-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-bs-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-bs-dismiss="modal" class="btn btn-default" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
785
                                                        <button type="button" data-bs-dismiss="modal" class="btn btn-default" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
785
                                                        <button type="button" data-bs-dismiss="modal" class="btn btn-default print 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-bs-dismiss="modal" class="btn btn-default print 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 => 36;
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 1309-1316 subtest 'Tests for itemtype|item_type' => sub { Link Here
1309
    $schema->storage->txn_rollback;
1309
    $schema->storage->txn_rollback;
1310
};
1310
};
1311
1311
1312
subtest 'get_transfer' => sub {
1313
    plan tests => 8;
1314
    $schema->storage->txn_begin;
1315
1316
    my $item = $builder->build_sample_item();
1317
1318
    my $transfer = $item->get_transfer();
1319
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item has no queued transfers' );
1320
1321
    my $library_to = $builder->build( { source => 'Branch' } );
1322
1323
    my $transfer_1 = $builder->build_object(
1324
        {
1325
            class => 'Koha::Item::Transfers',
1326
            value => {
1327
                itemnumber    => $item->itemnumber,
1328
                frombranch    => $item->holdingbranch,
1329
                tobranch      => $library_to->{branchcode},
1330
                reason        => 'Manual',
1331
                datesent      => undef,
1332
                datearrived   => undef,
1333
                datecancelled => undef,
1334
                daterequested => \'NOW()'
1335
            }
1336
        }
1337
    );
1338
1339
    $transfer = $item->get_transfer();
1340
    is(
1341
        ref($transfer), 'Koha::Item::Transfer',
1342
        'Koha::Item->get_transfer should return a Koha::Item::Transfer object'
1343
    );
1344
1345
    my $transfer_2 = $builder->build_object(
1346
        {
1347
            class => 'Koha::Item::Transfers',
1348
            value => {
1349
                itemnumber    => $item->itemnumber,
1350
                frombranch    => $item->holdingbranch,
1351
                tobranch      => $library_to->{branchcode},
1352
                reason        => 'Manual',
1353
                datesent      => undef,
1354
                datearrived   => undef,
1355
                datecancelled => undef,
1356
                daterequested => \'NOW()'
1357
            }
1358
        }
1359
    );
1360
1361
    $transfer = $item->get_transfer();
1362
    is(
1363
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1364
        'Koha::Item->get_transfer returns the oldest transfer request'
1365
    );
1366
1367
    $transfer_2->datesent( \'NOW()' )->store;
1368
    $transfer = $item->get_transfer();
1369
    is(
1370
        $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1371
        'Koha::Item->get_transfer returns the in_transit transfer'
1372
    );
1373
1374
    my $transfer_3 = $builder->build_object(
1375
        {
1376
            class => 'Koha::Item::Transfers',
1377
            value => {
1378
                itemnumber    => $item->itemnumber,
1379
                frombranch    => $item->holdingbranch,
1380
                tobranch      => $library_to->{branchcode},
1381
                reason        => 'Manual',
1382
                datesent      => undef,
1383
                datearrived   => undef,
1384
                datecancelled => undef,
1385
                daterequested => \'NOW()'
1386
            }
1387
        }
1388
    );
1389
1390
    $transfer_2->datearrived( \'NOW()' )->store;
1391
    $transfer = $item->get_transfer();
1392
    is(
1393
        $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1394
        'Koha::Item->get_transfer returns the next queued transfer'
1395
    );
1396
    is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1397
1398
    $transfer_1->datecancelled( \'NOW()' )->store;
1399
    $transfer = $item->get_transfer();
1400
    is(
1401
        $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1402
        'Koha::Item->get_transfer ignores cancelled transfers'
1403
    );
1404
1405
    subtest "Ensure prefetches don't affect which transfer if returned" => sub {
1406
        plan tests => 5;
1407
1408
        # Reset test data
1409
        $transfer_1->datecancelled(undef)->store;
1410
        $transfer_2->set( { datesent => undef, datearrived => undef } )->store;
1411
1412
        my $prefetched_item = Koha::Items->search(
1413
            { 'me.itemnumber' => $item->itemnumber },
1414
            { prefetch        => ['current_branchtransfers'] }
1415
        )->next;
1416
1417
        $transfer = $prefetched_item->get_transfer();
1418
        is(
1419
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1420
            'Koha::Item->get_transfer returns the oldest transfer request'
1421
        );
1422
1423
        $transfer_2->datesent( \'NOW()' )->store;
1424
        $prefetched_item = Koha::Items->search(
1425
            { 'me.itemnumber' => $item->itemnumber },
1426
            { prefetch        => ['current_branchtransfers'] }
1427
        )->next;
1428
1429
        $transfer = $prefetched_item->get_transfer();
1430
        is(
1431
            $transfer->branchtransfer_id, $transfer_2->branchtransfer_id,
1432
            'Koha::Item->get_transfer returns the in_transit transfer'
1433
        );
1434
1435
        $transfer_2->datearrived( \'NOW()' )->store;
1436
        $prefetched_item = Koha::Items->search(
1437
            { 'me.itemnumber' => $item->itemnumber },
1438
            { prefetch        => ['current_branchtransfers'] }
1439
        )->next;
1440
        $transfer = $prefetched_item->get_transfer();
1441
        is(
1442
            $transfer->branchtransfer_id, $transfer_1->branchtransfer_id,
1443
            'Koha::Item->get_transfer returns the next queued transfer'
1444
        );
1445
        is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
1446
1447
        $transfer_1->datecancelled( \'NOW()' )->store;
1448
        $prefetched_item = Koha::Items->search(
1449
            { 'me.itemnumber' => $item->itemnumber },
1450
            { prefetch        => ['current_branchtransfers'] }
1451
        )->next;
1452
        $transfer = $prefetched_item->get_transfer();
1453
        is(
1454
            $transfer->branchtransfer_id, $transfer_3->branchtransfer_id,
1455
            'Koha::Item->get_transfer ignores cancelled transfers'
1456
        );
1457
    };
1458
    $schema->storage->txn_rollback;
1459
};
1460
1312
subtest 'get_transfers' => sub {
1461
subtest 'get_transfers' => sub {
1313
    plan tests => 16;
1462
    plan tests => 17;
1314
    $schema->storage->txn_begin;
1463
    $schema->storage->txn_begin;
1315
1464
1316
    my $item = $builder->build_sample_item();
1465
    my $item = $builder->build_sample_item();
Lines 1405-1410 subtest 'get_transfers' => sub { Link Here
1405
    $result_1 = $transfers->next;
1554
    $result_1 = $transfers->next;
1406
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1555
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1407
1556
1557
    subtest "Ensure prefetches don't affect the return order" => sub {
1558
        plan tests => 13;
1559
1560
        # Reset test data
1561
        $transfer_2->datesent(undef)->store;
1562
        $transfer_2->datearrived(undef)->store;
1563
        $transfer_1->datecancelled(undef)->store;
1564
1565
        my $prefetched_item = Koha::Items->search(
1566
            { 'me.itemnumber' => $item->itemnumber },
1567
            { prefetch        => ['current_branchtransfers'] }
1568
        )->next;
1569
1570
        $transfers = $prefetched_item->get_transfers();
1571
        is(
1572
            $transfers->count, 3,
1573
            'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all'
1574
        );
1575
        $result_1 = $transfers->next;
1576
        $result_2 = $transfers->next;
1577
        $result_3 = $transfers->next;
1578
        is(
1579
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1580
            'Koha::Item->get_transfers returns the oldest transfer request first'
1581
        );
1582
        is(
1583
            $result_2->branchtransfer_id, $transfer_2->branchtransfer_id,
1584
            'Koha::Item->get_transfers returns the newer transfer request second'
1585
        );
1586
        is(
1587
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1588
            'Koha::Item->get_transfers returns the newest transfer request last'
1589
        );
1590
1591
        $transfer_2->datesent( \'NOW()' )->store;
1592
        $prefetched_item = Koha::Items->search(
1593
            { 'me.itemnumber' => $item->itemnumber },
1594
            { prefetch        => ['current_branchtransfers'] }
1595
        )->next;
1596
        $transfers = $prefetched_item->get_transfers();
1597
        is(
1598
            $transfers->count, 3,
1599
            'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all'
1600
        );
1601
        $result_1 = $transfers->next;
1602
        $result_2 = $transfers->next;
1603
        $result_3 = $transfers->next;
1604
        is(
1605
            $result_1->branchtransfer_id, $transfer_2->branchtransfer_id,
1606
            'Koha::Item->get_transfers returns the active transfer request first'
1607
        );
1608
        is(
1609
            $result_2->branchtransfer_id, $transfer_1->branchtransfer_id,
1610
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1611
        );
1612
        is(
1613
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1614
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1615
        );
1616
1617
        $transfer_2->datearrived( \'NOW()' )->store;
1618
        $prefetched_item = Koha::Items->search(
1619
            { 'me.itemnumber' => $item->itemnumber },
1620
            { prefetch        => ['current_branchtransfers'] }
1621
        )->next;
1622
        $transfers = $prefetched_item->get_transfers();
1623
        is(
1624
            $transfers->count, 2,
1625
            'Once a transfer is received, it no longer appears in the list from ->get_transfers()'
1626
        );
1627
        $result_1 = $transfers->next;
1628
        $result_2 = $transfers->next;
1629
        is(
1630
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1631
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1632
        );
1633
        is(
1634
            $result_2->branchtransfer_id, $transfer_3->branchtransfer_id,
1635
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1636
        );
1637
1638
        $transfer_1->datecancelled( \'NOW()' )->store;
1639
        $prefetched_item = Koha::Items->search(
1640
            { 'me.itemnumber' => $item->itemnumber },
1641
            { prefetch        => ['current_branchtransfers'] }
1642
        )->next;
1643
        $transfers = $prefetched_item->get_transfers();
1644
        is(
1645
            $transfers->count, 1,
1646
            'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()'
1647
        );
1648
        $result_1 = $transfers->next;
1649
        is(
1650
            $result_1->branchtransfer_id, $transfer_3->branchtransfer_id,
1651
            'Koha::Item->get_transfers returns the only transfer that remains'
1652
        );
1653
    };
1654
1408
    $schema->storage->txn_rollback;
1655
    $schema->storage->txn_rollback;
1409
};
1656
};
1410
1657
1411
- 

Return to bug 35100