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

(-)a/C4/HoldsQueue.pm (+54 lines)
Lines 388-393 sub MapItemsToHoldRequests { Link Here
388
388
389
    # figure out which item-level requests can be filled
389
    # figure out which item-level requests can be filled
390
    my $num_items_remaining = scalar(@$available_items);
390
    my $num_items_remaining = scalar(@$available_items);
391
392
    # Look for Local Holds Priority matches first
393
    if ( C4::Context->preference('LocalHoldsPriority') ) {
394
        my $LocalHoldsPriorityPatronControl =
395
          C4::Context->preference('LocalHoldsPriorityPatronControl');
396
        my $LocalHoldsPriorityItemControl =
397
          C4::Context->preference('LocalHoldsPriorityItemControl');
398
399
        foreach my $request (@$hold_requests) {
400
            last if $num_items_remaining == 0;
401
402
            my $local_hold_match;
403
            foreach my $item (@$available_items) {
404
                next
405
                  if ( !$item->{holdallowed} )
406
                  || ( $item->{holdallowed} == 1
407
                    && $item->{homebranch} ne $request->{borrowerbranch} );
408
409
                my $local_holds_priority_item_branchcode =
410
                  $item->{$LocalHoldsPriorityItemControl};
411
412
                my $local_holds_priority_patron_branchcode =
413
                  ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
414
                  ? $request->{branchcode}
415
                  : ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' )
416
                  ? $request->{borrowerbranch}
417
                  : undef;
418
419
                $local_hold_match =
420
                  $local_holds_priority_item_branchcode eq
421
                  $local_holds_priority_patron_branchcode;
422
423
                if ($local_hold_match) {
424
                    if ( exists $items_by_itemnumber{ $item->{itemnumber} }
425
                        and not exists $allocated_items{ $item->{itemnumber} } )
426
                    {
427
                        $item_map{ $item->{itemnumber} } = {
428
                            borrowernumber => $request->{borrowernumber},
429
                            biblionumber   => $request->{biblionumber},
430
                            holdingbranch  => $item->{holdingbranch},
431
                            pickup_branch  => $request->{branchcode}
432
                              || $request->{borrowerbranch},
433
                            item_level   => 0,
434
                            reservedate  => $request->{reservedate},
435
                            reservenotes => $request->{reservenotes},
436
                        };
437
                        $allocated_items{ $item->{itemnumber} }++;
438
                        $num_items_remaining--;
439
                    }
440
                }
441
            }
442
        }
443
    }
444
391
    foreach my $request (@$hold_requests) {
445
    foreach my $request (@$hold_requests) {
392
        last if $num_items_remaining == 0;
446
        last if $num_items_remaining == 0;
393
447
(-)a/t/db_dependent/HoldsQueue.t (-2 / +81 lines)
Lines 8-14 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 26;
11
use Test::More tests => 30;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Branch;
14
use C4::Branch;
Lines 68-73 $itemtype or BAIL_OUT("No adequate itemtype"); #FIXME Should be $itemtype = $ite Link Here
68
#Set up the stage
68
#Set up the stage
69
# Sysprefs and cost matrix
69
# Sysprefs and cost matrix
70
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
70
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
71
C4::Context->set_preference('LocalHoldsPriority', 0);
71
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
72
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
72
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
73
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
73
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
74
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
Lines 341-346 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
341
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
342
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
342
C4::Context->set_preference( 'HoldsQueueSkipClosed', 0 );
343
C4::Context->set_preference( 'HoldsQueueSkipClosed', 0 );
343
344
345
## Test LocalHoldsPriority
346
C4::Context->set_preference('LocalHoldsPriority', 1);
347
348
$dbh->do("DELETE FROM default_circ_rules");
349
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
350
$dbh->do("DELETE FROM issues");
351
352
# Test homebranch = patron branch
353
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
354
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch');
355
C4::Context->clear_syspref_cache();
356
$dbh->do("DELETE FROM reserves");
357
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
358
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
359
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
360
361
$dbh->do("DELETE FROM items");
362
# barcode, homebranch, holdingbranch, itemtype
363
$items_insert_sth->execute( $barcode + 4, $branchcodes[2], $branchcodes[0] );
364
365
C4::HoldsQueue::CreateQueue();
366
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
367
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library");
368
369
# Test holdingbranch = patron branch
370
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
371
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
372
C4::Context->clear_syspref_cache();
373
$dbh->do("DELETE FROM reserves");
374
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
375
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
376
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
377
378
$dbh->do("DELETE FROM items");
379
# barcode, homebranch, holdingbranch, itemtype
380
$items_insert_sth->execute( $barcode + 4, $branchcodes[0], $branchcodes[2] );
381
382
C4::HoldsQueue::CreateQueue();
383
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
384
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library");
385
386
# Test holdingbranch = pickup branch
387
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary');
388
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
389
C4::Context->clear_syspref_cache();
390
$dbh->do("DELETE FROM reserves");
391
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
392
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
393
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[2], 3 );
394
395
$dbh->do("DELETE FROM items");
396
# barcode, homebranch, holdingbranch, itemtype
397
$items_insert_sth->execute( $barcode + 4, $branchcodes[0], $branchcodes[2] );
398
399
C4::HoldsQueue::CreateQueue();
400
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
401
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library");
402
403
# Test homebranch = pickup branch
404
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary');
405
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch');
406
C4::Context->clear_syspref_cache();
407
$dbh->do("DELETE FROM reserves");
408
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
409
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
410
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[2], 3 );
411
412
$dbh->do("DELETE FROM items");
413
# barcode, homebranch, holdingbranch, itemtype
414
$items_insert_sth->execute( $barcode + 4, $branchcodes[2], $branchcodes[0] );
415
416
C4::HoldsQueue::CreateQueue();
417
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
418
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library");
419
420
C4::Context->set_preference('LocalHoldsPriority', 0);
421
## End testing of LocalHoldsPriority
422
423
344
# Bug 14297
424
# Bug 14297
345
$itemtype = Koha::ItemTypes->search->next->itemtype;
425
$itemtype = Koha::ItemTypes->search->next->itemtype;
346
$borrowernumber = $borrower3->{borrowernumber};
426
$borrowernumber = $borrower3->{borrowernumber};
347
- 

Return to bug 14514