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

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

Return to bug 14514