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

(-)a/C4/Circulation.pm (-6 / +6 lines)
Lines 2376-2385 sub AddReturn { Link Here
2376
            else {
2376
            else {
2377
                $messages->{'TransferTrigger'} = $transfer->reason;
2377
                $messages->{'TransferTrigger'} = $transfer->reason;
2378
                if ( $transfer->frombranch eq $branch ) {
2378
                if ( $transfer->frombranch eq $branch ) {
2379
                    $transfer->transit;
2379
                    $messages->{'TransferTo'}    = $transfer->tobranch;
2380
                    $messages->{'WasTransfered'}   = $transfer->tobranch;
2380
                    $messages->{'WasTransfered'} = $transfer->id;
2381
                }
2381
                } else {
2382
                else {
2383
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2382
                    $messages->{'WrongTransfer'}     = $transfer->tobranch;
2384
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2383
                    $messages->{'WrongTransferItem'} = $item->itemnumber;
2385
                }
2384
                }
Lines 2529-2536 sub AddReturn { Link Here
2529
            (C4::Context->preference("UseBranchTransferLimits") and
2528
            (C4::Context->preference("UseBranchTransferLimits") and
2530
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2529
             ! IsBranchTransferAllowed($branch, $returnbranch, $item->$BranchTransferLimitsType )
2531
           )) {
2530
           )) {
2532
            ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2531
            my $transfer = ModItemTransfer($item->itemnumber, $branch, $returnbranch, $transfer_trigger, { skip_record_index => 1 });
2533
            $messages->{'WasTransfered'} = $returnbranch;
2532
            $messages->{'TransferTo'} = $returnbranch;
2533
            $messages->{'WasTransfered'} = $transfer->id;
2534
            $messages->{'TransferTrigger'} = $transfer_trigger;
2534
            $messages->{'TransferTrigger'} = $transfer_trigger;
2535
        } else {
2535
        } else {
2536
            $messages->{'NeedsTransfer'} = $returnbranch;
2536
            $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 519-528 my $recalled = 0; Link Here
519
519
520
if ( $messages->{'WasTransfered'} ) {
520
if ( $messages->{'WasTransfered'} ) {
521
    $template->param(
521
    $template->param(
522
        found          => 1,
522
        found      => 1,
523
        transfer       => $messages->{'WasTransfered'},
523
        transfer   => $messages->{'WasTransfered'},
524
        trigger        => $messages->{'TransferTrigger'},
524
        transferto => $messages->{'TransferTo'},
525
        itemnumber     => $itemnumber,
525
        trigger    => $messages->{'TransferTrigger'},
526
        itemnumber => $itemnumber,
526
    );
527
    );
527
}
528
}
528
529
Lines 696-701 foreach my $code ( keys %$messages ) { Link Here
696
    elsif ( $code eq 'WasTransfered' ) {
697
    elsif ( $code eq 'WasTransfered' ) {
697
        ;    # FIXME... anything to do here?
698
        ;    # FIXME... anything to do here?
698
    }
699
    }
700
    elsif ( $code eq 'TransferTo' ) {
701
        ;    # Handled above, along with WasTransfered
702
    }
699
    elsif ( $code eq 'withdrawn' ) {
703
    elsif ( $code eq 'withdrawn' ) {
700
        $err{withdrawn} = 1;
704
        $err{withdrawn} = 1;
701
    }
705
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt (-2 / +3 lines)
Lines 121-127 Link Here
121
                                </div> <!-- /.hold-auto-filled -->
121
                                </div> <!-- /.hold-auto-filled -->
122
                            [% END # /IF hold_auto_filled %]
122
                            [% END # /IF hold_auto_filled %]
123
123
124
                            [% IF ( trigger ) %]
124
                            [% IF ( trigger && !transfertodo ) %]
125
                                 <div id="transfer-trigger" class="dialog message">
125
                                 <div id="transfer-trigger" class="dialog message">
126
                                     <h3>Reason for transfer</h3>
126
                                     <h3>Reason for transfer</h3>
127
                                     <p>
127
                                     <p>
Lines 737-743 Link Here
737
737
738
                                                <div class="modal-header">
738
                                                <div class="modal-header">
739
                                                    <h3>
739
                                                    <h3>
740
                                                        Please return this item to [% IF transfer %][% Branches.GetName( transfer ) | html %][% ELSE %][% Branches.GetName( returnbranch ) | html %][% END %]
740
                                                        Please return this item to [% IF transferto %][% Branches.GetName( transferto ) | html %][% ELSE %][% Branches.GetName( returnbranch ) | html %][% END %]
741
                                                    </h3>
741
                                                    </h3>
742
                                                </div>
742
                                                </div>
743
                                                <div class="modal-body">
743
                                                <div class="modal-body">
Lines 763-768 Link Here
763
                                                        <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>
763
                                                        <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>
764
                                                        <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>
764
                                                        <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>
765
                                                    [% ELSE %]
765
                                                    [% ELSE %]
766
                                                        <input type="hidden" name="transit" value="[% transfer | uri %]"/>
766
                                                        <button type="button" data-dismiss="modal" class="btn btn-default approve" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
767
                                                        <button type="button" data-dismiss="modal" class="btn btn-default approve" accesskey="y"><i class="fa fa-check"></i> OK (Y)</button>
767
                                                        <button type="button" data-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>
768
                                                        <button type="button" data-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>
768
                                                    [% END %]
769
                                                    [% 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 / +99 lines)
Lines 1101-1107 subtest 'Tests for itemtype' => sub { Link Here
1101
};
1101
};
1102
1102
1103
subtest 'get_transfers' => sub {
1103
subtest 'get_transfers' => sub {
1104
    plan tests => 16;
1104
    plan tests => 17;
1105
    $schema->storage->txn_begin;
1105
    $schema->storage->txn_begin;
1106
1106
1107
    my $item = $builder->build_sample_item();
1107
    my $item = $builder->build_sample_item();
Lines 1196-1201 subtest 'get_transfers' => sub { Link Here
1196
    $result_1 = $transfers->next;
1196
    $result_1 = $transfers->next;
1197
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1197
    is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains');
1198
1198
1199
    subtest "Ensure prefetches don't affect the return order" => sub {
1200
        plan tests => 13;
1201
1202
        # Reset test data
1203
        $transfer_2->datesent(undef)->store;
1204
        $transfer_2->datearrived(undef)->store;
1205
        $transfer_1->datecancelled(undef)->store;
1206
1207
        my $prefetched_item = Koha::Items->search(
1208
            { 'me.itemnumber' => $item->itemnumber },
1209
            { prefetch        => ['current_branchtransfers'] }
1210
        )->next;
1211
1212
        $transfers = $prefetched_item->get_transfers();
1213
        is(
1214
            $transfers->count, 3,
1215
            'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all'
1216
        );
1217
        $result_1 = $transfers->next;
1218
        $result_2 = $transfers->next;
1219
        $result_3 = $transfers->next;
1220
        is(
1221
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1222
            'Koha::Item->get_transfers returns the oldest transfer request first'
1223
        );
1224
        is(
1225
            $result_2->branchtransfer_id, $transfer_2->branchtransfer_id,
1226
            'Koha::Item->get_transfers returns the newer transfer request second'
1227
        );
1228
        is(
1229
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1230
            'Koha::Item->get_transfers returns the newest transfer request last'
1231
        );
1232
1233
        $transfer_2->datesent( \'NOW()' )->store;
1234
        $prefetched_item = Koha::Items->search(
1235
            { 'me.itemnumber' => $item->itemnumber },
1236
            { prefetch        => ['current_branchtransfers'] }
1237
        )->next;
1238
        $transfers = $prefetched_item->get_transfers();
1239
        is(
1240
            $transfers->count, 3,
1241
            'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all'
1242
        );
1243
        $result_1 = $transfers->next;
1244
        $result_2 = $transfers->next;
1245
        $result_3 = $transfers->next;
1246
        is(
1247
            $result_1->branchtransfer_id, $transfer_2->branchtransfer_id,
1248
            'Koha::Item->get_transfers returns the active transfer request first'
1249
        );
1250
        is(
1251
            $result_2->branchtransfer_id, $transfer_1->branchtransfer_id,
1252
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1253
        );
1254
        is(
1255
            $result_3->branchtransfer_id, $transfer_3->branchtransfer_id,
1256
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1257
        );
1258
1259
        $transfer_2->datearrived( \'NOW()' )->store;
1260
        $prefetched_item = Koha::Items->search(
1261
            { 'me.itemnumber' => $item->itemnumber },
1262
            { prefetch        => ['current_branchtransfers'] }
1263
        )->next;
1264
        $transfers = $prefetched_item->get_transfers();
1265
        is(
1266
            $transfers->count, 2,
1267
            'Once a transfer is received, it no longer appears in the list from ->get_transfers()'
1268
        );
1269
        $result_1 = $transfers->next;
1270
        $result_2 = $transfers->next;
1271
        is(
1272
            $result_1->branchtransfer_id, $transfer_1->branchtransfer_id,
1273
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1274
        );
1275
        is(
1276
            $result_2->branchtransfer_id, $transfer_3->branchtransfer_id,
1277
            'Koha::Item->get_transfers returns the other transfers oldest to newest'
1278
        );
1279
1280
        $transfer_1->datecancelled( \'NOW()' )->store;
1281
        $prefetched_item = Koha::Items->search(
1282
            { 'me.itemnumber' => $item->itemnumber },
1283
            { prefetch        => ['current_branchtransfers'] }
1284
        )->next;
1285
        $transfers = $prefetched_item->get_transfers();
1286
        is(
1287
            $transfers->count, 1,
1288
            'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()'
1289
        );
1290
        $result_1 = $transfers->next;
1291
        is(
1292
            $result_1->branchtransfer_id, $transfer_3->branchtransfer_id,
1293
            'Koha::Item->get_transfers returns the only transfer that remains'
1294
        );
1295
    };
1296
1199
    $schema->storage->txn_rollback;
1297
    $schema->storage->txn_rollback;
1200
};
1298
};
1201
1299
1202
- 

Return to bug 35100