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

(-)a/C4/Reserves.pm (-16 / +18 lines)
Lines 483-495 sub CanItemBeReserved { Link Here
483
        branchcode   => $reserves_control_branch,
483
        branchcode   => $reserves_control_branch,
484
        rules        => ['holds_per_record','holds_per_day','opacitemholds']
484
        rules        => ['holds_per_record','holds_per_day','opacitemholds']
485
    });
485
    });
486
    my $branchitemrule =
487
      C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->effective_itemtype );
488
489
    $rights->{holdallowed} = $branchitemrule->{holdallowed};
490
486
    my $holds_per_record = $rights->{holds_per_record} // 1;
491
    my $holds_per_record = $rights->{holds_per_record} // 1;
487
    my $holds_per_day    = $rights->{holds_per_day};
492
    my $holds_per_day    = $rights->{holds_per_day};
488
    my $opacitemholds    = $rights->{opacitemholds} // 'Y';
493
    my $opacitemholds    = $rights->{opacitemholds} // 'Y';
489
494
490
    if (   defined $holds_per_record && $holds_per_record ne '' ){
495
    if (   defined $holds_per_record && $holds_per_record ne '' ){
491
        if ( $holds_per_record == 0 ) {
496
        if ( $holds_per_record == 0 ) {
492
            return { status => "noReservesAllowed" };
497
            return { status => "noReservesAllowed", rights => $rights };
493
        }
498
        }
494
        if ( !$params->{ignore_hold_counts} ) {
499
        if ( !$params->{ignore_hold_counts} ) {
495
            my $search_params = {
500
            my $search_params = {
Lines 498-504 sub CanItemBeReserved { Link Here
498
            };
503
            };
499
            $search_params->{found} = undef if $params->{ignore_found_holds};
504
            $search_params->{found} = undef if $params->{ignore_found_holds};
500
            my $holds = Koha::Holds->search($search_params);
505
            my $holds = Koha::Holds->search($search_params);
501
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record } if $holds->count() >= $holds_per_record;
506
            return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record, rights => $rights } if $holds->count() >= $holds_per_record;
502
        }
507
        }
503
    }
508
    }
504
509
Lines 508-514 sub CanItemBeReserved { Link Here
508
            borrowernumber => $patron->borrowernumber,
513
            borrowernumber => $patron->borrowernumber,
509
            reservedate    => dt_from_string->date
514
            reservedate    => dt_from_string->date
510
        });
515
        });
511
        return { status => 'tooManyReservesToday', limit => $holds_per_day } if $today_holds->count() >= $holds_per_day;
516
        return { status => 'tooManyReservesToday', limit => $holds_per_day, rights => $rights } if $today_holds->count() >= $holds_per_day;
512
    }
517
    }
513
518
514
    # we check if it's ok or not
519
    # we check if it's ok or not
Lines 550-556 sub CanItemBeReserved { Link Here
550
                $reservecount = $rowcount->{count};
555
                $reservecount = $rowcount->{count};
551
            }
556
            }
552
557
553
            return { status => 'tooManyReserves', limit => $allowedreserves } if $reservecount >= $allowedreserves;
558
            return { status => 'tooManyReserves', limit => $allowedreserves, rights => $rights } if $reservecount >= $allowedreserves;
554
        }
559
        }
555
    }
560
    }
556
561
Lines 569-594 sub CanItemBeReserved { Link Here
569
            }
574
            }
570
        )->count();
575
        )->count();
571
576
572
        return { status => 'tooManyReserves', limit => $rule->rule_value} if $total_holds_count >= $rule->rule_value;
577
        return { status => 'tooManyReserves', limit => $rule->rule_value, rights => $rights } if $total_holds_count >= $rule->rule_value;
573
    }
578
    }
574
579
575
    my $branchitemrule =
576
      C4::Circulation::GetBranchItemRule( $reserves_control_branch, $item->effective_itemtype );
577
578
    if ( $branchitemrule->{holdallowed} eq 'not_allowed' ) {
580
    if ( $branchitemrule->{holdallowed} eq 'not_allowed' ) {
579
        return { status => 'notReservable' };
581
        return { status => 'notReservable', rights => $rights };
580
    }
582
    }
581
583
582
    if (   $branchitemrule->{holdallowed} eq 'from_home_library'
584
    if (   $branchitemrule->{holdallowed} eq 'from_home_library'
583
        && $borrower->{branchcode} ne $item->homebranch )
585
        && $borrower->{branchcode} ne $item->homebranch )
584
    {
586
    {
585
        return { status => 'cannotReserveFromOtherBranches' };
587
        return { status => 'cannotReserveFromOtherBranches', rights => $rights };
586
    }
588
    }
587
589
588
    my $item_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
590
    my $item_library = Koha::Libraries->find( {branchcode => $item->homebranch} );
