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

(-)a/C4/HoldsQueue.pm (+11 lines)
Lines 409-414 sub MapItemsToHoldRequests { Link Here
409
                  || ( $item->{holdallowed} == 1
409
                  || ( $item->{holdallowed} == 1
410
                    && $item->{homebranch} ne $request->{borrowerbranch} );
410
                    && $item->{homebranch} ne $request->{borrowerbranch} );
411
411
412
                next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
413
412
                my $local_holds_priority_item_branchcode =
414
                my $local_holds_priority_item_branchcode =
413
                  $item->{$LocalHoldsPriorityItemControl};
415
                  $item->{$LocalHoldsPriorityItemControl};
414
416
Lines 463-468 sub MapItemsToHoldRequests { Link Here
463
                and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
465
                and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
464
                    || $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} )
466
                    || $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} )
465
                )
467
                )
468
                and Koha::Items->find( $request->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } )
466
469
467
              )
470
              )
468
            {
471
            {
Lines 510-515 sub MapItemsToHoldRequests { Link Here
510
        my $holding_branch_items = $items_by_branch{$pickup_branch};
513
        my $holding_branch_items = $items_by_branch{$pickup_branch};
511
        if ( $holding_branch_items ) {
514
        if ( $holding_branch_items ) {
512
            foreach my $item (@$holding_branch_items) {
515
            foreach my $item (@$holding_branch_items) {
516
                next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
517
513
                if (
518
                if (
514
                    $request->{borrowerbranch} eq $item->{homebranch}
519
                    $request->{borrowerbranch} eq $item->{homebranch}
515
                    && ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time
520
                    && ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time
Lines 532-537 sub MapItemsToHoldRequests { Link Here
532
                my $holding_branch_items = $items_by_branch{$holdingbranch};
537
                my $holding_branch_items = $items_by_branch{$holdingbranch};
533
                foreach my $item (@$holding_branch_items) {
538
                foreach my $item (@$holding_branch_items) {
534
                    next if $request->{borrowerbranch} ne $item->{homebranch};
539
                    next if $request->{borrowerbranch} ne $item->{homebranch};
540
                    next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraris->find( $request->{branchcode} ) } );
535
541
536
                    # Don't fill item level holds that contravene the hold pickup policy at this time
542
                    # Don't fill item level holds that contravene the hold pickup policy at this time
537
                    next unless $item->{hold_fulfillment_policy} eq 'any'
543
                    next unless $item->{hold_fulfillment_policy} eq 'any'
Lines 568-573 sub MapItemsToHoldRequests { Link Here
568
                foreach my $item (@$holding_branch_items) {
574
                foreach my $item (@$holding_branch_items) {
569
                    next if $pickup_branch ne $item->{homebranch};
575
                    next if $pickup_branch ne $item->{homebranch};
570
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
576
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
577
                    next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
571
578
572
                    # Don't fill item level holds that contravene the hold pickup policy at this time
579
                    # Don't fill item level holds that contravene the hold pickup policy at this time
573
                    next unless $item->{hold_fulfillment_policy} eq 'any'
580
                    next unless $item->{hold_fulfillment_policy} eq 'any'
Lines 596-601 sub MapItemsToHoldRequests { Link Here
596
                        next unless ( !$request->{itemtype}
603
                        next unless ( !$request->{itemtype}
597
                            || $current_item->{itype} eq $request->{itemtype} );
604
                            || $current_item->{itype} eq $request->{itemtype} );
598
605
606
                        next unless Koha::Items->find( $current_item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
607
599
                        $itemnumber = $current_item->{itemnumber};
608
                        $itemnumber = $current_item->{itemnumber};
600
                        last; # quit this loop as soon as we have a suitable item
609
                        last; # quit this loop as soon as we have a suitable item
601
                    }
610
                    }
Lines 620-625 sub MapItemsToHoldRequests { Link Here
620
                        next unless ( !$request->{itemtype}
629
                        next unless ( !$request->{itemtype}
621
                            || $item->{itype} eq $request->{itemtype} );
630
                            || $item->{itype} eq $request->{itemtype} );
622
631
632
                        next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
633
623
                        $itemnumber = $item->{itemnumber};
634
                        $itemnumber = $item->{itemnumber};
624
                        $holdingbranch = $branch;
635
                        $holdingbranch = $branch;
625
                        last PULL_BRANCHES2;
636
                        last PULL_BRANCHES2;
(-)a/C4/ILSDI/Services.pm (-4 / +8 lines)
Lines 691-696 sub HoldTitle { Link Here
691
        $branch = $patron->branchcode;
691
        $branch = $patron->branchcode;
692
    }
692
    }
693
693
694
    my $destination = Koha::Libraries->find($branch);
695
    return { code => 'libraryNotPickupLocation' } unless $destination->pickup_location;
696
    return { code => 'cannotBeTransferred' } unless $biblio->can_be_transferred({ to => $destination });
697
694
    # Add the reserve
698
    # Add the reserve
695
    #    $branch,    $borrowernumber, $biblionumber,
699
    #    $branch,    $borrowernumber, $biblionumber,
696
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
700
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
Lines 754-763 sub HoldItem { Link Here
754
    # If the biblio does not match the item, return an error code
758
    # If the biblio does not match the item, return an error code
755
    return { code => 'RecordNotFound' } if $item->biblionumber ne $biblio->biblionumber;
759
    return { code => 'RecordNotFound' } if $item->biblionumber ne $biblio->biblionumber;
756
760
757
    # Check for item disponibility
758
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber )->{status};
759
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
760
761
    # Pickup branch management
761
    # Pickup branch management
762
    my $branch;
762
    my $branch;
763
    if ( $cgi->param('pickup_location') ) {
763
    if ( $cgi->param('pickup_location') ) {
Lines 767-772 sub HoldItem { Link Here
767
        $branch = $patron->branchcode;
767
        $branch = $patron->branchcode;
768
    }
768
    }
769
769
770
    # Check for item disponibility
771
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber, $branch )->{status};
772
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
773
770
    # Add the reserve
774
    # Add the reserve
771
    #    $branch,    $borrowernumber, $biblionumber,
775
    #    $branch,    $borrowernumber, $biblionumber,
772
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
776
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
(-)a/C4/Reserves.pm (-15 / +25 lines)
Lines 23-59 package C4::Reserves; Link Here
23
23
24
use strict;
24
use strict;
25
#use warnings; FIXME - Bug 2505
25
#use warnings; FIXME - Bug 2505
26
use C4::Context;
26
use C4::Accounts;
27
use C4::Biblio;
27
use C4::Biblio;
28
use C4::Members;
29
use C4::Items;
30
use C4::Circulation;
28
use C4::Circulation;
31
use C4::Accounts;
29
use C4::Context;
30
use C4::Items;
31
use C4::Members;
32
32
33
# for _koha_notify_reserve
33
# for _koha_notify_reserve
34
use C4::Members::Messaging;
35
use C4::Members qw();
36
use C4::Letters;
34
use C4::Letters;
37
use C4::Log;
35
use C4::Log;
36
use C4::Members qw();
37
use C4::Members::Messaging;
38
38
39
use Koha::Account::Lines;
39
use Koha::Biblios;
40
use Koha::Biblios;
40
use Koha::DateUtils;
41
use Koha::Calendar;
41
use Koha::Calendar;
42
use Koha::CirculationRules;
42
use Koha::Database;
43
use Koha::Database;
44
use Koha::DateUtils;
43
use Koha::Hold;
45
use Koha::Hold;
44
use Koha::Old::Hold;
45
use Koha::Holds;
46
use Koha::Holds;
46
use Koha::Libraries;
47
use Koha::IssuingRules;
47
use Koha::IssuingRules;
48
use Koha::Items;
49
use Koha::ItemTypes;
48
use Koha::ItemTypes;
49
use Koha::Items;
50
use Koha::Libraries;
51
use Koha::Libraries;
52
use Koha::Old::Hold;
50
use Koha::Patrons;
53
use Koha::Patrons;
51
use Koha::CirculationRules;
52
use Koha::Account::Lines;
53
54
54
use List::MoreUtils qw( firstidx any );
55
use Carp;
55
use Carp;
56
use Data::Dumper;
56
use Data::Dumper;
57
use List::MoreUtils qw( firstidx any );
57
58
58
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
59
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
59
60
Lines 482-488 sub CanItemBeReserved { Link Here
482
            return { status => 'libraryNotPickupLocation' };
483
            return { status => 'libraryNotPickupLocation' };
483
        }
484
        }
484
        unless ($item->can_be_transferred({ to => $destination })) {
485
        unless ($item->can_be_transferred({ to => $destination })) {
485
            return 'cannotBeTransferred';
486
            return { status => 'cannotBeTransferred' };
486
        }
487
        }
487
    }
488
    }
488
489
Lines 801-806 sub CheckReserves { Link Here
801
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
802
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
802
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
803
                    my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy};
803
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
804
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) );
805
                    next unless $item->can_be_transferred( { to => scalar Koha::Libraries->find( $res->{branchcode} ) } );
804
                    $priority = $res->{'priority'};
806
                    $priority = $res->{'priority'};
805
                    $highest  = $res;
807
                    $highest  = $res;
806
                    last if $local_hold_match;
808
                    last if $local_hold_match;
Lines 1140-1146 sub ModReserveMinusPriority { Link Here
1140
1142
1141
=head2 IsAvailableForItemLevelRequest
1143
=head2 IsAvailableForItemLevelRequest
1142
1144
1143
  my $is_available = IsAvailableForItemLevelRequest($item_record,$borrower_record);
1145
  my $is_available = IsAvailableForItemLevelRequest( $item_record, $borrower_record, $pickup_branchcode );
1144
1146
1145
Checks whether a given item record is available for an
1147
Checks whether a given item record is available for an
1146
item-level hold request.  An item is available if
1148
item-level hold request.  An item is available if
Lines 1165-1170 and canreservefromotherbranches. Link Here
1165
sub IsAvailableForItemLevelRequest {
1167
sub IsAvailableForItemLevelRequest {
1166
    my $item = shift;
1168
    my $item = shift;
1167
    my $borrower = shift;
1169
    my $borrower = shift;
1170
    my $pickup_branchcode = shift;
1168
1171
1169
    my $dbh = C4::Context->dbh;
1172
    my $dbh = C4::Context->dbh;
1170
    # must check the notforloan setting of the itemtype
1173
    # must check the notforloan setting of the itemtype
Lines 1187-1192 sub IsAvailableForItemLevelRequest { Link Here
1187
1190
1188
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
1191
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
1189
1192
1193
    if ($pickup_branchcode) {
1194
        my $destination = Koha::Libraries->find($pickup_branchcode);
1195
        return 0 unless $destination;
1196
        return 0 unless $destination->pickup_location;
1197
        return 0 unless $item_object->can_be_transferred( { to => $destination } );
1198
    }
1199
1190
    if ( $on_shelf_holds == 1 ) {
1200
    if ( $on_shelf_holds == 1 ) {
1191
        return 1;
1201
        return 1;
1192
    } elsif ( $on_shelf_holds == 2 ) {
1202
    } elsif ( $on_shelf_holds == 2 ) {
(-)a/C4/SIP/ILS/Transaction/Hold.pm (+6 lines)
Lines 60-65 sub do_hold { Link Here
60
        $self->ok(0);
60
        $self->ok(0);
61
        return $self;
61
        return $self;
62
    }
62
    }
63
    unless ( $item->can_be_transferred( { to => scalar Koha::Libraries->find( $branch ) } ) ) {
64
        $self->screen_msg('Item cannot be transferred.');
65
        $self->ok(0);
66
        return $self;
67
    }
68
63
    AddReserve( $branch, $patron->borrowernumber, $item->biblionumber );
69
    AddReserve( $branch, $patron->borrowernumber, $item->biblionumber );
64
70
65
    # unfortunately no meaningful return value
71
    # unfortunately no meaningful return value
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-1 / +15 lines)
Lines 199-205 Link Here
199
        <li>
199
        <li>
200
            <label for="pickup">Pickup at:</label>
200
            <label for="pickup">Pickup at:</label>
201
            <select name="pickup" size="1" id="pickup">
201
            <select name="pickup" size="1" id="pickup">
202
                [% PROCESS options_for_libraries libraries => Branches.all({ search_params => { pickup_location => 1 } }) %]
202
                [% PROCESS options_for_libraries libraries => Branches.all({ selected => pickup, search_params => { pickup_location => 1 } }) %]
203
            </select>
203
            </select>
204
        </li>
204
        </li>
205
205
Lines 340-345 Link Here
340
                                Patron is from different library
340
                                Patron is from different library
341
                            [% ELSIF itemloo.not_holdable == 'itemAlreadyOnHold' %]
341
                            [% ELSIF itemloo.not_holdable == 'itemAlreadyOnHold' %]
342
                                Patron already has hold for this item
342
                                Patron already has hold for this item
343
                            [% ELSIF itemloo.not_holdable == 'cannotBeTransferred' %]
344
                                Cannot be transferred to pickup library
343
                            [% ELSE %]
345
                            [% ELSE %]
344
                                [% itemloo.not_holdable | html %]
346
                                [% itemloo.not_holdable | html %]
345
                            [% END %]
347
                            [% END %]
Lines 660-665 Link Here
660
    [% INCLUDE 'calendar.inc' %]
662
    [% INCLUDE 'calendar.inc' %]
661
    [% Asset.js("js/circ-patron-search-results.js") | $raw %]
663
    [% Asset.js("js/circ-patron-search-results.js") | $raw %]
662
    <script>
664
    <script>
665
        var biblionumber = "[% biblionumber %]";
666
        var borrowernumber = "[% patron.borrowernumber %]";
663
        var MSG_CONFIRM_DELETE_HOLD   = _("Are you sure you want to cancel this hold?");
667
        var MSG_CONFIRM_DELETE_HOLD   = _("Are you sure you want to cancel this hold?");
664
        var patron_homebranch = "[% Branches.GetName( patron.branchcode ) |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
668
        var patron_homebranch = "[% Branches.GetName( patron.branchcode ) |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
665
        var override_items = {[% FOREACH bibitemloo IN bibitemloop %][% FOREACH itemloo IN bibitemloo.itemloop %][% IF ( itemloo.override ) %]
669
        var override_items = {[% FOREACH bibitemloo IN bibitemloop %][% FOREACH itemloo IN bibitemloo.itemloop %][% IF ( itemloo.override ) %]
Lines 684-689 Link Here
684
                ToggleHoldsToPlace();
688
                ToggleHoldsToPlace();
685
            });
689
            });
686
690
691
            [% IF Koha.Preference('UseBranchTransferLimits') %]
692
                $("#pickup").on('change', function(){
693
                    var pickup = $("#pickup").val();
694
                    var url = "?pickup=" + pickup;
695
                    url += "&borrowernumber=" + borrowernumber;
696
                    url += "&biblionumber=" + biblionumber;
697
                    window.location.replace(url);
698
                });
699
            [% END %]
700
687
            [% IF AutoResumeSuspendedHolds %]
701
            [% IF AutoResumeSuspendedHolds %]
688
                $(".suspend_until_datepicker, .datepickerfrom, .datepickerto").datepicker("option", "minDate", 1);
702
                $(".suspend_until_datepicker, .datepickerfrom, .datepickerto").datepicker("option", "minDate", 1);
689
            [% END %]
703
            [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/circ-patron-search-results.js (-7 / +7 lines)
Lines 3-13 $(document).ready(function() { Link Here
3
    $(".clickable").click(function() {
3
    $(".clickable").click(function() {
4
        window.document.location = $(this).data('url');
4
        window.document.location = $(this).data('url');
5
    });
5
    });
6
    var table = KohaTable("table_borrowers",
6
//    var table = KohaTable("table_borrowers",
7
        {
7
//        {
8
            "aaSorting": [ 0, "asc" ],
8
//            "aaSorting": [ 0, "asc" ],
9
            "sDom": "t",
9
//            "sDom": "t",
10
            "iDisplayLength": -1
10
//            "iDisplayLength": -1
11
        },
11
//        },
12
        columns_settings_borrowers_table, null);
12
//        columns_settings_borrowers_table, null);
13
});
13
});
(-)a/reserve/request.pl (-2 / +4 lines)
Lines 67-72 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user( Link Here
67
);
67
);
68
68
69
my $showallitems = $input->param('showallitems');
69
my $showallitems = $input->param('showallitems');
70
my $pickup = $input->param('pickup') || C4::Context->userenv->{'branch'};
70
71
71
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
72
my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
72
73
Lines 221-227 foreach my $biblionumber (@biblionumbers) { Link Here
221
    my $force_hold_level;
222
    my $force_hold_level;
222
    if ( $patron ) {
223
    if ( $patron ) {
223
        { # CanBookBeReserved
224
        { # CanBookBeReserved
224
            my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
225
            my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber, $pickup );
225
            if ( $canReserve->{status} eq 'OK' ) {
226
            if ( $canReserve->{status} eq 'OK' ) {
226
227
227
                #All is OK and we can continue
228
                #All is OK and we can continue
Lines 472-478 foreach my $biblionumber (@biblionumbers) { Link Here
472
473
473
                $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
474
                $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
474
475
475
                my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber );
476
                my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber, $pickup );
476
                $item->{not_holdable} = $can_item_be_reserved->{status} unless ( $can_item_be_reserved->{status} eq 'OK' );
477
                $item->{not_holdable} = $can_item_be_reserved->{status} unless ( $can_item_be_reserved->{status} eq 'OK' );
477
478
478
                $item->{item_level_holds} = Koha::IssuingRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
479
                $item->{item_level_holds} = Koha::IssuingRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
Lines 645-650 $template->param( biblionumbers => $biblionumbers ); Link Here
645
$template->param( exceeded_maxreserves => $exceeded_maxreserves );
646
$template->param( exceeded_maxreserves => $exceeded_maxreserves );
646
$template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
647
$template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
647
$template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));
648
$template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));
649
$template->param( pickup => $pickup );
648
650
649
if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
651
if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
650
    $template->param( reserve_in_future => 1 );
652
    $template->param( reserve_in_future => 1 );
(-)a/t/db_dependent/Holds/HoldFulfillmentPolicy.t (-1 / +19 lines)
Lines 4-12 use Modern::Perl; Link Here
4
4
5
use C4::Context;
5
use C4::Context;
6
6
7
use Test::More tests => 10;
7
use Test::More tests => 11;
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
use t::lib::Mocks;
10
use Koha::Holds;
11
use Koha::Holds;
11
12
12
BEGIN {
13
BEGIN {
Lines 137-139 $reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 ); Link Here
137
( $status ) = CheckReserves($itemnumber);
138
( $status ) = CheckReserves($itemnumber);
138
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
139
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
139
Koha::Holds->find( $reserve_id )->cancel;
140
Koha::Holds->find( $reserve_id )->cancel;
141
142
# Test enforement of branch transfer limits
143
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
144
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
145
Koha::Holds->search()->delete();
146
my ($item) = Koha::Biblios->find($biblionumber)->items;
147
my $limit = Koha::Item::Transfer::Limit->new(
148
    {
149
        toBranch   => $library_C,
150
        fromBranch => $item->holdingbranch,
151
        itemtype   => $item->effective_itemtype,
152
    }
153
)->store();
154
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
155
($status) = CheckReserves($itemnumber);
156
is( $status, '',  "No hold where branch transfer is not allowed" );
157
Koha::Holds->find($reserve_id)->cancel;
(-)a/t/db_dependent/HoldsQueue.t (-2 / +72 lines)
Lines 8-14 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 44;
11
use Test::More tests => 48;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Calendar;
14
use C4::Calendar;
Lines 35-40 my $dbh = C4::Context->dbh; Link Here
35
35
36
my $builder = t::lib::TestBuilder->new;
36
my $builder = t::lib::TestBuilder->new;
37
37
38
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '0' );
39
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
40
38
my $library1 = $builder->build({
41
my $library1 = $builder->build({
39
    source => 'Branch',
42
    source => 'Branch',
40
});
43
});
Lines 358-363 C4::HoldsQueue::CreateQueue(); Link Here
358
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
361
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
359
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library");
362
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library");
360
363
364
### Test branch transfer limits ###
365
t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
366
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
367
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
368
C4::Context->clear_syspref_cache();
369
$dbh->do("DELETE FROM reserves");
370
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
371
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[1], 2 );
372
373
$dbh->do("DELETE FROM items");
374
# barcode, homebranch, holdingbranch, itemtype
375
$items_insert_sth->execute( $barcode, $branchcodes[2], $branchcodes[2] );
376
my $item = Koha::Items->find( { barcode => $barcode } );
377
378
my $limit1 = Koha::Item::Transfer::Limit->new(
379
    {
380
        toBranch   => $branchcodes[0],
381
        fromBranch => $branchcodes[2],
382
        itemtype   => $item->effective_itemtype,
383
    }
384
)->store();
385
386
C4::HoldsQueue::CreateQueue();
387
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
388
is( $holds_queue->[0]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue skips hold transfer that would violate branch transfer limits");
389
390
my $limit2 = Koha::Item::Transfer::Limit->new(
391
    {
392
        toBranch   => $branchcodes[1],
393
        fromBranch => $branchcodes[2],
394
        itemtype   => $item->effective_itemtype,
395
    }
396
)->store();
397
398
C4::HoldsQueue::CreateQueue();
399
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
400
is( $holds_queue->[0]->{cardnumber}, undef, "Holds queue doesn't fill hold where all available items would violate branch transfer limits");
401
402
$limit1->delete();
403
$limit2->delete();
404
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' );
405
### END Test branch transfer limits ###
406
361
# Test holdingbranch = patron branch
407
# Test holdingbranch = patron branch
362
t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
408
t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
363
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
409
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
Lines 706-712 $dbh->do("DELETE FROM default_branch_item_rules"); Link Here
706
$dbh->do("DELETE FROM default_circ_rules");
752
$dbh->do("DELETE FROM default_circ_rules");
707
$dbh->do("DELETE FROM branch_item_rules");
753
$dbh->do("DELETE FROM branch_item_rules");
708
754
709
my $item = Koha::Items->find( { biblionumber => $biblionumber } );
755
$item = Koha::Items->find( { biblionumber => $biblionumber } );
710
$item->holdingbranch( $item->homebranch );
756
$item->holdingbranch( $item->homebranch );
711
$item->store();
757
$item->store();
712
758
Lines 759-764 sub test_queue { Link Here
759
    diag( "Wrong pick-up/hold for first target (pick_branch, hold_branch, reserves, hold_fill_targets, tmp_holdsqueue): "
805
    diag( "Wrong pick-up/hold for first target (pick_branch, hold_branch, reserves, hold_fill_targets, tmp_holdsqueue): "
760
        . Dumper ($pick_branch, $hold_branch, map dump_records($_), qw(reserves hold_fill_targets tmp_holdsqueue)) )
806
        . Dumper ($pick_branch, $hold_branch, map dump_records($_), qw(reserves hold_fill_targets tmp_holdsqueue)) )
761
      unless $ok;
807
      unless $ok;
808
809
    # Test enforcement of branch transfer limit
810
    if ( $r->{pickbranch} ne $r->{holdingbranch} ) {
811
        t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
812
        my $limit = Koha::Item::Transfer::Limit->new(
813
            {
814
                toBranch   => $r->{pickbranch},
815
                fromBranch => $r->{holdingbranch},
816
                itemtype   => $r->{itype},
817
            }
818
        )->store();
819
        C4::Context->clear_syspref_cache();
820
        C4::HoldsQueue::CreateQueue();
821
        $results = $dbh->selectall_arrayref( $test_sth, { Slice => {} } )
822
          ;    # should be only one
823
        my $s = $results->[0];
824
        isnt( $r->{holdingbranch}, $s->{holdingbranch}, 'Hold is not trapped for pickup at a branch that cannot be transferred to');
825
826
        $limit->delete();
827
        t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' );
828
        C4::Context->clear_syspref_cache();
829
        C4::HoldsQueue::CreateQueue();
830
    }
831
762
}
832
}
763
833
764
sub dump_records {
834
sub dump_records {
(-)a/t/db_dependent/ILSDI_Services.t (-1 / +94 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
use Test::MockModule;
23
use Test::MockModule;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 447-449 subtest 'Holds test' => sub { Link Here
447
447
448
    $schema->storage->txn_rollback;
448
    $schema->storage->txn_rollback;
449
};
449
};
450
451
subtest 'Holds test for branch transfer limits' => sub {
452
453
    plan tests => 4;
454
455
    $schema->storage->txn_begin;
456
457
    # Test enforement of branch transfer limits
458
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
459
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
460
461
    my $patron = $builder->build({
462
        source => 'Borrower',
463
    });
464
465
    my $origin_branch = $builder->build(
466
        {
467
            source => 'Branch',
468
            value  => {
469
                pickup_location => 1,
470
            }
471
        }
472
    );
473
    my $pickup_branch = $builder->build(
474
        {
475
            source => 'Branch',
476
            value  => {
477
                pickup_location => 1,
478
            }
479
        }
480
    );
481
482
    my $biblio = $builder->build({
483
        source => 'Biblio',
484
    });
485
    my $biblioitem = $builder->build({
486
        source => 'Biblioitem',
487
        value => {
488
            biblionumber => $biblio->{biblionumber},
489
        }
490
    });
491
    my $item = $builder->build({
492
        source => 'Item',
493
        value => {
494
            homebranch => $origin_branch->{branchcode},
495
            holdingbranch => $origin_branch->{branchcode},
496
            biblionumber => $biblio->{biblionumber},
497
            damaged => 0,
498
            itemlost => 0,
499
        }
500
    });
501
502
    Koha::IssuingRules->search()->delete();
503
    my $issuingrule = $builder->build({
504
        source => 'Issuingrule',
505
        value => {
506
            categorycode => '*',
507
            itemtype => '*',
508
            branchcode => '*',
509
            reservesallowed => 99,
510
        }
511
    });
512
513
    my $limit = Koha::Item::Transfer::Limit->new({
514
        toBranch => $pickup_branch->{branchcode},
515
        fromBranch => $item->{holdingbranch},
516
        itemtype => $item->{itype},
517
    })->store();
518
519
    my $query = new CGI;
520
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
521
    $query->param( 'patron_id', $patron->{borrowernumber});
522
    $query->param( 'bib_id', $biblio->{biblionumber});
523
    $query->param( 'item_id', $item->{itemnumber});
524
525
    my $reply = C4::ILSDI::Services::HoldItem( $query );
526
    is( $reply->{code}, 'cannotBeTransferred', "Item hold, Item cannot be transferred" );
527
528
    $reply = C4::ILSDI::Services::HoldTitle( $query );
529
    is( $reply->{code}, 'cannotBeTransferred', "Record hold, Item cannot be transferred" );
530
531
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' );
532
533
    $reply = C4::ILSDI::Services::HoldItem( $query );
534
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
535
536
    Koha::Holds->search()->delete();
537
538
    $reply = C4::ILSDI::Services::HoldTitle( $query );
539
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
540
541
    $schema->storage->txn_rollback;
542
}
(-)a/t/db_dependent/Reserves.t (-1 / +14 lines)
Lines 524-529 $item = Koha::Items->find($itemnumber)->unblessed; Link Here
524
524
525
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
525
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
526
526
527
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
528
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
529
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
530
my ($item_object) = Koha::Biblios->find($biblionumber)->items;
531
my $limit = Koha::Item::Transfer::Limit->new(
532
    {
533
        toBranch   => $pickup_branch,
534
        fromBranch => $item_object->holdingbranch,
535
        itemtype   => $item_object->effective_itemtype,
536
    }
537
)->store();
538
is( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower, $pickup_branch), 0, "Item level request not available due to transfer limit" );
539
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '0' );
540
527
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
541
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
528
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
542
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
529
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
543
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
530
- 

Return to bug 22330