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

(-)a/C4/HoldsQueue.pm (+54 lines)
Lines 375-380 sub MapItemsToHoldRequests { Link Here
375
375
376
    # figure out which item-level requests can be filled
376
    # figure out which item-level requests can be filled
377
    my $num_items_remaining = scalar(@$available_items);
377
    my $num_items_remaining = scalar(@$available_items);
378
379
    # Look for Local Holds Priority matches first
380
    if ( C4::Context->preference('LocalHoldsPriority') ) {
381
        my $LocalHoldsPriorityPatronControl =
382
          C4::Context->preference('LocalHoldsPriorityPatronControl');
383
        my $LocalHoldsPriorityItemControl =
384
          C4::Context->preference('LocalHoldsPriorityItemControl');
385
386
        foreach my $request (@$hold_requests) {
387
            last if $num_items_remaining == 0;
388
389
            my $local_hold_match;
390
            foreach my $item (@$available_items) {
391
                next
392
                  if ( !$item->{holdallowed} )
393
                  || ( $item->{holdallowed} == 1
394
                    && $item->{homebranch} ne $request->{borrowerbranch} );
395
396
                my $local_holds_priority_item_branchcode =
397
                  $item->{$LocalHoldsPriorityItemControl};
398
399
                my $local_holds_priority_patron_branchcode =
400
                  ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
401
                  ? $request->{branchcode}
402
                  : ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' )
403
                  ? $request->{borrowerbranch}
404
                  : undef;
405
406
                $local_hold_match =
407
                  $local_holds_priority_item_branchcode eq
408
                  $local_holds_priority_patron_branchcode;
409
410
                if ($local_hold_match) {
411
                    if ( exists $items_by_itemnumber{ $item->{itemnumber} }
412
                        and not exists $allocated_items{ $item->{itemnumber} } )
413
                    {
414
                        $item_map{ $item->{itemnumber} } = {
415
                            borrowernumber => $request->{borrowernumber},
416
                            biblionumber   => $request->{biblionumber},
417
                            holdingbranch  => $item->{holdingbranch},
418
                            pickup_branch  => $request->{branchcode}
419
                              || $request->{borrowerbranch},
420
                            item_level   => 0,
421
                            reservedate  => $request->{reservedate},
422
                            reservenotes => $request->{reservenotes},
423
                        };
424
                        $allocated_items{ $item->{itemnumber} }++;
425
                        $num_items_remaining--;
426
                    }
427
                }
428
            }
429
        }
430
    }
431
378
    foreach my $request (@$hold_requests) {
432
    foreach my $request (@$hold_requests) {
379
        last if $num_items_remaining == 0;
433
        last if $num_items_remaining == 0;
380
434
(-)a/t/db_dependent/HoldsQueue.t (-2 / +81 lines)
Lines 12-18 use C4::Context; Link Here
12
12
13
use Data::Dumper;
13
use Data::Dumper;
14
14
15
use Test::More tests => 23;
15
use Test::More tests => 27;
16
16
17
use C4::Branch;
17
use C4::Branch;
18
use C4::Members;
18
use C4::Members;
Lines 66-71 $itemtype or BAIL_OUT("No adequate itemtype"); #FIXME Should be $itemtype = $ite Link Here
66
66
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('LocalHoldsPriority', 0);
69
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
70
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
70
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
71
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
71
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
72
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
Lines 307-312 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
307
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
308
is( @$holds_queue, 3, "Holds queue filling correct number for holds for default holds policy 'from any library'" );
308
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
309
#warn "HOLDS QUEUE: " . Data::Dumper::Dumper( $holds_queue );
309
310
311
## Test LocalHoldsPriority
312
C4::Context->set_preference('LocalHoldsPriority', 1);
313
314
$dbh->do("DELETE FROM default_circ_rules");
315
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
316
$dbh->do("DELETE FROM issues");
317
318
# Test homebranch = patron branch
319
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
320
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch');
321
C4::Context->clear_syspref_cache();
322
$dbh->do("DELETE FROM reserves");
323
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
324
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
325
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
326
327
$dbh->do("DELETE FROM items");
328
# barcode, homebranch, holdingbranch, itemtype
329
$items_insert_sth->execute( $barcode + 4, $branchcodes[2], $branchcodes[0] );
330
331
C4::HoldsQueue::CreateQueue();
332
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
333
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library");
334
335
# Test holdingbranch = patron branch
336
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
337
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
338
C4::Context->clear_syspref_cache();
339
$dbh->do("DELETE FROM reserves");
340
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
341
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
342
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
343
344
$dbh->do("DELETE FROM items");
345
# barcode, homebranch, holdingbranch, itemtype
346
$items_insert_sth->execute( $barcode + 4, $branchcodes[0], $branchcodes[2] );
347
348
C4::HoldsQueue::CreateQueue();
349
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
350
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library");
351
352
# Test holdingbranch = pickup branch
353
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary');
354
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
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[2], 3 );
360
361
$dbh->do("DELETE FROM items");
362
# barcode, homebranch, holdingbranch, itemtype
363
$items_insert_sth->execute( $barcode + 4, $branchcodes[0], $branchcodes[2] );
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 holding library");
368
369
# Test homebranch = pickup branch
370
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary');
371
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch');
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[2], 3 );
377
378
$dbh->do("DELETE FROM items");
379
# barcode, homebranch, holdingbranch, itemtype
380
$items_insert_sth->execute( $barcode + 4, $branchcodes[2], $branchcodes[0] );
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
C4::Context->set_preference('LocalHoldsPriority', 0);
387
## End testing of LocalHoldsPriority
388
389
310
# Bug 14297
390
# Bug 14297
311
$itemtype = Koha::ItemTypes->search->next->itemtype;
391
$itemtype = Koha::ItemTypes->search->next->itemtype;
312
$borrowernumber = $borrower3->{borrowernumber};
392
$borrowernumber = $borrower3->{borrowernumber};
313
- 

Return to bug 14514