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

(-)a/C4/HoldsQueue.pm (-2 / +3 lines)
Lines 560-571 sub MapItemsToHoldRequests { Link Here
560
        my ($itemnumber, $holdingbranch);
560
        my ($itemnumber, $holdingbranch);
561
561
562
        my $holding_branch_items = $items_by_branch{$pickup_branch};
562
        my $holding_branch_items = $items_by_branch{$pickup_branch};
563
        my $priority_branch = C4::Context->preference('HoldsQueuePrioritizeBranch') // 'homebranch';
563
        if ( $holding_branch_items ) {
564
        if ( $holding_branch_items ) {
564
            foreach my $item (@$holding_branch_items) {
565
            foreach my $item (@$holding_branch_items) {
565
                next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
566
                next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
566
567
567
                if (
568
                if (
568
                    $request->{borrowerbranch} eq $item->{homebranch}
569
                    $request->{borrowerbranch} eq $item->{$priority_branch}
569
                    && _checkHoldPolicy($item, $request) # Don't fill item level holds that contravene the hold pickup policy at this time
570
                    && _checkHoldPolicy($item, $request) # Don't fill item level holds that contravene the hold pickup policy at this time
570
                    && ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
571
                    && ( !$request->{itemtype} # If hold itemtype is set, item's itemtype must match
571
                        || ( $request->{itemnumber} && ( $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) ) )
572
                        || ( $request->{itemnumber} && ( $items_by_itemnumber{ $request->{itemnumber} }->{itype} eq $request->{itemtype} ) ) )
Lines 584-590 sub MapItemsToHoldRequests { Link Here
584
585
585
                my $holding_branch_items = $items_by_branch{$holdingbranch};
586
                my $holding_branch_items = $items_by_branch{$holdingbranch};
586
                foreach my $item (@$holding_branch_items) {
587
                foreach my $item (@$holding_branch_items) {
587
                    next if $request->{borrowerbranch} ne $item->{homebranch};
588
                    next if $request->{borrowerbranch} ne $item->{$priority_branch};
588
                    next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
589
                    next unless $items_by_itemnumber{ $item->{itemnumber} }->{_object}->can_be_transferred( { to => $libraries->{ $request->{branchcode} } } );
589
590
590
                    # Don't fill item level holds that contravene the hold pickup policy at this time
591
                    # 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 264-269 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
264
('HoldsLog','0',NULL,'If ON, log create/cancel/suspend/resume actions on holds.','YesNo'),
264
('HoldsLog','0',NULL,'If ON, log create/cancel/suspend/resume actions on holds.','YesNo'),
265
('HoldsNeedProcessingSIP', '0', NULL, 'Require staff to check-in before hold is set to waiting state', 'YesNo' ),
265
('HoldsNeedProcessingSIP', '0', NULL, 'Require staff to check-in before hold is set to waiting state', 'YesNo' ),
266
('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'),
266
('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'),
267
('HoldsQueuePrioritizeBranch','homebranch','holdingbranch|homebranch','Decides if holds queue builder patron home library match to home or holding branch','Choice'),
267
('HoldsSplitQueue','nothing','nothing|branch|itemtype|branch_itemtype','In the staff interface, split the holds view by the given criteria','Choice'),
268
('HoldsSplitQueue','nothing','nothing|branch|itemtype|branch_itemtype','In the staff interface, split the holds view by the given criteria','Choice'),
268
('HoldsSplitQueueNumbering', 'actual', 'actual|virtual', 'If the holds queue is split, decide if the actual priorities should be displayed', 'Choice'),
269
('HoldsSplitQueueNumbering', 'actual', 'actual|virtual', 'If the holds queue is split, decide if the actual priorities should be displayed', 'Choice'),
269
('HoldsToPullStartDate','2',NULL,'Set the default start date for the Holds to pull list to this many days ago','Integer'),
270
('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 782-787 Circulation: Link Here
782
            - pref: ExpireReservesMaxPickUpDelayCharge
782
            - pref: ExpireReservesMaxPickUpDelayCharge
783
              class: currency
783
              class: currency
784
            - "."
784
            - "."
785
        -
786
            - The holds queue should prioritize filling a hold by matching the patron's home library with an item having a matching
787
            - pref: HoldsQueuePrioritizeBranch
788
              type: choice
789
              choices:
790
                  homebranch: home library (homebranch).
791
                  holdingbranch: holding library (holdingbranch).
785
        -
792
        -
786
            - Satisfy holds using items from the libraries
793
            - Satisfy holds using items from the libraries
787
            - pref: StaticHoldsQueueWeight
794
            - pref: StaticHoldsQueueWeight
(-)a/t/db_dependent/HoldsQueue.t (-2 / +94 lines)
Lines 8-14 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 58;
11
use Test::More tests => 59;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Calendar qw( new insert_single_holiday );
14
use C4::Calendar qw( new insert_single_holiday );
Lines 1817-1819 subtest "GetHoldsQueueItems" => sub { Link Here
1817
1817
1818
    $schema->storage->txn_rollback;
1818
    $schema->storage->txn_rollback;
1819
};
1819
};
1820
- 
1820
1821
subtest "Test HoldsQueuePrioritizeBranch" => sub {
1822
    plan tests => 4;
1823
1824
    Koha::Biblios->delete();
1825
    t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 0 );
1826
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'homebranch' );
1827
    t::lib::Mocks::mock_preference('UseTransportCostMatrix', 0);
1828
1829
    my $branch1 = $builder->build_object( { class => 'Koha::Libraries' } );
1830
    my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
1831
    my $category = $builder->build_object( { class => 'Koha::Patron::Categories' });
1832
    my $patron = $builder->build_object(
1833
        {
1834
            class => "Koha::Patrons",
1835
            value => {
1836
                branchcode => $branch1->branchcode,
1837
                categorycode => $category->categorycode
1838
            }
1839
        }
1840
    );
1841
1842
    my $biblio = $builder->build_sample_biblio();
1843
    my $item1   = $builder->build_sample_item(
1844
        {
1845
            biblionumber  => $biblio->biblionumber,
1846
            library    => $branch1->branchcode,
1847
        }
1848
    )->holdingbranch( $branch2->id )->store();
1849
1850
    my $item2   = $builder->build_sample_item(
1851
        {
1852
            biblionumber  => $biblio->biblionumber,
1853
            library    => $branch1->branchcode,
1854
        }
1855
    )->homebranch( $branch2->id )->store();
1856
1857
    my $reserve_id = AddReserve(
1858
        {
1859
            branchcode     => $branch1->branchcode,
1860
            borrowernumber => $patron->borrowernumber,
1861
            biblionumber   => $biblio->biblionumber,
1862
            priority       => 1,
1863
        }
1864
    );
1865
1866
    C4::HoldsQueue::CreateQueue();
1867
1868
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
1869
    my $target_rs = $schema->resultset('HoldFillTarget');
1870
    is(
1871
        $queue_rs->next->itemnumber->itemnumber,
1872
        $item1->itemnumber,
1873
        "Picked the item whose homebranch matches the pickup branch"
1874
    );
1875
1876
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'holdingbranch' );
1877
1878
    C4::HoldsQueue::CreateQueue();
1879
1880
    $queue_rs = $schema->resultset('TmpHoldsqueue');
1881
    $target_rs = $schema->resultset('HoldFillTarget');
1882
    is(
1883
        $queue_rs->next->itemnumber->itemnumber,
1884
        $item2->itemnumber,
1885
        "Picked the item whose holdingbranch matches the pickup branch"
1886
    );
1887
1888
    t::lib::Mocks::mock_preference('UseTransportCostMatrix', 1);
1889
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'homebranch' );
1890
1891
    C4::HoldsQueue::CreateQueue();
1892
1893
    $queue_rs = $schema->resultset('TmpHoldsqueue');
1894
    $target_rs = $schema->resultset('HoldFillTarget');
1895
    is(
1896
        $queue_rs->next->itemnumber->itemnumber,
1897
        $item1->itemnumber,
1898
        "Picked the item whose homebranch matches the pickup branch"
1899
    );
1900
1901
    t::lib::Mocks::mock_preference( 'HoldsQueuePrioritizeBranch', 'holdingbranch' );
1902
1903
    C4::HoldsQueue::CreateQueue();
1904
1905
    $queue_rs = $schema->resultset('TmpHoldsqueue');
1906
    $target_rs = $schema->resultset('HoldFillTarget');
1907
    is(
1908
        $queue_rs->next->itemnumber->itemnumber,
1909
        $item2->itemnumber,
1910
        "Picked the item whose holdingbranch matches the pickup branch"
1911
    );
1912
};

Return to bug 31557