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

(-)a/Koha/Item.pm (-2 / +17 lines)
Lines 1932-1943 sub can_be_recalled { Link Here
1932
    return 0 if ( scalar @items == 0 );
1932
    return 0 if ( scalar @items == 0 );
1933
1933
1934
    my $checked_out_count = 0;
1934
    my $checked_out_count = 0;
1935
    my $recallable_items = scalar @items;
1935
    foreach (@items) {
1936
    foreach (@items) {
1936
        if ( Koha::Checkouts->search({ itemnumber => $_->itemnumber })->count > 0 ){ $checked_out_count++; }
1937
        my $item_recalls_allowed = Koha::CirculationRules->get_effective_rule({
1938
            branchcode => $branchcode,
1939
            categorycode => $patron ? $patron->categorycode : undef,
1940
            itemtype => $_->effective_itemtype,
1941
            rule_name => 'recalls_allowed',
1942
        });
1943
        if ( $item_recalls_allowed->rule_value == 0 ) {
1944
            # item is not allowed to be recalled
1945
            $recallable_items--;
1946
        } elsif ( $_->holds({ found => [ 'W','T','P' ] })->count > 0 ) {
1947
            # item is allocated for another hold
1948
            $recallable_items--;
1949
        } elsif ( Koha::Checkouts->search({ itemnumber => $_->itemnumber })->count > 0 ) {
1950
            $checked_out_count++;
1951
        }
1937
    }
1952
    }
1938
1953
1939
    # can't recall if on shelf recalls only allowed when all unavailable, but items are still available for checkout
1954
    # can't recall if on shelf recalls only allowed when all unavailable, but items are still available for checkout
1940
    return 0 if ( $rule->{on_shelf_recalls} eq 'all' && $checked_out_count < scalar @items );
1955
    return 0 if ( $rule->{on_shelf_recalls} eq 'all' && $checked_out_count < $recallable_items );
1941
1956
1942
    # can't recall if no items have been checked out
1957
    # can't recall if no items have been checked out
1943
    return 0 if ( $checked_out_count == 0 );
1958
    return 0 if ( $checked_out_count == 0 );
(-)a/t/db_dependent/Koha/Item.t (-2 / +31 lines)
Lines 1920-1926 subtest 'store() tests' => sub { Link Here
1920
1920
1921
subtest 'Recalls tests' => sub {
1921
subtest 'Recalls tests' => sub {
1922
1922
1923
    plan tests => 23;
1923
    plan tests => 25;
1924
1924
1925
    $schema->storage->txn_begin;
1925
    $schema->storage->txn_begin;
1926
1926
Lines 1938-1943 subtest 'Recalls tests' => sub { Link Here
1938
1938
1939
    t::lib::Mocks::mock_userenv( { patron => $patron1 } );
1939
    t::lib::Mocks::mock_userenv( { patron => $patron1 } );
1940
    t::lib::Mocks::mock_preference('UseRecalls', 1);
1940
    t::lib::Mocks::mock_preference('UseRecalls', 1);
1941
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
1941
1942
1942
    my $recall1 = Koha::Recall->new(
1943
    my $recall1 = Koha::Recall->new(
1943
        {   patron_id         => $patron1->borrowernumber,
1944
        {   patron_id         => $patron1->borrowernumber,
Lines 2016-2021 subtest 'Recalls tests' => sub { Link Here
2016
2017
2017
    is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
2018
    is( $item1->can_be_recalled({ patron => $patron1 }), 0, "Can't recall if on_shelf_recalls = all and items are still available" );
2018
2019
2020
    my $item2_itype = $builder->build_object({ class => 'Koha::ItemTypes' });
2021
    $item2->set({ itype => $item2_itype->itemtype })->store;
2022
    $item2 = Koha::Items->find( $item2->id );
2023
2024
    Koha::CirculationRules->set_rules({
2025
        branchcode => $branchcode,
2026
        categorycode => $patron1->categorycode,
2027
        itemtype => $item2->effective_itemtype,
2028
        rules => {
2029
            recalls_allowed => 0,
2030
            recalls_per_record => 1,
2031
            on_shelf_recalls => 'all',
2032
        },
2033
    });
2034
    is( $item1->can_be_recalled({ patron => $patron1 }), 1, "Can recall because on_shelf_recalls = all and other attached item is not allowed to be recalled so doesn't count" );
2035
2036
    Koha::CirculationRules->set_rules({
2037
        branchcode => $branchcode,
2038
        categorycode => $patron1->categorycode,
2039
        itemtype => $item2->effective_itemtype,
2040
        rules => {
2041
            recalls_allowed => 1,
2042
            recalls_per_record => 1,
2043
            on_shelf_recalls => 'all',
2044
        },
2045
    });
2046
    my $allocated_hold = $builder->build_object({ class => 'Koha::Holds', value => { itemnumber => $item2->id, borrowernumber => $patron3->id, branchcode => $branchcode, found => 'W' } });
2047
    is( $item1->can_be_recalled({ patron => $patron1 }), 1, "Can recall because on_shelf_recalls = all and other attached item is allocated elsewhere so doesn't count" );
2048
2019
    Koha::CirculationRules->set_rules({
2049
    Koha::CirculationRules->set_rules({
2020
        branchcode => $branchcode,
2050
        branchcode => $branchcode,
2021
        categorycode => $patron1->categorycode,
2051
        categorycode => $patron1->categorycode,
2022
- 

Return to bug 33399