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

(-)a/C4/HoldsQueue.pm (+11 lines)
Lines 408-413 sub MapItemsToHoldRequests { Link Here
408
                  || ( $item->{holdallowed} == 1
408
                  || ( $item->{holdallowed} == 1
409
                    && $item->{homebranch} ne $request->{borrowerbranch} );
409
                    && $item->{homebranch} ne $request->{borrowerbranch} );
410
410
411
                next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
412
411
                my $local_holds_priority_item_branchcode =
413
                my $local_holds_priority_item_branchcode =
412
                  $item->{$LocalHoldsPriorityItemControl};
414
                  $item->{$LocalHoldsPriorityItemControl};
413
415
Lines 462-467 sub MapItemsToHoldRequests { Link Here
462
                and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
464
                and ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
463
                    || $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} )
465
                    || $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} )
464
                )
466
                )
467
                and Koha::Items->find( $request->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } )
465
468
466
              )
469
              )
467
            {
470
            {
Lines 509-514 sub MapItemsToHoldRequests { Link Here
509
        my $holding_branch_items = $items_by_branch{$pickup_branch};
512
        my $holding_branch_items = $items_by_branch{$pickup_branch};
510
        if ( $holding_branch_items ) {
513
        if ( $holding_branch_items ) {
511
            foreach my $item (@$holding_branch_items) {
514
            foreach my $item (@$holding_branch_items) {
515
                next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
516
512
                if (
517
                if (
513
                    $request->{borrowerbranch} eq $item->{homebranch}
518
                    $request->{borrowerbranch} eq $item->{homebranch}
514
                    && ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time
519
                    && ( ( $item->{hold_fulfillment_policy} eq 'any' ) # Don't fill item level holds that contravene the hold pickup policy at this time
Lines 531-536 sub MapItemsToHoldRequests { Link Here
531
                my $holding_branch_items = $items_by_branch{$holdingbranch};
536
                my $holding_branch_items = $items_by_branch{$holdingbranch};
532
                foreach my $item (@$holding_branch_items) {
537
                foreach my $item (@$holding_branch_items) {
533
                    next if $request->{borrowerbranch} ne $item->{homebranch};
538
                    next if $request->{borrowerbranch} ne $item->{homebranch};
539
                    next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraris->find( $request->{branchcode} ) } );
534
540
535
                    # Don't fill item level holds that contravene the hold pickup policy at this time
541
                    # Don't fill item level holds that contravene the hold pickup policy at this time
536
                    next unless $item->{hold_fulfillment_policy} eq 'any'
542
                    next unless $item->{hold_fulfillment_policy} eq 'any'
Lines 567-572 sub MapItemsToHoldRequests { Link Here
567
                foreach my $item (@$holding_branch_items) {
573
                foreach my $item (@$holding_branch_items) {
568
                    next if $pickup_branch ne $item->{homebranch};
574
                    next if $pickup_branch ne $item->{homebranch};
569
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
575
                    next if ( $item->{holdallowed} == 1 && $item->{homebranch} ne $request->{borrowerbranch} );
576
                    next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
570
577
571
                    # Don't fill item level holds that contravene the hold pickup policy at this time
578
                    # Don't fill item level holds that contravene the hold pickup policy at this time
572
                    next unless $item->{hold_fulfillment_policy} eq 'any'
579
                    next unless $item->{hold_fulfillment_policy} eq 'any'
Lines 594-599 sub MapItemsToHoldRequests { Link Here
594
                        # If hold itemtype is set, item's itemtype must match
601
                        # If hold itemtype is set, item's itemtype must match
595
                        next unless ( !$request->{itemtype}
602
                        next unless ( !$request->{itemtype}
596
                            || $current_item->{itype} eq $request->{itemtype} );
603
                            || $current_item->{itype} eq $request->{itemtype} );
604
                    
605
                        next unless Koha::Items->find( $current_item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
597
606
598
                        $itemnumber = $current_item->{itemnumber};
607
                        $itemnumber = $current_item->{itemnumber};
599
                        last; # quit this loop as soon as we have a suitable item
608
                        last; # quit this loop as soon as we have a suitable item
Lines 619-624 sub MapItemsToHoldRequests { Link Here
619
                        next unless ( !$request->{itemtype}
628
                        next unless ( !$request->{itemtype}
620
                            || $item->{itype} eq $request->{itemtype} );
629
                            || $item->{itype} eq $request->{itemtype} );
621
630
631
                        next unless Koha::Items->find( $item->{itemnumber} )->can_be_transferred( { to => scalar Koha::Libraries->find( $request->{branchcode} ) } );
632
622
                        $itemnumber = $item->{itemnumber};
633
                        $itemnumber = $item->{itemnumber};
623
                        $holdingbranch = $branch;
634
                        $holdingbranch = $branch;
624
                        last PULL_BRANCHES2;
635
                        last PULL_BRANCHES2;
(-)a/C4/ILSDI/Services.pm (-4 / +8 lines)
Lines 676-681 sub HoldTitle { Link Here
676
        $branch = $patron->branchcode;
676
        $branch = $patron->branchcode;
677
    }
677
    }
678
678
679
    my $destination = Koha::Libraries->find($branch);
680
    return { code => 'libraryNotPickupLocation' } unless $destination->pickup_location;
681
    return { code => 'cannotBeTransferred' } unless $biblio->can_be_transferred({ to => $destination });
682
679
    # Add the reserve
683
    # Add the reserve
680
    #    $branch,    $borrowernumber, $biblionumber,
684
    #    $branch,    $borrowernumber, $biblionumber,
681
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
685
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
Lines 739-748 sub HoldItem { Link Here
739
    # If the biblio does not match the item, return an error code
743
    # If the biblio does not match the item, return an error code
740
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
744
    return { code => 'RecordNotFound' } if $$item{biblionumber} ne $biblio->biblionumber;
741
745
742
    # Check for item disponibility
743
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber )->{status};
744
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
745
746
    # Pickup branch management
746
    # Pickup branch management
747
    my $branch;
747
    my $branch;
748
    if ( $cgi->param('pickup_location') ) {
748
    if ( $cgi->param('pickup_location') ) {
Lines 752-757 sub HoldItem { Link Here
752
        $branch = $patron->branchcode;
752
        $branch = $patron->branchcode;
753
    }
753
    }
754
754
755
    # Check for item disponibility
756
    my $canitembereserved = C4::Reserves::CanItemBeReserved( $borrowernumber, $itemnumber, $branch )->{status};
757
    return { code => $canitembereserved } unless $canitembereserved eq 'OK';
758
755
    # Add the reserve
759
    # Add the reserve
756
    #    $branch,    $borrowernumber, $biblionumber,
760
    #    $branch,    $borrowernumber, $biblionumber,
757
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
761
    #    $constraint, $bibitems,  $priority, $resdate, $expdate, $notes,
(-)a/C4/Reserves.pm (-15 / +29 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 484-490 sub CanItemBeReserved { Link Here
484
            return { status => 'libraryNotPickupLocation' };
485
            return { status => 'libraryNotPickupLocation' };
485
        }
486
        }
486
        unless ($item->can_be_transferred({ to => $destination })) {
487
        unless ($item->can_be_transferred({ to => $destination })) {
487
            return 'cannotBeTransferred';
488
            return { status => 'cannotBeTransferred' };
488
        }
489
        }
489
    }
490
    }
490
491
Lines 777-787 sub CheckReserves { Link Here
777
            } else {
778
            } else {
778
                my $patron;
779
                my $patron;
779
                my $iteminfo;
780
                my $iteminfo;
781
                my $item;
780
                my $local_hold_match;
782
                my $local_hold_match;
781
783
782
                if ($LocalHoldsPriority) {
784
                if ($LocalHoldsPriority) {
783
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
785
                    $patron = Koha::Patrons->find( $res->{borrowernumber} );
784
                    $iteminfo = C4::Items::GetItem($itemnumber);
786
                    $iteminfo = C4::Items::GetItem($itemnumber);
787
                    $item = Koha::Items->find( $itemnumber );
785
788
786
                    my $local_holds_priority_item_branchcode =
789
                    my $local_holds_priority_item_branchcode =
787
                      $iteminfo->{$LocalHoldsPriorityItemControl};
790
                      $iteminfo->{$LocalHoldsPriorityItemControl};
Lines 799-804 sub CheckReserves { Link Here
799
                # See if this item is more important than what we've got so far
802
                # See if this item is more important than what we've got so far
800
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
803
                if ( ( $res->{'priority'} && $res->{'priority'} < $priority ) || $local_hold_match ) {
801
                    $iteminfo ||= C4::Items::GetItem($itemnumber);
804
                    $iteminfo ||= C4::Items::GetItem($itemnumber);
805
                    my $item ||= Koha::Items->find( $itemnumber );
806
802
                    next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
807
                    next if $res->{itemtype} && $res->{itemtype} ne _get_itype( $iteminfo );
803
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
808
                    $patron ||= Koha::Patrons->find( $res->{borrowernumber} );
804
                    my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
809
                    my $branch = GetReservesControlBranch( $iteminfo, $patron->unblessed );
Lines 806-811 sub CheckReserves { Link Here
806
                    next if ($branchitemrule->{'holdallowed'} == 0);
811
                    next if ($branchitemrule->{'holdallowed'} == 0);
807
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
812
                    next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode));
808
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
813
                    next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $iteminfo->{ $branchitemrule->{hold_fulfillment_policy} }) );
814
                    next unless $item->can_be_transferred( { to => scalar Koha::Libraries->find( $res->{branchcode} ) } );
809
                    $priority = $res->{'priority'};
815
                    $priority = $res->{'priority'};
810
                    $highest  = $res;
816
                    $highest  = $res;
811
                    last if $local_hold_match;
817
                    last if $local_hold_match;
Lines 1145-1151 sub ModReserveMinusPriority { Link Here
1145
1151
1146
=head2 IsAvailableForItemLevelRequest
1152
=head2 IsAvailableForItemLevelRequest
1147
1153
1148
  my $is_available = IsAvailableForItemLevelRequest($item_record,$borrower_record);
1154
  my $is_available = IsAvailableForItemLevelRequest( $item_record, $borrower_record, $pickup_branchcode );
1149
1155
1150
Checks whether a given item record is available for an
1156
Checks whether a given item record is available for an
1151
item-level hold request.  An item is available if
1157
item-level hold request.  An item is available if
Lines 1170-1175 and canreservefromotherbranches. Link Here
1170
sub IsAvailableForItemLevelRequest {
1176
sub IsAvailableForItemLevelRequest {
1171
    my $item = shift;
1177
    my $item = shift;
1172
    my $borrower = shift;
1178
    my $borrower = shift;
1179
    my $pickup_branchcode = shift;
1173
1180
1174
    my $dbh = C4::Context->dbh;
1181
    my $dbh = C4::Context->dbh;
1175
    # must check the notforloan setting of the itemtype
1182
    # must check the notforloan setting of the itemtype
Lines 1192-1197 sub IsAvailableForItemLevelRequest { Link Here
1192
1199
1193
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
1200
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item_object, patron => $patron } );
1194
1201
1202
    if ($pickup_branchcode) {
1203
        my $destination = Koha::Libraries->find($pickup_branchcode);
1204
        return 0 unless $destination;
1205
        return 0 unless $destination->pickup_location;
1206
        return 0 unless $item_object->can_be_transferred( { to => $destination } );
1207
    }
1208
1195
    if ( $on_shelf_holds == 1 ) {
1209
    if ( $on_shelf_holds == 1 ) {
1196
        return 1;
1210
        return 1;
1197
    } elsif ( $on_shelf_holds == 2 ) {
1211
    } 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 200-206 Link Here
200
        <li>
200
        <li>
201
            <label for="pickup">Pickup at:</label>
201
            <label for="pickup">Pickup at:</label>
202
            <select name="pickup" size="1" id="pickup">
202
            <select name="pickup" size="1" id="pickup">
203
                [% PROCESS options_for_libraries libraries => Branches.all({ search_params => { pickup_location => 1 } }) %]
203
                [% PROCESS options_for_libraries libraries => Branches.all({ selected => pickup, search_params => { pickup_location => 1 } }) %]
204
            </select>
204
            </select>
205
        </li>
205
        </li>
206
206
Lines 341-346 Link Here
341
                                Patron is from different library
341
                                Patron is from different library
342
                            [% ELSIF itemloo.not_holdable == 'itemAlreadyOnHold' %]
342
                            [% ELSIF itemloo.not_holdable == 'itemAlreadyOnHold' %]
343
                                Patron already has hold for this item
343
                                Patron already has hold for this item
344
                            [% ELSIF itemloo.not_holdable == 'cannotBeTransferred' %]
345
                                Cannot be transferred to pickup library
344
                            [% ELSE %]
346
                            [% ELSE %]
345
                                [% itemloo.not_holdable | html %]
347
                                [% itemloo.not_holdable | html %]
346
                            [% END %]
348
                            [% END %]
Lines 661-666 Link Here
661
    [% INCLUDE 'calendar.inc' %]
663
    [% INCLUDE 'calendar.inc' %]
662
    [% Asset.js("js/circ-patron-search-results.js") | $raw %]
664
    [% Asset.js("js/circ-patron-search-results.js") | $raw %]
663
    <script>
665
    <script>
666
        var biblionumber = "[% biblionumber %]";
667
        var borrowernumber = "[% patron.borrowernumber %]";
664
        var MSG_CONFIRM_DELETE_HOLD   = _("Are you sure you want to cancel this hold?");
668
        var MSG_CONFIRM_DELETE_HOLD   = _("Are you sure you want to cancel this hold?");
665
        var patron_homebranch = "[% Branches.GetName( patron.branchcode ) |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
669
        var patron_homebranch = "[% Branches.GetName( patron.branchcode ) |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') | html %]";
666
        var override_items = {[% FOREACH bibitemloo IN bibitemloop %][% FOREACH itemloo IN bibitemloo.itemloop %][% IF ( itemloo.override ) %]
670
        var override_items = {[% FOREACH bibitemloo IN bibitemloop %][% FOREACH itemloo IN bibitemloo.itemloop %][% IF ( itemloo.override ) %]
Lines 685-690 Link Here
685
                ToggleHoldsToPlace();
689
                ToggleHoldsToPlace();
686
            });
690
            });
687
691
692
            [% IF Koha.Preference('UseBranchTransferLimits') %]
693
                $("#pickup").on('change', function(){
694
                    var pickup = $("#pickup").val();
695
                    var url = "?pickup=" + pickup;
696
                    url += "&borrowernumber=" + borrowernumber;
697
                    url += "&biblionumber=" + biblionumber;
698
                    window.location.replace(url);
699
                });
700
            [% END %]
701
688
            [% IF AutoResumeSuspendedHolds %]
702
            [% IF AutoResumeSuspendedHolds %]
689
                $(".suspend_until_datepicker, .datepickerfrom, .datepickerto").datepicker("option", "minDate", 1);
703
                $(".suspend_until_datepicker, .datepickerfrom, .datepickerto").datepicker("option", "minDate", 1);
690
            [% END %]
704
            [% 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
            $canReserve->{status} //= '';
226
            $canReserve->{status} //= '';
226
            if ( $canReserve->{status} eq 'OK' ) {
227
            if ( $canReserve->{status} eq 'OK' ) {
227
228
Lines 473-479 foreach my $biblionumber (@biblionumbers) { Link Here
473
474
474
                $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
475
                $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
475
476
476
                my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber );
477
                my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber, $pickup );
477
                $item->{not_holdable} = $can_item_be_reserved->{status} unless ( $can_item_be_reserved->{status} eq 'OK' );
478
                $item->{not_holdable} = $can_item_be_reserved->{status} unless ( $can_item_be_reserved->{status} eq 'OK' );
478
479
479
                $item->{item_level_holds} = Koha::IssuingRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
480
                $item->{item_level_holds} = Koha::IssuingRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
Lines 646-651 $template->param( biblionumbers => $biblionumbers ); Link Here
646
$template->param( exceeded_maxreserves => $exceeded_maxreserves );
647
$template->param( exceeded_maxreserves => $exceeded_maxreserves );
647
$template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
648
$template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
648
$template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));
649
$template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber));
650
$template->param( pickup => $pickup );
649
651
650
if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
652
if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
651
    $template->param( reserve_in_future => 1 );
653
    $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 436-438 subtest 'Holds test' => sub { Link Here
436
436
437
    $schema->storage->txn_rollback;
437
    $schema->storage->txn_rollback;
438
};
438
};
439
440
subtest 'Holds test for branch transfer limits' => sub {
441
442
    plan tests => 4;
443
444
    $schema->storage->txn_begin;
445
446
    # Test enforement of branch transfer limits
447
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '1' );
448
    t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
449
450
    my $patron = $builder->build({
451
        source => 'Borrower',
452
    });
453
454
    my $origin_branch = $builder->build(
455
        {
456
            source => 'Branch',
457
            value  => {
458
                pickup_location => 1,
459
            }
460
        }
461
    );
462
    my $pickup_branch = $builder->build(
463
        {
464
            source => 'Branch',
465
            value  => {
466
                pickup_location => 1,
467
            }
468
        }
469
    );
470
471
    my $biblio = $builder->build({
472
        source => 'Biblio',
473
    });
474
    my $biblioitem = $builder->build({
475
        source => 'Biblioitem',
476
        value => {
477
            biblionumber => $biblio->{biblionumber},
478
        }
479
    });
480
    my $item = $builder->build({
481
        source => 'Item',
482
        value => {
483
            homebranch => $origin_branch->{branchcode},
484
            holdingbranch => $origin_branch->{branchcode},
485
            biblionumber => $biblio->{biblionumber},
486
            damaged => 0,
487
            itemlost => 0,
488
        }
489
    });
490
491
    Koha::IssuingRules->search()->delete();
492
    my $issuingrule = $builder->build({
493
        source => 'Issuingrule',
494
        value => {
495
            categorycode => '*',
496
            itemtype => '*',
497
            branchcode => '*',
498
            reservesallowed => 99,
499
        }
500
    });
501
502
    my $limit = Koha::Item::Transfer::Limit->new({
503
        toBranch => $pickup_branch->{branchcode},
504
        fromBranch => $item->{holdingbranch},
505
        itemtype => $item->{itype},
506
    })->store();
507
508
    my $query = new CGI;
509
    $query->param( 'pickup_location', $pickup_branch->{branchcode} );
510
    $query->param( 'patron_id', $patron->{borrowernumber});
511
    $query->param( 'bib_id', $biblio->{biblionumber});
512
    $query->param( 'item_id', $item->{itemnumber});
513
514
    my $reply = C4::ILSDI::Services::HoldItem( $query );
515
    is( $reply->{code}, 'cannotBeTransferred', "Item hold, Item cannot be transferred" );
516
517
    $reply = C4::ILSDI::Services::HoldTitle( $query );
518
    is( $reply->{code}, 'cannotBeTransferred', "Record hold, Item cannot be transferred" );
519
520
    t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' );
521
522
    $reply = C4::ILSDI::Services::HoldItem( $query );
523
    is( $reply->{code}, undef, "Item hold, Item can be transferred" );
524
525
    Koha::Holds->search()->delete();
526
527
    $reply = C4::ILSDI::Services::HoldTitle( $query );
528
    is( $reply->{code}, undef, "Record hold, Item con be transferred" );
529
530
    $schema->storage->txn_rollback;
531
}
(-)a/t/db_dependent/Reserves.t (-2 / +15 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 58;
20
use Test::More tests => 59;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 519-524 $item = GetItem($itemnumber); Link Here
519
519
520
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
520
ok( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower), "Reserving a book on item level" );
521
521
522
my $pickup_branch = $builder->build({ source => 'Branch' })->{ branchcode };
523
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '1' );
524
t::lib::Mocks::mock_preference( 'BranchTransferLimitsType', 'itemtype' );
525
my ($item_object) = Koha::Biblios->find($biblionumber)->items;
526
my $limit = Koha::Item::Transfer::Limit->new(
527
    {
528
        toBranch   => $pickup_branch,
529
        fromBranch => $item_object->holdingbranch,
530
        itemtype   => $item_object->effective_itemtype,
531
    }
532
)->store();
533
is( C4::Reserves::IsAvailableForItemLevelRequest($item, $borrower, $pickup_branch), 0, "Item level request not available due to transfer limit" );
534
t::lib::Mocks::mock_preference( 'UseBranchTransferLimits',  '0' );
535
522
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
536
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
523
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
537
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
524
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
538
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
525
- 

Return to bug 22330