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

(-)a/C4/HoldsQueue.pm (-2 / +3 lines)
Lines 567-578 sub MapItemsToHoldRequests { Link Here
567
        my ($itemnumber, $holdingbranch);
567
        my ($itemnumber, $holdingbranch);
568
568
569
        my $holding_branch_items = $items_by_branch{$pickup_branch};
569
        my $holding_branch_items = $items_by_branch{$pickup_branch};
570
        my $priority_branch = C4::Context->preference('HoldsQueuePrioritizeBranch') // 'homebranch';
570
        if ( $holding_branch_items ) {
571
        if ( $holding_branch_items ) {
571
            foreach my $item (@$holding_branch_items) {
572
            foreach my $item (@$holding_branch_items) {
572
                next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
573
                next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
573
574
574
                if (
575
                if (
575
                    $request->{borrowerbranch} eq $item->{homebranch}
576
                    $request->{borrowerbranch} eq $item->{$priority_branch}
576
                    && _checkHoldPolicy($item, $request) # Don't fill item level holds that contravene the hold pickup policy at this time
577
                    && _checkHoldPolicy($item, $request) # Don't fill item level holds that contravene the hold pickup policy at this time
577
                    && ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
578
                    && ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
578
                        || ( $request->{itemnumber} && ( $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) ) )
579
                        || ( $request->{itemnumber} && ( $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) ) )
Lines 593-599 sub MapItemsToHoldRequests { Link Here
593
594
594
                my $holding_branch_items = $items_by_branch{$holdingbranch};
595
                my $holding_branch_items = $items_by_branch{$holdingbranch};
595
                foreach my $item (@$holding_branch_items) {
596
                foreach my $item (@$holding_branch_items) {
596
                    next if $request->{borrowerbranch} ne $item->{homebranch};
597
                    next if $request->{borrowerbranch} ne $item->{$priority_branch};
597
                    next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
598
                    next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
598
599
599
                    # Don't fill item level holds that contravene the hold pickup policy at this time
600
                    # Don't fill item level holds that contravene the hold pickup policy at this time
(-)a/installer/data/mysql/atomicupdate/bug_31557.pl (+14 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "31557",
5
    description => "Add syspref HoldsQueuePrioritizeBranch",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        $dbh->do(q{
10
            INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
11
            ('HoldsQueuePrioritizeBranch','homebranch','holdingbranch|homebranch','Decides if holds queue builder patron home library match to home or holding branch','Choice')
12
        });
13
    },
14
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 270-275 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
270
('HoldsLog','0',NULL,'If ON, log create/cancel/suspend/resume actions on holds.','YesNo'),
270
('HoldsLog','0',NULL,'If ON, log create/cancel/suspend/resume actions on holds.','YesNo'),
271
('HoldsNeedProcessingSIP', '0', NULL, 'Require staff to check-in before hold is set to waiting state', 'YesNo' ),
271
('HoldsNeedProcessingSIP', '0', NULL, 'Require staff to check-in before hold is set to waiting state', 'YesNo' ),
272
('HoldsQueueSkipClosed', '0', NULL, 'If enabled, any libraries that are closed when the holds queue is built will be ignored for the purpose of filling holds.', 'YesNo'),
272
('HoldsQueueSkipClosed', '0', NULL, 'If enabled, any libraries that are closed when the holds queue is built will be ignored for the purpose of filling holds.', 'YesNo'),
273
('HoldsQueuePrioritizeBranch','homebranch','holdingbranch|homebranch','Decides if holds queue builder patron home library match to home or holding branch','Choice'),
273
('HoldsSplitQueue','nothing','nothing|branch|itemtype|branch_itemtype','In the staff interface, split the holds view by the given criteria','Choice'),
274
('HoldsSplitQueue','nothing','nothing|branch|itemtype|branch_itemtype','In the staff interface, split the holds view by the given criteria','Choice'),
274
('HoldsSplitQueueNumbering', 'actual', 'actual|virtual', 'If the holds queue is split, decide if the actual priorities should be displayed', 'Choice'),
275
('HoldsSplitQueueNumbering', 'actual', 'actual|virtual', 'If the holds queue is split, decide if the actual priorities should be displayed', 'Choice'),
275
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
276
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+7 lines)
Lines 788-793 Circulation: Link Here
788
            - pref: ExpireReservesMaxPickUpDelayCharge
788
            - pref: ExpireReservesMaxPickUpDelayCharge
789
              class: currency
789
              class: currency
790
            - "."
790
            - "."
791
        -
792
            - The holds queue should prioritize filling a hold by matching the patron's home library with an item having a matching
793
            - pref: HoldsQueuePrioritizeBranch
794
              type: choice
795
              choices:
796
                  homebranch: home library (homebranch).
797
                  holdingbranch: holding library (holdingbranch).
791
        -
798
        -
792
            - Satisfy holds using items from the libraries
799
            - Satisfy holds using items from the libraries
793
            - pref: StaticHoldsQueueWeight
800
            - pref: StaticHoldsQueueWeight
(-)a/t/db_dependent/HoldsQueue.t (-1 / +93 lines)
Lines 1967-1969 subtest "GetHoldsQueueItems" => sub { Link Here
1967
1967
1968
    $schema->storage->txn_rollback;
1968
    $schema->storage->txn_rollback;
1969
};
1969
};
1970
- 
1970
1971
subtest "Test HoldsQueuePrioritizeBranch" => sub {
1972
    plan tests => 4;
1973
1974
    Koha::Biblios->delete();
1975
    t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 );
1976
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'homebranch' );
1977
    t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0);
1978
1979
    my $branch1 = $builder->build_object( { class => 'Koha::Libraries' } );
1980
    my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
1981
    my $category = $builder->build_object( { class => 'Koha::Patron::Categories' });
1982
    my $patron = $builder->build_object(
1983
        {
1984
            class => "Koha::Patrons",
1985
            value => {
1986
                branchcode => $branch1->branchcode,
1987
                categorycode => $category->categorycode
1988
            }
1989
        }
1990
    );
1991
1992
    my $biblio = $builder->build_sample_biblio();
1993
    my $item1   = $builder->build_sample_item(
1994
        {
1995
            biblionumber  => $biblio->biblionumber,
1996
            library    => $branch1->branchcode,
1997
        }
1998
    )->holdingbranch( $branch2->id )->store();
1999
2000
    my $item2   = $builder->build_sample_item(
2001
        {
2002
            biblionumber  => $biblio->biblionumber,
2003
            library    => $branch1->branchcode,
2004
        }
2005
    )->homebranch( $branch2->id )->store();
2006
2007
    my $reserve_id = AddReserve(
2008
        {
2009
            branchcode     => $branch1->branchcode,
2010
            borrowernumber => $patron->borrowernumber,
2011
            biblionumber   => $biblio->biblionumber,
2012
            priority       => 1,
2013
        }
2014
    );
2015
2016
    C4::HoldsQueue::CreateQueue();
2017
2018
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
2019
    my $target_rs = $schema->resultset('HoldFillTarget');
2020
    is(
2021
        $queue_rs->next->itemnumber->itemnumber,
2022
        $item1->itemnumber,
2023
        "Picked the item whose homebranch matches the pickup branch"
2024
    );
2025
2026
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'holdingbranch' );
2027
2028
    C4::HoldsQueue::CreateQueue();
2029
2030
    $queue_rs = $schema->resultset('TmpHoldsqueue');
2031
    $target_rs = $schema->resultset('HoldFillTarget');
2032
    is(
2033
        $queue_rs->next->itemnumber->itemnumber,
2034
        $item2->itemnumber,
2035
        "Picked the item whose holdingbranch matches the pickup branch"
2036
    );
2037
2038
    t::lib::Mocks::mock_preference('UseTransportCostMatrix', 1);
2039
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'homebranch' );
2040
2041
    C4::HoldsQueue::CreateQueue();
2042
2043
    $queue_rs = $schema->resultset('TmpHoldsqueue');
2044
    $target_rs = $schema->resultset('HoldFillTarget');
2045
    is(
2046
        $queue_rs->next->itemnumber->itemnumber,
2047
        $item1->itemnumber,
2048
        "Picked the item whose homebranch matches the pickup branch"
2049
    );
2050
2051
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'holdingbranch' );
2052
2053
    C4::HoldsQueue::CreateQueue();
2054
2055
    $queue_rs = $schema->resultset('TmpHoldsqueue');
2056
    $target_rs = $schema->resultset('HoldFillTarget');
2057
    is(
2058
        $queue_rs->next->itemnumber->itemnumber,
2059
        $item2->itemnumber,
2060
        "Picked the item whose holdingbranch matches the pickup branch"
2061
    );
2062
};

Return to bug 31557