589
    if ( $branchitemrule->{holdallowed} eq 'from_local_hold_group') {
591
    if ( $branchitemrule->{holdallowed} eq 'from_local_hold_group') {
590
        if($patron->branchcode ne $item->homebranch && !$item_library->validate_hold_sibling( {branchcode => $patron->branchcode} )) {
592
        if($patron->branchcode ne $item->homebranch && !$item_library->validate_hold_sibling( {branchcode => $patron->branchcode} )) {
591
            return { status => 'branchNotInHoldGroup' };
593
            return { status => 'branchNotInHoldGroup', rights => $rights };
592
        }
594
        }
593
    }
595
    }
594
596
Lines 598-616 sub CanItemBeReserved { Link Here
598
        });
600
        });
599
601
600
        unless ($destination) {
602
        unless ($destination) {
601
            return { status => 'libraryNotFound' };
603
            return { status => 'libraryNotFound', rights => $rights };
602
        }
604
        }
603
        unless ($destination->pickup_location) {
605
        unless ($destination->pickup_location) {
604
            return { status => 'libraryNotPickupLocation' };
606
            return { status => 'libraryNotPickupLocation', rigths => $rights };
605
        }
607
        }
606
        unless ($item->can_be_transferred({ to => $destination })) {
608
        unless ($item->can_be_transferred({ to => $destination })) {
607
            return { status => 'cannotBeTransferred' };
609
            return { status => 'cannotBeTransferred', rights => $rights };
608
        }
610
        }
609
        if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup' && !$item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} )) {
611
        if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup' && !$item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} )) {
610
            return { status => 'pickupNotInHoldGroup' };
612
            return { status => 'pickupNotInHoldGroup', rights => $rights };
611
        }
613
        }
612
        if ($branchitemrule->{hold_fulfillment_policy} eq 'patrongroup' && !Koha::Libraries->find({branchcode => $borrower->{branchcode}})->validate_hold_sibling({branchcode => $pickup_branchcode})) {
614
        if ($branchitemrule->{hold_fulfillment_policy} eq 'patrongroup' && !Koha::Libraries->find({branchcode => $borrower->{branchcode}})->validate_hold_sibling({branchcode => $pickup_branchcode})) {
613
            return { status => 'pickupNotInHoldGroup' };
615
            return { status => 'pickupNotInHoldGroup', rights => $rights };
614
        }
616
        }
615
    }
617
    }
616
618
(-)a/reserve/request.pl (-9 / +5 lines)
Lines 477-498 if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) Link Here
477
                }
477
                }
478
478
479
                if ( $patron ) {
479
                if ( $patron ) {
480
                    my $patron_unblessed = $patron->unblessed;
481
                    my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
482
480
483
                    my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
481
                    my $can_item_be_reserved = CanItemBeReserved( $patron, $item_object );
484
482
485
                    $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
483
                    $item->{'holdallowed'} = $can_item_be_reserved->{rights}->{holdallowed};
486
484
                    $item->{not_holdable} = $can_item_be_reserved->{status} unless ( $can_item_be_reserved->{status} eq 'OK' );
487
                    my $can_item_be_reserved = CanItemBeReserved( $patron, $item_object )->{status};
488
                    $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
489
485
490
                    $item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
486
                    $item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
491
487
492
                    if (
488
                    if (
493
                           !$item->{cantreserve}
489
                           !$item->{cantreserve}
494
                        && !$exceeded_maxreserves
490
                        && !$exceeded_maxreserves
495
                        && $can_item_be_reserved eq 'OK'
491
                        && $can_item_be_reserved->{status} eq 'OK'
496
                        # items_any_available defined outside of the current loop,
492
                        # items_any_available defined outside of the current loop,
497
                        # so we avoiding loop inside IsAvailableForItemLevelRequest:
493
                        # so we avoiding loop inside IsAvailableForItemLevelRequest:
498
                        && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
494
                        && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
Lines 518-524 if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold ) Link Here
518
                    elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
514
                    elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
519
                        # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
515
                        # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
520
                        # with the exception of itemAlreadyOnHold because, you know, the item is already on hold
516
                        # with the exception of itemAlreadyOnHold because, you know, the item is already on hold
521
                        if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) {
517
                        if ( $can_item_be_reserved->{status} ne 'itemAlreadyOnHold' ) {
522
                            # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
518
                            # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
523
                            my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list;
519
                            my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list;
524
                            $item->{pickup_locations_count} = scalar @pickup_locations;
520
                            $item->{pickup_locations_count} = scalar @pickup_locations;
(-)a/t/db_dependent/Holds.t (-1 / +1 lines)
Lines 881-886 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
881
        }
881
        }
882
    );
882
    );
883
883
884
    warn Data::Dumper::Dumper( CanItemBeReserved( $patron, $item_1 )->{rights} );
884
    is_deeply(
885
    is_deeply(
885
        CanItemBeReserved( $patron, $item_1 ),
886
        CanItemBeReserved( $patron, $item_1 ),
886
        { status => 'OK' },
887
        { status => 'OK' },
887
- 

Return to bug 30851